Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider: Support default tags (resources aws_d*) #18732

Merged
merged 4 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aws/dx_vif.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func dxVirtualInterfaceUpdate(d *schema.ResourceData, meta interface{}) error {
}

arn := d.Get("arn").(string)
if d.HasChange("tags") {
o, n := d.GetChange("tags")
if d.HasChange("tags_all") {
o, n := d.GetChange("tags_all")

if err := keyvaluetags.DirectconnectUpdateTags(conn, arn, o, n); err != nil {
return fmt.Errorf("error updating Direct Connect virtual interface (%s) tags: %s", arn, err)
Expand Down
25 changes: 19 additions & 6 deletions aws/resource_aws_datapipeline_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,25 @@ func resourceAwsDataPipelinePipeline() *schema.Resource {
ForceNew: true,
},

"tags": tagsSchema(),
"tags": tagsSchema(),
"tags_all": tagsSchemaComputed(),
},

CustomizeDiff: SetTagsDiff,
}
}

func resourceAwsDataPipelinePipelineCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).datapipelineconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{})))

uniqueID := resource.UniqueId()

input := datapipeline.CreatePipelineInput{
Name: aws.String(d.Get("name").(string)),
UniqueId: aws.String(uniqueID),
Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().DatapipelineTags(),
Tags: tags.IgnoreAws().DatapipelineTags(),
}

if v, ok := d.GetOk("description"); ok {
Expand All @@ -68,6 +73,7 @@ func resourceAwsDataPipelinePipelineCreate(d *schema.ResourceData, meta interfac

func resourceAwsDataPipelinePipelineRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).datapipelineconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

v, err := resourceAwsDataPipelinePipelineRetrieve(d.Id(), conn)
Expand All @@ -82,8 +88,15 @@ func resourceAwsDataPipelinePipelineRead(d *schema.ResourceData, meta interface{

d.Set("name", v.Name)
d.Set("description", v.Description)
if err := d.Set("tags", keyvaluetags.DatapipelineKeyValueTags(v.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
tags := keyvaluetags.DatapipelineKeyValueTags(v.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig)

//lintignore:AWSR002
if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %w", err)
}

if err := d.Set("tags_all", tags.Map()); err != nil {
return fmt.Errorf("error setting tags_all: %w", err)
}

return nil
Expand All @@ -92,8 +105,8 @@ func resourceAwsDataPipelinePipelineRead(d *schema.ResourceData, meta interface{
func resourceAwsDataPipelinePipelineUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).datapipelineconn

if d.HasChange("tags") {
o, n := d.GetChange("tags")
if d.HasChange("tags_all") {
o, n := d.GetChange("tags_all")

if err := keyvaluetags.DatapipelineUpdateTags(conn, d.Id(), o, n); err != nil {
return fmt.Errorf("error updating Datapipeline Pipeline (%s) tags: %s", d.Id(), err)
Expand Down
25 changes: 19 additions & 6 deletions aws/resource_aws_datasync_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ func resourceAwsDataSyncAgent() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"tags": tagsSchema(),
"tags": tagsSchema(),
"tags_all": tagsSchemaComputed(),
},

CustomizeDiff: SetTagsDiff,
}
}

func resourceAwsDataSyncAgentCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).datasyncconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{})))
region := meta.(*AWSClient).region

activationKey := d.Get("activation_key").(string)
Expand Down Expand Up @@ -125,7 +130,7 @@ func resourceAwsDataSyncAgentCreate(d *schema.ResourceData, meta interface{}) er

input := &datasync.CreateAgentInput{
ActivationKey: aws.String(activationKey),
Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().DatasyncTags(),
Tags: tags.IgnoreAws().DatasyncTags(),
}

if v, ok := d.GetOk("name"); ok {
Expand Down Expand Up @@ -169,6 +174,7 @@ func resourceAwsDataSyncAgentCreate(d *schema.ResourceData, meta interface{}) er

func resourceAwsDataSyncAgentRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).datasyncconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

input := &datasync.DescribeAgentInput{
Expand Down Expand Up @@ -197,8 +203,15 @@ func resourceAwsDataSyncAgentRead(d *schema.ResourceData, meta interface{}) erro
return fmt.Errorf("error listing tags for DataSync Agent (%s): %s", d.Id(), err)
}

if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
tags = tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig)

//lintignore:AWSR002
if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %w", err)
}

if err := d.Set("tags_all", tags.Map()); err != nil {
return fmt.Errorf("error setting tags_all: %w", err)
}

return nil
Expand All @@ -220,8 +233,8 @@ func resourceAwsDataSyncAgentUpdate(d *schema.ResourceData, meta interface{}) er
}
}

if d.HasChange("tags") {
o, n := d.GetChange("tags")
if d.HasChange("tags_all") {
o, n := d.GetChange("tags_all")

if err := keyvaluetags.DatasyncUpdateTags(conn, d.Id(), o, n); err != nil {
return fmt.Errorf("error updating DataSync Agent (%s) tags: %s", d.Id(), err)
Expand Down
25 changes: 19 additions & 6 deletions aws/resource_aws_datasync_location_efs.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,28 @@ func resourceAwsDataSyncLocationEfs() *schema.Resource {
return false
},
},
"tags": tagsSchema(),
"tags": tagsSchema(),
"tags_all": tagsSchemaComputed(),
"uri": {
Type: schema.TypeString,
Computed: true,
},
},

CustomizeDiff: SetTagsDiff,
}
}

func resourceAwsDataSyncLocationEfsCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).datasyncconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{})))

input := &datasync.CreateLocationEfsInput{
Ec2Config: expandDataSyncEc2Config(d.Get("ec2_config").([]interface{})),
EfsFilesystemArn: aws.String(d.Get("efs_file_system_arn").(string)),
Subdirectory: aws.String(d.Get("subdirectory").(string)),
Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().DatasyncTags(),
Tags: tags.IgnoreAws().DatasyncTags(),
}

log.Printf("[DEBUG] Creating DataSync Location EFS: %s", input)
Expand All @@ -103,6 +108,7 @@ func resourceAwsDataSyncLocationEfsCreate(d *schema.ResourceData, meta interface

func resourceAwsDataSyncLocationEfsRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).datasyncconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

input := &datasync.DescribeLocationEfsInput{
Expand Down Expand Up @@ -143,8 +149,15 @@ func resourceAwsDataSyncLocationEfsRead(d *schema.ResourceData, meta interface{}
return fmt.Errorf("error listing tags for DataSync Location EFS (%s): %s", d.Id(), err)
}

if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
tags = tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig)

//lintignore:AWSR002
if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %w", err)
}

if err := d.Set("tags_all", tags.Map()); err != nil {
return fmt.Errorf("error setting tags_all: %w", err)
}

return nil
Expand All @@ -153,8 +166,8 @@ func resourceAwsDataSyncLocationEfsRead(d *schema.ResourceData, meta interface{}
func resourceAwsDataSyncLocationEfsUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).datasyncconn

if d.HasChange("tags") {
o, n := d.GetChange("tags")
if d.HasChange("tags_all") {
o, n := d.GetChange("tags_all")

if err := keyvaluetags.DatasyncUpdateTags(conn, d.Id(), o, n); err != nil {
return fmt.Errorf("error updating DataSync Location EFS (%s) tags: %s", d.Id(), err)
Expand Down
23 changes: 18 additions & 5 deletions aws/resource_aws_datasync_location_fsx_windows_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystem() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 4096),
},
"tags": tagsSchema(),
"tags": tagsSchema(),
"tags_all": tagsSchemaComputed(),
"uri": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -94,19 +95,23 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystem() *schema.Resource {
Computed: true,
},
},

CustomizeDiff: SetTagsDiff,
}
}

func resourceAwsDataSyncLocationFsxWindowsFileSystemCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).datasyncconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{})))
fsxArn := d.Get("fsx_filesystem_arn").(string)

input := &datasync.CreateLocationFsxWindowsInput{
FsxFilesystemArn: aws.String(fsxArn),
User: aws.String(d.Get("user").(string)),
Password: aws.String(d.Get("password").(string)),
SecurityGroupArns: expandStringSet(d.Get("security_group_arns").(*schema.Set)),
Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().DatasyncTags(),
Tags: tags.IgnoreAws().DatasyncTags(),
}

if v, ok := d.GetOk("subdirectory"); ok {
Expand All @@ -130,6 +135,7 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemCreate(d *schema.ResourceDat

func resourceAwsDataSyncLocationFsxWindowsFileSystemRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).datasyncconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

input := &datasync.DescribeLocationFsxWindowsInput{
Expand Down Expand Up @@ -175,18 +181,25 @@ func resourceAwsDataSyncLocationFsxWindowsFileSystemRead(d *schema.ResourceData,
return fmt.Errorf("error listing tags for DataSync Location Fsx Windows (%s): %w", d.Id(), err)
}

if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
tags = tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig)

//lintignore:AWSR002
if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %w", err)
}

if err := d.Set("tags_all", tags.Map()); err != nil {
return fmt.Errorf("error setting tags_all: %w", err)
}

return nil
}

func resourceAwsDataSyncLocationFsxWindowsFileSystemUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).datasyncconn

if d.HasChange("tags") {
o, n := d.GetChange("tags")
if d.HasChange("tags_all") {
o, n := d.GetChange("tags_all")

if err := keyvaluetags.DatasyncUpdateTags(conn, d.Id(), o, n); err != nil {
return fmt.Errorf("error updating DataSync Location Fsx Windows File System (%s) tags: %w", d.Id(), err)
Expand Down
25 changes: 19 additions & 6 deletions aws/resource_aws_datasync_location_nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,28 @@ func resourceAwsDataSyncLocationNfs() *schema.Resource {
return false
},
},
"tags": tagsSchema(),
"tags": tagsSchema(),
"tags_all": tagsSchemaComputed(),
"uri": {
Type: schema.TypeString,
Computed: true,
},
},

CustomizeDiff: SetTagsDiff,
}
}

func resourceAwsDataSyncLocationNfsCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).datasyncconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(keyvaluetags.New(d.Get("tags").(map[string]interface{})))

input := &datasync.CreateLocationNfsInput{
OnPremConfig: expandDataSyncOnPremConfig(d.Get("on_prem_config").([]interface{})),
ServerHostname: aws.String(d.Get("server_hostname").(string)),
Subdirectory: aws.String(d.Get("subdirectory").(string)),
Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().DatasyncTags(),
Tags: tags.IgnoreAws().DatasyncTags(),
}

log.Printf("[DEBUG] Creating DataSync Location NFS: %s", input)
Expand All @@ -96,6 +101,7 @@ func resourceAwsDataSyncLocationNfsCreate(d *schema.ResourceData, meta interface

func resourceAwsDataSyncLocationNfsRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).datasyncconn
defaultTagsConfig := meta.(*AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

input := &datasync.DescribeLocationNfsInput{
Expand Down Expand Up @@ -136,8 +142,15 @@ func resourceAwsDataSyncLocationNfsRead(d *schema.ResourceData, meta interface{}
return fmt.Errorf("error listing tags for DataSync Location NFS (%s): %s", d.Id(), err)
}

if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
tags = tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig)

//lintignore:AWSR002
if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %w", err)
}

if err := d.Set("tags_all", tags.Map()); err != nil {
return fmt.Errorf("error setting tags_all: %w", err)
}

return nil
Expand All @@ -146,8 +159,8 @@ func resourceAwsDataSyncLocationNfsRead(d *schema.ResourceData, meta interface{}
func resourceAwsDataSyncLocationNfsUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).datasyncconn

if d.HasChange("tags") {
o, n := d.GetChange("tags")
if d.HasChange("tags_all") {
o, n := d.GetChange("tags_all")

if err := keyvaluetags.DatasyncUpdateTags(conn, d.Id(), o, n); err != nil {
return fmt.Errorf("error updating DataSync Location NFS (%s) tags: %s", d.Id(), err)
Expand Down
Loading