func (u *UserDataConfiguration) ParseBool(key string) *bool { s := u.Settings[key] if s == "" { return nil } s = strings.ToLower(s) if s == "true" || s == "1" || s == "y" || s == "yes" || s == "t" { return fi.Bool(true) } return fi.Bool(false) }
func (_ *AutoscalingGroup) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *AutoscalingGroup) error { tf := &terraformAutoscalingGroup{ Name: e.Name, MinSize: e.MinSize, MaxSize: e.MaxSize, LaunchConfigurationName: e.LaunchConfiguration.TerraformLink(), } for _, s := range e.Subnets { tf.VPCZoneIdentifier = append(tf.VPCZoneIdentifier, s.TerraformLink()) } tags := e.buildTags(t.Cloud) // Make sure we output in a stable order var tagKeys []string for k := range tags { tagKeys = append(tagKeys, k) } sort.Strings(tagKeys) for _, k := range tagKeys { v := tags[k] tf.Tags = append(tf.Tags, &terraformASGTag{ Key: fi.String(k), Value: fi.String(v), PropagateAtLaunch: fi.Bool(true), }) } return t.RenderResource("aws_autoscaling_group", *e.Name, tf) }
func (e *Service) Find(c *fi.Context) (*Service, error) { servicePath := path.Join(systemdSystemPath, e.Name) d, err := ioutil.ReadFile(servicePath) if err != nil { if !os.IsNotExist(err) { return nil, fmt.Errorf("Error reading systemd file %q: %v", servicePath, err) } // Not found return &Service{ Name: e.Name, Definition: nil, Running: fi.Bool(false), }, nil } actual := &Service{ Name: e.Name, Definition: fi.String(string(d)), // Avoid spurious changes ManageState: e.ManageState, SmartRestart: e.SmartRestart, } properties, err := getSystemdStatus(e.Name) if err != nil { return nil, err } activeState := properties["ActiveState"] switch activeState { case "active": actual.Running = fi.Bool(true) case "failed", "inactive": actual.Running = fi.Bool(false) default: glog.Warningf("Unknown ActiveState=%q; will treat as not running", activeState) actual.Running = fi.Bool(false) } return actual, nil }
func (_ *LaunchConfiguration) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *LaunchConfiguration) error { cloud := t.Cloud.(*awsup.AWSCloud) if e.ImageID == nil { return fi.RequiredField("ImageID") } image, err := cloud.ResolveImage(*e.ImageID) if err != nil { return err } tf := &terraformLaunchConfiguration{ NamePrefix: fi.String(*e.Name + "-"), ImageID: image.ImageId, InstanceType: e.InstanceType, } if e.SSHKey != nil { tf.KeyName = e.SSHKey.TerraformLink() } for _, sg := range e.SecurityGroups { tf.SecurityGroups = append(tf.SecurityGroups, sg.TerraformLink()) } tf.AssociatePublicIpAddress = e.AssociatePublicIP if e.BlockDeviceMappings != nil { tf.EphemeralBlockDevice = []*terraformBlockDevice{} for deviceName, bdm := range e.BlockDeviceMappings { tf.EphemeralBlockDevice = append(tf.EphemeralBlockDevice, &terraformBlockDevice{ VirtualName: bdm.VirtualName, DeviceName: fi.String(deviceName), }) } } if e.UserData != nil { tf.UserData, err = t.AddFile("aws_launch_configuration", *e.Name, "user_data", e.UserData) if err != nil { return err } } if e.IAMInstanceProfile != nil { tf.IAMInstanceProfile = e.IAMInstanceProfile.TerraformLink() } // So that we can update configurations tf.Lifecycle = &terraformLifecycle{CreateBeforeDestroy: fi.Bool(true)} return t.RenderResource("aws_launch_configuration", *e.Name, tf) }
func NewService(name string, contents string, meta string) (fi.Task, error) { s := &Service{Name: name} s.Definition = fi.String(contents) if meta != "" { err := json.Unmarshal([]byte(meta), s) if err != nil { return nil, fmt.Errorf("error parsing json for service %q: %v", name, err) } } // Default some values to true: Running, SmartRestart, ManageState if s.Running == nil { s.Running = fi.Bool(true) } if s.SmartRestart == nil { s.SmartRestart = fi.Bool(true) } if s.ManageState == nil { s.ManageState = fi.Bool(true) } return s, nil }