From cdef0bc2335613f1cca9087e2a783d1f86875c1f Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 4 Apr 2023 17:41:38 -0400 Subject: [PATCH 1/3] Remove tagging boilerplate for Plugin SDK resources - backup. --- internal/service/backup/framework.go | 41 +++--------------- internal/service/backup/plan.go | 37 +++------------- internal/service/backup/report_plan.go | 43 +++---------------- .../service/backup/service_package_gen.go | 16 +++++++ internal/service/backup/vault.go | 39 +++-------------- 5 files changed, 41 insertions(+), 135 deletions(-) diff --git a/internal/service/backup/framework.go b/internal/service/backup/framework.go index 183965498ca..7ec591e152e 100644 --- a/internal/service/backup/framework.go +++ b/internal/service/backup/framework.go @@ -18,9 +18,11 @@ import ( tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" + "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKResource("aws_backup_framework") +// @SDKResource("aws_backup_framework", name="Framework") +// @Tags(identifierAttribute="arn") func ResourceFramework() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceFrameworkCreate, @@ -125,8 +127,8 @@ func ResourceFramework() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, CustomizeDiff: verify.SetTagsDiff, } @@ -135,26 +137,19 @@ func ResourceFramework() *schema.Resource { func resourceFrameworkCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).BackupConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) name := d.Get("name").(string) - input := &backup.CreateFrameworkInput{ IdempotencyToken: aws.String(id.UniqueId()), FrameworkControls: expandFrameworkControls(ctx, d.Get("control").(*schema.Set).List()), FrameworkName: aws.String(name), + FrameworkTags: GetTagsIn(ctx), } if v, ok := d.GetOk("description"); ok { input.FrameworkDescription = aws.String(v.(string)) } - if len(tags) > 0 { - input.FrameworkTags = Tags(tags.IgnoreAWS()) - } - - log.Printf("[DEBUG] Creating Backup Framework: %#v", input) resp, err := conn.CreateFrameworkWithContext(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating Backup Framework: %s", err) @@ -174,8 +169,6 @@ func resourceFrameworkCreate(ctx context.Context, d *schema.ResourceData, meta i func resourceFrameworkRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).BackupConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig resp, err := conn.DescribeFrameworkWithContext(ctx, &backup.DescribeFrameworkInput{ FrameworkName: aws.String(d.Id()), @@ -204,21 +197,6 @@ func resourceFrameworkRead(ctx context.Context, d *schema.ResourceData, meta int return sdkdiag.AppendErrorf(diags, "setting control: %s", err) } - tags, err := ListTags(ctx, conn, d.Get("arn").(string)) - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for Backup Framework (%s): %s", d.Id(), err) - } - tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags_all: %s", err) - } - return diags } @@ -249,13 +227,6 @@ func resourceFrameworkUpdate(ctx context.Context, d *schema.ResourceData, meta i } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating tags for Backup Framework (%s): %s", d.Id(), err) - } - } - return append(diags, resourceFrameworkRead(ctx, d, meta)...) } diff --git a/internal/service/backup/plan.go b/internal/service/backup/plan.go index a86f1612da1..f4c4e285ca4 100644 --- a/internal/service/backup/plan.go +++ b/internal/service/backup/plan.go @@ -22,9 +22,11 @@ import ( tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" + "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKResource("aws_backup_plan") +// @SDKResource("aws_backup_plan", name="Plan") +// @Tags(identifierAttribute="arn") func ResourcePlan() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourcePlanCreate, @@ -161,8 +163,8 @@ func ResourcePlan() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, CustomizeDiff: verify.SetTagsDiff, @@ -172,8 +174,6 @@ func ResourcePlan() *schema.Resource { func resourcePlanCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).BackupConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) input := &backup.CreateBackupPlanInput{ BackupPlan: &backup.PlanInput{ @@ -181,10 +181,9 @@ func resourcePlanCreate(ctx context.Context, d *schema.ResourceData, meta interf Rules: expandPlanRules(ctx, d.Get("rule").(*schema.Set)), AdvancedBackupSettings: expandPlanAdvancedSettings(d.Get("advanced_backup_setting").(*schema.Set)), }, - BackupPlanTags: Tags(tags.IgnoreAWS()), + BackupPlanTags: GetTagsIn(ctx), } - log.Printf("[DEBUG] Creating Backup Plan: %#v", input) resp, err := conn.CreateBackupPlanWithContext(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating Backup Plan: %s", err) @@ -198,8 +197,6 @@ func resourcePlanCreate(ctx context.Context, d *schema.ResourceData, meta interf func resourcePlanRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).BackupConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig resp, err := conn.GetBackupPlanWithContext(ctx, &backup.GetBackupPlanInput{ BackupPlanId: aws.String(d.Id()), @@ -227,21 +224,6 @@ func resourcePlanRead(ctx context.Context, d *schema.ResourceData, meta interfac return sdkdiag.AppendErrorf(diags, "setting advanced_backup_setting: %s", err) } - tags, err := ListTags(ctx, conn, d.Get("arn").(string)) - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for Backup Plan (%s): %s", d.Id(), err) - } - tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags_all: %s", err) - } - return diags } @@ -266,13 +248,6 @@ func resourcePlanUpdate(ctx context.Context, d *schema.ResourceData, meta interf } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating tags for Backup Plan (%s): %s", d.Id(), err) - } - } - return append(diags, resourcePlanRead(ctx, d, meta)...) } diff --git a/internal/service/backup/report_plan.go b/internal/service/backup/report_plan.go index 1be987f20d5..897014bc01f 100644 --- a/internal/service/backup/report_plan.go +++ b/internal/service/backup/report_plan.go @@ -19,9 +19,11 @@ import ( tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" + "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKResource("aws_backup_report_plan") +// @SDKResource("aws_backup_report_plan", name="Report Plan") +// @Tags(identifierAttribute="arn") func ResourceReportPlan() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceReportPlanCreate, @@ -109,8 +111,8 @@ func ResourceReportPlan() *schema.Resource { }, }, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, CustomizeDiff: verify.SetTagsDiff, @@ -120,14 +122,13 @@ func ResourceReportPlan() *schema.Resource { func resourceReportPlanCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).BackupConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) name := d.Get("name").(string) input := &backup.CreateReportPlanInput{ IdempotencyToken: aws.String(id.UniqueId()), ReportDeliveryChannel: expandReportDeliveryChannel(d.Get("report_delivery_channel").([]interface{})), ReportPlanName: aws.String(name), + ReportPlanTags: GetTagsIn(ctx), ReportSetting: expandReportSetting(d.Get("report_setting").([]interface{})), } @@ -135,11 +136,6 @@ func resourceReportPlanCreate(ctx context.Context, d *schema.ResourceData, meta input.ReportPlanDescription = aws.String(v.(string)) } - if len(tags) > 0 { - input.ReportPlanTags = Tags(tags.IgnoreAWS()) - } - - log.Printf("[DEBUG] Creating Backup Report Plan: %s", input) output, err := conn.CreateReportPlanWithContext(ctx, input) if err != nil { @@ -159,8 +155,6 @@ func resourceReportPlanCreate(ctx context.Context, d *schema.ResourceData, meta func resourceReportPlanRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).BackupConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig reportPlan, err := FindReportPlanByName(ctx, conn, d.Id()) @@ -188,23 +182,6 @@ func resourceReportPlanRead(ctx context.Context, d *schema.ResourceData, meta in return sdkdiag.AppendErrorf(diags, "setting report_setting: %s", err) } - tags, err := ListTags(ctx, conn, d.Get("arn").(string)) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for Backup Report Plan (%s): %s", d.Id(), err) - } - - tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags_all: %s", err) - } - return diags } @@ -233,14 +210,6 @@ func resourceReportPlanUpdate(ctx context.Context, d *schema.ResourceData, meta } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating tags for Backup Report Plan (%s): %s", d.Id(), err) - } - } - return append(diags, resourceReportPlanRead(ctx, d, meta)...) } diff --git a/internal/service/backup/service_package_gen.go b/internal/service/backup/service_package_gen.go index 868b04d21fb..7e2713c873c 100644 --- a/internal/service/backup/service_package_gen.go +++ b/internal/service/backup/service_package_gen.go @@ -49,6 +49,10 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceFramework, TypeName: "aws_backup_framework", + Name: "Framework", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceGlobalSettings, @@ -57,6 +61,10 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourcePlan, TypeName: "aws_backup_plan", + Name: "Plan", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceRegionSettings, @@ -65,6 +73,10 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceReportPlan, TypeName: "aws_backup_report_plan", + Name: "Report Plan", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceSelection, @@ -73,6 +85,10 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceVault, TypeName: "aws_backup_vault", + Name: "Vault", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceVaultLockConfiguration, diff --git a/internal/service/backup/vault.go b/internal/service/backup/vault.go index 0b12ca0022d..d287d8986cd 100644 --- a/internal/service/backup/vault.go +++ b/internal/service/backup/vault.go @@ -19,9 +19,11 @@ import ( tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" + "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKResource("aws_backup_vault") +// @SDKResource("aws_backup_vault", name="Vault") +// @Tags(identifierAttribute="arn") func ResourceVault() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceVaultCreate, @@ -67,8 +69,8 @@ func ResourceVault() *schema.Resource { Type: schema.TypeInt, Computed: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, CustomizeDiff: verify.SetTagsDiff, @@ -78,13 +80,11 @@ func ResourceVault() *schema.Resource { func resourceVaultCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).BackupConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) name := d.Get("name").(string) input := &backup.CreateBackupVaultInput{ BackupVaultName: aws.String(name), - BackupVaultTags: Tags(tags.IgnoreAWS()), + BackupVaultTags: GetTagsIn(ctx), } if v, ok := d.GetOk("kms_key_arn"); ok { @@ -105,8 +105,6 @@ func resourceVaultCreate(ctx context.Context, d *schema.ResourceData, meta inter func resourceVaultRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).BackupConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig output, err := FindVaultByName(ctx, conn, d.Id()) @@ -125,36 +123,13 @@ func resourceVaultRead(ctx context.Context, d *schema.ResourceData, meta interfa d.Set("name", output.BackupVaultName) d.Set("recovery_points", output.NumberOfRecoveryPoints) - tags, err := ListTags(ctx, conn, d.Get("arn").(string)) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "listing tags for Backup Vault (%s): %s", d.Id(), err) - } - - tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags_all: %s", err) - } - return diags } func resourceVaultUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).BackupConn() - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating tags for Backup Vault (%s): %s", d.Id(), err) - } - } + // Tags only. return append(diags, resourceVaultRead(ctx, d, meta)...) } From 253e75dd952b9be45a89adfe7e2e450d4d9deea2 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 4 Apr 2023 17:41:45 -0400 Subject: [PATCH 2/3] Remove tagging boilerplate for Plugin SDK resources - batch. --- internal/service/batch/compute_environment.go | 38 +++------------- internal/service/batch/job_definition.go | 43 +++++-------------- internal/service/batch/job_queue.go | 37 ++++------------ internal/service/batch/scheduling_policy.go | 36 +++------------- internal/service/batch/service_package_gen.go | 16 +++++++ 5 files changed, 49 insertions(+), 121 deletions(-) diff --git a/internal/service/batch/compute_environment.go b/internal/service/batch/compute_environment.go index aef7b29e288..9fc97c72390 100644 --- a/internal/service/batch/compute_environment.go +++ b/internal/service/batch/compute_environment.go @@ -22,9 +22,11 @@ import ( tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" + "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKResource("aws_batch_compute_environment") +// @SDKResource("aws_batch_compute_environment", name="Compute Environment") +// @Tags(identifierAttribute="arn") func ResourceComputeEnvironment() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceComputeEnvironmentCreate, @@ -248,8 +250,8 @@ func ResourceComputeEnvironment() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags:tftags.TagsSchema(), +names.AttrTagsAll: tftags.TagsSchemaComputed(), "type": { Type: schema.TypeString, Required: true, @@ -266,15 +268,13 @@ func ResourceComputeEnvironment() *schema.Resource { func resourceComputeEnvironmentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).BatchConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) computeEnvironmentName := create.Name(d.Get("compute_environment_name").(string), d.Get("compute_environment_name_prefix").(string)) computeEnvironmentType := d.Get("type").(string) - input := &batch.CreateComputeEnvironmentInput{ ComputeEnvironmentName: aws.String(computeEnvironmentName), ServiceRole: aws.String(d.Get("service_role").(string)), + Tags: GetTagsIn(ctx), Type: aws.String(computeEnvironmentType), } @@ -290,11 +290,6 @@ func resourceComputeEnvironmentCreate(ctx context.Context, d *schema.ResourceDat input.State = aws.String(v.(string)) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - - log.Printf("[DEBUG] Creating Batch Compute Environment: %s", input) output, err := conn.CreateComputeEnvironmentWithContext(ctx, input) if err != nil { @@ -313,8 +308,6 @@ func resourceComputeEnvironmentCreate(ctx context.Context, d *schema.ResourceDat func resourceComputeEnvironmentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).BatchConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig computeEnvironment, err := FindComputeEnvironmentDetailByName(ctx, conn, d.Id()) @@ -356,16 +349,7 @@ func resourceComputeEnvironmentRead(ctx context.Context, d *schema.ResourceData, d.Set("eks_configuration", nil) } - tags := KeyValueTags(ctx, computeEnvironment.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags_all: %s", err) - } + SetTagsOut(ctx, computeEnvironment.Tags) return diags } @@ -422,14 +406,6 @@ func resourceComputeEnvironmentUpdate(ctx context.Context, d *schema.ResourceDat } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating tags: %s", err) - } - } - return append(diags, resourceComputeEnvironmentRead(ctx, d, meta)...) } diff --git a/internal/service/batch/job_definition.go b/internal/service/batch/job_definition.go index f25a7bc39ca..b021f18bfa7 100644 --- a/internal/service/batch/job_definition.go +++ b/internal/service/batch/job_definition.go @@ -24,9 +24,11 @@ import ( tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" + "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKResource("aws_batch_job_definition") +// @SDKResource("aws_batch_job_definition", name="Job Definition") +// @Tags(identifierAttribute="arn") func ResourceJobDefinition() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceJobDefinitionCreate, @@ -151,8 +153,8 @@ func ResourceJobDefinition() *schema.Resource { Type: schema.TypeInt, Computed: true, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "timeout": { Type: schema.TypeList, Optional: true, @@ -184,14 +186,13 @@ func ResourceJobDefinition() *schema.Resource { func resourceJobDefinitionCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).BatchConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) - name := d.Get("name").(string) + name := d.Get("name").(string) input := &batch.RegisterJobDefinitionInput{ JobDefinitionName: aws.String(name), - Type: aws.String(d.Get("type").(string)), PropagateTags: aws.Bool(d.Get("propagate_tags").(bool)), + Tags: GetTagsIn(ctx), + Type: aws.String(d.Get("type").(string)), } if v, ok := d.GetOk("container_properties"); ok { @@ -225,10 +226,6 @@ func resourceJobDefinitionCreate(ctx context.Context, d *schema.ResourceData, me input.RetryStrategy = expandRetryStrategy(v.([]interface{})[0].(map[string]interface{})) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - if v, ok := d.GetOk("timeout"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { input.Timeout = expandJobTimeout(v.([]interface{})[0].(map[string]interface{})) } @@ -247,8 +244,6 @@ func resourceJobDefinitionCreate(ctx context.Context, d *schema.ResourceData, me func resourceJobDefinitionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).BatchConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig jobDefinition, err := FindJobDefinitionByARN(ctx, conn, d.Id()) @@ -287,16 +282,7 @@ func resourceJobDefinitionRead(ctx context.Context, d *schema.ResourceData, meta d.Set("retry_strategy", nil) } - tags := KeyValueTags(ctx, jobDefinition.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags_all: %s", err) - } + SetTagsOut(ctx, jobDefinition.Tags) if jobDefinition.Timeout != nil { if err := d.Set("timeout", []interface{}{flattenJobTimeout(jobDefinition.Timeout)}); err != nil { @@ -314,17 +300,10 @@ func resourceJobDefinitionRead(ctx context.Context, d *schema.ResourceData, meta func resourceJobDefinitionUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).BatchConn() - - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - if err := UpdateTags(ctx, conn, d.Id(), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating tags: %s", err) - } - } + // Tags only. - return diags + return append(diags, resourceJobDefinitionRead(ctx, d, meta)...) } func resourceJobDefinitionDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { diff --git a/internal/service/batch/job_queue.go b/internal/service/batch/job_queue.go index 2c8d406c619..e5d8ebd8f50 100644 --- a/internal/service/batch/job_queue.go +++ b/internal/service/batch/job_queue.go @@ -17,9 +17,11 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/verify" + "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKResource("aws_batch_job_queue") +// @SDKResource("aws_batch_job_queue", name="Job Queue") +// @Tags(identifierAttribute="arn") func ResourceJobQueue() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceJobQueueCreate, @@ -60,8 +62,8 @@ func ResourceJobQueue() *schema.Resource { Required: true, ValidateFunc: validation.StringInSlice([]string{batch.JQStateDisabled, batch.JQStateEnabled}, true), }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "arn": { Type: schema.TypeString, Computed: true, @@ -75,23 +77,19 @@ func ResourceJobQueue() *schema.Resource { func resourceJobQueueCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).BatchConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) + input := batch.CreateJobQueueInput{ ComputeEnvironmentOrder: createComputeEnvironmentOrder(d.Get("compute_environments").([]interface{})), JobQueueName: aws.String(d.Get("name").(string)), Priority: aws.Int64(int64(d.Get("priority").(int))), State: aws.String(d.Get("state").(string)), + Tags: GetTagsIn(ctx), } if v, ok := d.GetOk("scheduling_policy_arn"); ok { input.SchedulingPolicyArn = aws.String(v.(string)) } - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) - } - name := d.Get("name").(string) out, err := conn.CreateJobQueueWithContext(ctx, &input) if err != nil { @@ -122,8 +120,6 @@ func resourceJobQueueCreate(ctx context.Context, d *schema.ResourceData, meta in func resourceJobQueueRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).BatchConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig jq, err := GetJobQueue(ctx, conn, d.Id()) if err != nil { @@ -156,16 +152,7 @@ func resourceJobQueueRead(ctx context.Context, d *schema.ResourceData, meta inte d.Set("scheduling_policy_arn", jq.SchedulingPolicyArn) d.Set("state", jq.State) - tags := KeyValueTags(ctx, jq.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags_all: %s", err) - } + SetTagsOut(ctx, jq.Tags) return diags } @@ -217,14 +204,6 @@ func resourceJobQueueUpdate(ctx context.Context, d *schema.ResourceData, meta in } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return sdkdiag.AppendErrorf(diags, "updating tags: %s", err) - } - } - return append(diags, resourceJobQueueRead(ctx, d, meta)...) } diff --git a/internal/service/batch/scheduling_policy.go b/internal/service/batch/scheduling_policy.go index 948f84645af..fa0764d9b81 100644 --- a/internal/service/batch/scheduling_policy.go +++ b/internal/service/batch/scheduling_policy.go @@ -16,9 +16,11 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKResource("aws_batch_scheduling_policy") +// @SDKResource("aws_batch_scheduling_policy", name="Job Definition") +// @Tags(identifierAttribute="arn") func ResourceSchedulingPolicy() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceSchedulingPolicyCreate, @@ -89,25 +91,20 @@ func ResourceSchedulingPolicy() *schema.Resource { ForceNew: true, ValidateFunc: validName, }, - "tags": tftags.TagsSchema(), - "tags_all": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), }, } } func resourceSchedulingPolicyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).BatchConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - tags := defaultTagsConfig.MergeTags(tftags.New(ctx, d.Get("tags").(map[string]interface{}))) name := d.Get("name").(string) input := &batch.CreateSchedulingPolicyInput{ FairsharePolicy: expandFairsharePolicy(d.Get("fair_share_policy").([]interface{})), Name: aws.String(name), - } - - if len(tags) > 0 { - input.Tags = Tags(tags.IgnoreAWS()) + Tags: GetTagsIn(ctx), } output, err := conn.CreateSchedulingPolicyWithContext(ctx, input) @@ -124,8 +121,6 @@ func resourceSchedulingPolicyCreate(ctx context.Context, d *schema.ResourceData, func resourceSchedulingPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics conn := meta.(*conns.AWSClient).BatchConn() - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig sp, err := FindSchedulingPolicyByARN(ctx, conn, d.Id()) @@ -145,16 +140,7 @@ func resourceSchedulingPolicyRead(ctx context.Context, d *schema.ResourceData, m } d.Set("name", sp.Name) - tags := KeyValueTags(ctx, sp.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - - //lintignore:AWSR002 - if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } - - if err := d.Set("tags_all", tags.Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags_all: %s", err) - } + SetTagsOut(ctx, sp.Tags) return diags } @@ -175,14 +161,6 @@ func resourceSchedulingPolicyUpdate(ctx context.Context, d *schema.ResourceData, } } - if d.HasChange("tags_all") { - o, n := d.GetChange("tags_all") - - if err := UpdateTags(ctx, conn, d.Id(), o, n); err != nil { - return diag.Errorf("updating Batch Scheduling Policy (%s) tags: %s", d.Id(), err) - } - } - return resourceSchedulingPolicyRead(ctx, d, meta) } diff --git a/internal/service/batch/service_package_gen.go b/internal/service/batch/service_package_gen.go index a7aaefd8f53..6f17fe31797 100644 --- a/internal/service/batch/service_package_gen.go +++ b/internal/service/batch/service_package_gen.go @@ -41,18 +41,34 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka { Factory: ResourceComputeEnvironment, TypeName: "aws_batch_compute_environment", + Name: "Compute Environment", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceJobDefinition, TypeName: "aws_batch_job_definition", + Name: "Job Definition", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceJobQueue, TypeName: "aws_batch_job_queue", + Name: "Job Queue", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, { Factory: ResourceSchedulingPolicy, TypeName: "aws_batch_scheduling_policy", + Name: "Job Definition", + Tags: &types.ServicePackageResourceTags{ + IdentifierAttribute: "arn", + }, }, } } From 1b77c1e8b51f4f72799bedc363689e46ab0be1a9 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 4 Apr 2023 17:45:37 -0400 Subject: [PATCH 3/3] Run 'make fmt'. --- internal/service/batch/compute_environment.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/batch/compute_environment.go b/internal/service/batch/compute_environment.go index 9fc97c72390..7ff34a3eead 100644 --- a/internal/service/batch/compute_environment.go +++ b/internal/service/batch/compute_environment.go @@ -250,8 +250,8 @@ func ResourceComputeEnvironment() *schema.Resource { Type: schema.TypeString, Computed: true, }, - names.AttrTags:tftags.TagsSchema(), -names.AttrTagsAll: tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "type": { Type: schema.TypeString, Required: true, @@ -274,7 +274,7 @@ func resourceComputeEnvironmentCreate(ctx context.Context, d *schema.ResourceDat input := &batch.CreateComputeEnvironmentInput{ ComputeEnvironmentName: aws.String(computeEnvironmentName), ServiceRole: aws.String(d.Get("service_role").(string)), - Tags: GetTagsIn(ctx), + Tags: GetTagsIn(ctx), Type: aws.String(computeEnvironmentType), }