diff --git a/pkg/model/spotinstmodel/instance_group.go b/pkg/model/spotinstmodel/instance_group.go index dd9ac22172..bf307898f7 100644 --- a/pkg/model/spotinstmodel/instance_group.go +++ b/pkg/model/spotinstmodel/instance_group.go @@ -476,6 +476,12 @@ func (b *InstanceGroupModelBuilder) buildLaunchSpec(c *fi.ModelBuilderContext, return fmt.Errorf("error building security groups: %v", err) } + // Tags. + launchSpec.Tags, err = b.buildTags(ig) + if err != nil { + return fmt.Errorf("error building cloud tags: %v", err) + } + // Labels. autoScalerOpts, err := b.buildAutoScalerOpts(b.ClusterName(), ig) if err != nil { diff --git a/upup/pkg/fi/cloudup/spotinsttasks/launch_spec.go b/upup/pkg/fi/cloudup/spotinsttasks/launch_spec.go index c33da11ea3..5f0d4d189d 100644 --- a/upup/pkg/fi/cloudup/spotinsttasks/launch_spec.go +++ b/upup/pkg/fi/cloudup/spotinsttasks/launch_spec.go @@ -43,6 +43,7 @@ type LaunchSpec struct { SecurityGroups []*awstasks.SecurityGroup IAMInstanceProfile *awstasks.IAMInstanceProfile ImageID *string + Tags map[string]string Labels map[string]string Ocean *Ocean @@ -167,6 +168,16 @@ func (o *LaunchSpec) Find(c *fi.Context) (*LaunchSpec, error) { } } + // Tags. + { + if len(spec.Tags) > 0 { + actual.Tags = make(map[string]string) + for _, tag := range spec.Tags { + actual.Tags[fi.StringValue(tag.Key)] = fi.StringValue(tag.Value) + } + } + } + // Labels. if spec.Labels != nil { actual.Labels = make(map[string]string) @@ -265,6 +276,13 @@ func (_ *LaunchSpec) create(cloud awsup.AWSCloud, a, e, changes *LaunchSpec) err } } + // Tags. + { + if e.Tags != nil { + spec.SetTags(e.buildTags()) + } + } + // Labels. { if e.Labels != nil && len(e.Labels) > 0 { @@ -366,6 +384,15 @@ func (_ *LaunchSpec) update(cloud awsup.AWSCloud, a, e, changes *LaunchSpec) err } } + // Tags. + { + if changes.Tags != nil { + spec.SetTags(e.buildTags()) + changes.Tags = nil + changed = true + } + } + // Labels. { if changes.Labels != nil { @@ -474,6 +501,18 @@ func (_ *LaunchSpec) RenderTerraform(t *terraform.TerraformTarget, a, e, changes tf.IAMInstanceProfile = e.IAMInstanceProfile.TerraformLink() } + // Tags. + { + if e.Tags != nil { + for _, tag := range e.buildTags() { + tf.Tags = append(tf.Tags, &terraformKV{ + Key: tag.Key, + Value: tag.Value, + }) + } + } + } + // Labels. { if e.Labels != nil { @@ -493,3 +532,16 @@ func (_ *LaunchSpec) RenderTerraform(t *terraform.TerraformTarget, a, e, changes func (o *LaunchSpec) TerraformLink() *terraform.Literal { return terraform.LiteralProperty("spotinst_ocean_aws_launch_spec", *o.Name, "id") } + +func (o *LaunchSpec) buildTags() []*aws.Tag { + tags := make([]*aws.Tag, 0, len(o.Tags)) + + for key, value := range o.Tags { + tags = append(tags, &aws.Tag{ + Key: fi.String(key), + Value: fi.String(value), + }) + } + + return tags +} diff --git a/upup/pkg/fi/cloudup/spotinsttasks/ocean.go b/upup/pkg/fi/cloudup/spotinsttasks/ocean.go index 166c5a8cd6..e989c90e81 100644 --- a/upup/pkg/fi/cloudup/spotinsttasks/ocean.go +++ b/upup/pkg/fi/cloudup/spotinsttasks/ocean.go @@ -951,6 +951,7 @@ type terraformOceanLaunchSpec struct { KeyName *terraform.Literal `json:"key_name,omitempty"` SecurityGroups []*terraform.Literal `json:"security_groups,omitempty"` Labels []*terraformKV `json:"labels,omitempty"` + Tags []*terraformKV `json:"tags,omitempty"` } func (_ *Ocean) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Ocean) error {