Skip to content

Commit

Permalink
Merge pull request #22717 from hashicorp/b-add-iso-tag-fixes
Browse files Browse the repository at this point in the history
ISO Tags: Improve error handling
  • Loading branch information
YakDriver committed Jan 21, 2022
2 parents de458c3 + 3144aa9 commit 0a67faa
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 53 deletions.
51 changes: 51 additions & 0 deletions .changelog/22717.txt
@@ -0,0 +1,51 @@
```release-note:bug
resource/aws_cloudwatch_event_rule: Further refine tag error handling for ISO regions
```

```release-note:bug
resource/aws_cloudwatch_event_bus: Further refine tag error handling for ISO regions
```

```release-note:bug
resource/aws_cloudwatch_composite_alarm: Further refine tag error handling for ISO regions
```

```release-note:bug
resource/aws_cloudwatch_metric_alarm: Further refine tag error handling for ISO regions
```

```release-note:bug
resource/aws_cloudwatch_metric_stream: Further refine tag error handling for ISO regions
```

```release-note:bug
data-source/aws_lb_listener: Further refine tag error handling for ISO regions
```

```release-note:bug
resource/aws_lb_listener_rule: Further refine tag error handling for ISO regions
```

```release-note:bug
resource/aws_lb_listener: Further refine tag error handling for ISO regions
```

```release-note:bug
data-source/aws_lb: Further refine tag error handling for ISO regions
```

```release-note:bug
resource/aws_lb: Further refine tag error handling for ISO regions
```

```release-note:bug
data-source/aws_lb: Further refine tag error handling for ISO regions
```

```release-note:bug
data-source/aws_lb_target_group: Further refine tag error handling for ISO regions
```

```release-note:bug
resource/aws_lb_target_group: Further refine tag error handling for ISO regions
```
8 changes: 4 additions & 4 deletions internal/service/cloudwatch/composite_alarm.go
Expand Up @@ -102,7 +102,7 @@ func resourceCompositeAlarmCreate(ctx context.Context, d *schema.ResourceData, m
_, err := conn.PutCompositeAlarmWithContext(ctx, &input)

// Some partitions (i.e., ISO) may not support tag-on-create
if input.Tags != nil && (tfawserr.ErrCodeContains(err, errCodeAccessDenied) || tfawserr.ErrCodeContains(err, cloudwatch.ErrCodeInternalServiceFault)) {
if input.Tags != nil && verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] CloudWatch Composite Alarm (%s) create failed (%s) with tags. Trying create without tags.", d.Id(), err)
input.Tags = nil

Expand All @@ -129,7 +129,7 @@ func resourceCompositeAlarmCreate(ctx context.Context, d *schema.ResourceData, m
err = UpdateTags(conn, aws.StringValue(alarm.AlarmArn), nil, tags)

// If default tags only, log and continue. Otherwise, error.
if v, ok := d.GetOk("tags"); (!ok || len(v.(map[string]interface{})) == 0) && (tfawserr.ErrCodeContains(err, errCodeAccessDenied) || tfawserr.ErrCodeContains(err, cloudwatch.ErrCodeInternalServiceFault)) {
if v, ok := d.GetOk("tags"); (!ok || len(v.(map[string]interface{})) == 0) && verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] error adding tags after create for CloudWatch Composite Alarm (%s): %s", d.Id(), err)
return resourceCompositeAlarmRead(ctx, d, meta)
}
Expand Down Expand Up @@ -191,7 +191,7 @@ func resourceCompositeAlarmRead(ctx context.Context, d *schema.ResourceData, met
tags, err := ListTags(conn, aws.StringValue(alarm.AlarmArn))

// Some partitions (i.e., ISO) may not support tagging, giving error
if tfawserr.ErrCodeContains(err, errCodeAccessDenied) || tfawserr.ErrCodeContains(err, cloudwatch.ErrCodeInternalServiceFault) {
if verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] Unable to list tags for CloudWatch Composite Alarm %s: %s", d.Id(), err)
return nil
}
Expand Down Expand Up @@ -232,7 +232,7 @@ func resourceCompositeAlarmUpdate(ctx context.Context, d *schema.ResourceData, m
err := UpdateTags(conn, arn, o, n)

// Some partitions (i.e., ISO) may not support tagging, giving error
if tfawserr.ErrCodeContains(err, errCodeAccessDenied) || tfawserr.ErrCodeContains(err, cloudwatch.ErrCodeInternalServiceFault) {
if verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] Unable to update tags for CloudWatch Composite Alarm %s: %s", arn, err)
return resourceCompositeAlarmRead(ctx, d, meta)
}
Expand Down
4 changes: 0 additions & 4 deletions internal/service/cloudwatch/consts.go
@@ -1,9 +1,5 @@
package cloudwatch

const (
errCodeAccessDenied = "AccessDenied"
)

const (
lowSampleCountPercentilesEvaluate = "evaluate"
lowSampleCountPercentilesmissingDataIgnore = "ignore"
Expand Down
8 changes: 4 additions & 4 deletions internal/service/cloudwatch/metric_alarm.go
Expand Up @@ -296,7 +296,7 @@ func resourceMetricAlarmCreate(d *schema.ResourceData, meta interface{}) error {
_, err = conn.PutMetricAlarm(&params)

// Some partitions (i.e., ISO) may not support tag-on-create
if params.Tags != nil && (tfawserr.ErrCodeContains(err, errCodeAccessDenied) || tfawserr.ErrCodeContains(err, cloudwatch.ErrCodeInternalServiceFault)) {
if params.Tags != nil && verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] CloudWatch Metric Alarm (%s) create failed (%s) with tags. Trying create without tags.", d.Id(), err)
params.Tags = nil

Expand Down Expand Up @@ -324,7 +324,7 @@ func resourceMetricAlarmCreate(d *schema.ResourceData, meta interface{}) error {
err = UpdateTags(conn, aws.StringValue(resp.AlarmArn), nil, tags)

// If default tags only, log and continue. Otherwise, error.
if v, ok := d.GetOk("tags"); (!ok || len(v.(map[string]interface{})) == 0) && (tfawserr.ErrCodeContains(err, errCodeAccessDenied) || tfawserr.ErrCodeContains(err, cloudwatch.ErrCodeInternalServiceFault)) {
if v, ok := d.GetOk("tags"); (!ok || len(v.(map[string]interface{})) == 0) && verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] could not add tags after create for CloudWatch Metric Alarm (%s): %s", d.Id(), err)
return resourceMetricAlarmRead(d, meta)
}
Expand Down Expand Up @@ -407,7 +407,7 @@ func resourceMetricAlarmRead(d *schema.ResourceData, meta interface{}) error {
tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig)

// Some partitions (i.e., ISO) may not support tagging, giving error
if tfawserr.ErrCodeContains(err, errCodeAccessDenied) || tfawserr.ErrCodeContains(err, cloudwatch.ErrCodeInternalServiceFault) {
if verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] Unable to list tags for CloudWatch Metric Alarm %s: %s", d.Id(), err)
return nil
}
Expand Down Expand Up @@ -442,7 +442,7 @@ func resourceMetricAlarmUpdate(d *schema.ResourceData, meta interface{}) error {
err := UpdateTags(conn, arn, o, n)

// Some partitions (i.e., ISO) may not support tagging, giving error
if tfawserr.ErrCodeContains(err, errCodeAccessDenied) || tfawserr.ErrCodeContains(err, cloudwatch.ErrCodeInternalServiceFault) {
if verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] Unable to update tags for CloudWatch Metric Alarm %s: %s", arn, err)
return resourceMetricAlarmRead(d, meta)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/service/cloudwatch/metric_stream.go
Expand Up @@ -149,7 +149,7 @@ func resourceMetricStreamCreate(ctx context.Context, d *schema.ResourceData, met
output, err := conn.PutMetricStreamWithContext(ctx, &params)

// Some partitions (i.e., ISO) may not support tag-on-create
if params.Tags != nil && (tfawserr.ErrCodeContains(err, errCodeAccessDenied) || tfawserr.ErrCodeContains(err, cloudwatch.ErrCodeInternalServiceFault)) {
if params.Tags != nil && verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] CloudWatch Metric Stream (%s) create failed (%s) with tags. Trying create without tags.", d.Id(), err)
params.Tags = nil

Expand All @@ -168,7 +168,7 @@ func resourceMetricStreamCreate(ctx context.Context, d *schema.ResourceData, met
err := UpdateTags(conn, aws.StringValue(output.Arn), nil, tags)

// If default tags only, log and continue. Otherwise, error.
if v, ok := d.GetOk("tags"); (!ok || len(v.(map[string]interface{})) == 0) && (tfawserr.ErrCodeContains(err, errCodeAccessDenied) || tfawserr.ErrCodeContains(err, cloudwatch.ErrCodeInternalServiceFault)) {
if v, ok := d.GetOk("tags"); (!ok || len(v.(map[string]interface{})) == 0) && verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] error adding tags after create for CloudWatch Metric Stream (%s): %s", d.Id(), err)
return resourceMetricStreamRead(ctx, d, meta)
}
Expand Down Expand Up @@ -227,7 +227,7 @@ func resourceMetricStreamRead(ctx context.Context, d *schema.ResourceData, meta
tags, err := ListTags(conn, aws.StringValue(output.Arn))

// Some partitions (i.e., ISO) may not support tagging, giving error
if tfawserr.ErrCodeContains(err, errCodeAccessDenied) || tfawserr.ErrCodeContains(err, cloudwatch.ErrCodeInternalServiceFault) {
if verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] Unable to list tags for CloudWatch Metric Stream %s: %s", d.Id(), err)
return nil
}
Expand Down
5 changes: 0 additions & 5 deletions internal/service/elbv2/consts.go

This file was deleted.

8 changes: 4 additions & 4 deletions internal/service/elbv2/listener.go
Expand Up @@ -435,7 +435,7 @@ func resourceListenerCreate(d *schema.ResourceData, meta interface{}) error {
output, err := retryListenerCreate(conn, params)

// Some partitions may not support tag-on-create
if params.Tags != nil && (tfawserr.ErrCodeContains(err, ErrCodeAccessDenied) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeInvalidConfigurationRequestException) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeOperationNotPermittedException)) {
if params.Tags != nil && verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] ELBv2 Listener (%s) create failed (%s) with tags. Trying create without tags.", lbArn, err)
params.Tags = nil
output, err = retryListenerCreate(conn, params)
Expand All @@ -451,7 +451,7 @@ func resourceListenerCreate(d *schema.ResourceData, meta interface{}) error {
if params.Tags == nil && len(tags) > 0 {
err := UpdateTags(conn, d.Id(), nil, tags)

if v, ok := d.GetOk("tags"); (!ok || len(v.(map[string]interface{})) == 0) && (tfawserr.ErrCodeContains(err, ErrCodeAccessDenied) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeInvalidConfigurationRequestException) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeOperationNotPermittedException)) {
if v, ok := d.GetOk("tags"); (!ok || len(v.(map[string]interface{})) == 0) && verify.CheckISOErrorTagsUnsupported(err) {
// if default tags only, log and continue (i.e., should error if explicitly setting tags and they can't be)
log.Printf("[WARN] error adding tags after create for ELBv2 Listener (%s): %s", d.Id(), err)
return resourceListenerRead(d, meta)
Expand Down Expand Up @@ -534,7 +534,7 @@ func resourceListenerRead(d *schema.ResourceData, meta interface{}) error {

tags, err := ListTags(conn, d.Id())

if tfawserr.ErrCodeContains(err, ErrCodeAccessDenied) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeInvalidConfigurationRequestException) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeOperationNotPermittedException) {
if verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] Unable to list tags for ELBv2 Listener %s: %s", d.Id(), err)
return nil
}
Expand Down Expand Up @@ -643,7 +643,7 @@ func resourceListenerUpdate(d *schema.ResourceData, meta interface{}) error {
}

// ISO partitions may not support tagging, giving error
if tfawserr.ErrCodeContains(err, ErrCodeAccessDenied) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeInvalidConfigurationRequestException) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeOperationNotPermittedException) {
if verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] Unable to update tags for ELBv2 Listener %s: %s", d.Id(), err)
return resourceListenerRead(d, meta)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/service/elbv2/listener_data_source.go
Expand Up @@ -8,10 +8,10 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/elbv2"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)

func DataSourceListener() *schema.Resource {
Expand Down Expand Up @@ -341,7 +341,7 @@ func dataSourceListenerRead(d *schema.ResourceData, meta interface{}) error {

tags, err := ListTags(conn, d.Id())

if tfawserr.ErrCodeContains(err, ErrCodeAccessDenied) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeInvalidConfigurationRequestException) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeOperationNotPermittedException) {
if verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] Unable to list tags for ELBv2 Listener %s: %s", d.Id(), err)
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/service/elbv2/listener_rule.go
Expand Up @@ -513,7 +513,7 @@ func resourceListenerRuleCreate(d *schema.ResourceData, meta interface{}) error
resp, err := retryListenerRuleCreate(conn, d, params, listenerArn)

// Some partitions may not support tag-on-create
if params.Tags != nil && (tfawserr.ErrCodeContains(err, ErrCodeAccessDenied) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeInvalidConfigurationRequestException) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeOperationNotPermittedException)) {
if params.Tags != nil && verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] ELBv2 Listener Rule (%s) create failed (%s) with tags. Trying create without tags.", listenerArn, err)
params.Tags = nil
resp, err = retryListenerRuleCreate(conn, d, params, listenerArn)
Expand All @@ -529,7 +529,7 @@ func resourceListenerRuleCreate(d *schema.ResourceData, meta interface{}) error
if params.Tags == nil && len(tags) > 0 {
err := UpdateTags(conn, d.Id(), nil, tags)

if v, ok := d.GetOk("tags"); (!ok || len(v.(map[string]interface{})) == 0) && (tfawserr.ErrCodeContains(err, ErrCodeAccessDenied) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeInvalidConfigurationRequestException) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeOperationNotPermittedException)) {
if v, ok := d.GetOk("tags"); (!ok || len(v.(map[string]interface{})) == 0) && verify.CheckISOErrorTagsUnsupported(err) {
// if default tags only, log and continue (i.e., should error if explicitly setting tags and they can't be)
log.Printf("[WARN] error adding tags after create for ELBv2 Listener Rule (%s): %s", d.Id(), err)
return resourceListenerRuleRead(d, meta)
Expand Down Expand Up @@ -767,7 +767,7 @@ func resourceListenerRuleRead(d *schema.ResourceData, meta interface{}) error {
// tags at the end because, if not supported, will skip the rest of Read
tags, err := ListTags(conn, d.Id())

if tfawserr.ErrCodeContains(err, ErrCodeAccessDenied) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeInvalidConfigurationRequestException) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeOperationNotPermittedException) {
if verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] Unable to list tags for ELBv2 Listener Rule %s: %s", d.Id(), err)
return nil
}
Expand Down Expand Up @@ -866,7 +866,7 @@ func resourceListenerRuleUpdate(d *schema.ResourceData, meta interface{}) error
}

// ISO partitions may not support tagging, giving error
if tfawserr.ErrCodeContains(err, ErrCodeAccessDenied) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeInvalidConfigurationRequestException) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeOperationNotPermittedException) {
if verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] Unable to update tags for ELBv2 Listener Rule %s: %s", d.Id(), err)
return resourceListenerRuleRead(d, meta)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/service/elbv2/load_balancer.go
Expand Up @@ -361,7 +361,7 @@ func resourceLoadBalancerCreate(d *schema.ResourceData, meta interface{}) error
resp, err := conn.CreateLoadBalancer(elbOpts)

// Some partitions may not support tag-on-create
if elbOpts.Tags != nil && (tfawserr.ErrCodeContains(err, ErrCodeAccessDenied) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeInvalidConfigurationRequestException) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeOperationNotPermittedException)) {
if elbOpts.Tags != nil && verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] ELBv2 Load Balancer (%s) create failed (%s) with tags. Trying create without tags.", name, err)
elbOpts.Tags = nil
resp, err = conn.CreateLoadBalancer(elbOpts)
Expand Down Expand Up @@ -389,7 +389,7 @@ func resourceLoadBalancerCreate(d *schema.ResourceData, meta interface{}) error
err := UpdateTags(conn, d.Id(), nil, tags)

// if default tags only, log and continue (i.e., should error if explicitly setting tags and they can't be)
if v, ok := d.GetOk("tags"); (!ok || len(v.(map[string]interface{})) == 0) && (tfawserr.ErrCodeContains(err, ErrCodeAccessDenied) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeInvalidConfigurationRequestException) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeOperationNotPermittedException)) {
if v, ok := d.GetOk("tags"); (!ok || len(v.(map[string]interface{})) == 0) && verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] error adding tags after create for ELBv2 Load Balancer (%s): %s", d.Id(), err)
return resourceLoadBalancerUpdate(d, meta)
}
Expand Down Expand Up @@ -606,7 +606,7 @@ func resourceLoadBalancerUpdate(d *schema.ResourceData, meta interface{}) error
}

// ISO partitions may not support tagging, giving error
if tfawserr.ErrCodeContains(err, ErrCodeAccessDenied) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeInvalidConfigurationRequestException) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeOperationNotPermittedException) {
if verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] Unable to update tags for ELBv2 Load Balancer %s: %s", d.Id(), err)

_, err := waitLoadBalancerActive(conn, d.Id(), d.Timeout(schema.TimeoutUpdate))
Expand Down Expand Up @@ -885,7 +885,7 @@ func flattenResource(d *schema.ResourceData, meta interface{}, lb *elbv2.LoadBal

tags, err := ListTags(conn, d.Id())

if tfawserr.ErrCodeContains(err, ErrCodeAccessDenied) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeInvalidConfigurationRequestException) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeOperationNotPermittedException) {
if verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] Unable to list tags for ELBv2 Load Balancer %s: %s", d.Id(), err)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/elbv2/load_balancer_data_source.go
Expand Up @@ -306,7 +306,7 @@ func dataSourceLoadBalancerRead(d *schema.ResourceData, meta interface{}) error

tags, err := ListTags(conn, d.Id())

if tfawserr.ErrCodeContains(err, ErrCodeAccessDenied) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeInvalidConfigurationRequestException) || tfawserr.ErrCodeContains(err, elbv2.ErrCodeOperationNotPermittedException) {
if verify.CheckISOErrorTagsUnsupported(err) {
log.Printf("[WARN] Unable to list tags for ELBv2 Load Balancer %s: %s", d.Id(), err)
return nil
}
Expand Down

0 comments on commit 0a67faa

Please sign in to comment.