Skip to content

Commit

Permalink
Merge pull request #8931 from terraform-providers/b-aws_iam_service_l…
Browse files Browse the repository at this point in the history
…inked_role-appautoscaling

resource/aws_iam_service_linked_role: Automatically suppress Application Autoscaling custom_suffix differences
  • Loading branch information
bflad committed Jun 10, 2019
2 parents 1f6f2dc + 79dfeb3 commit 0a04f07
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
6 changes: 6 additions & 0 deletions aws/resource_aws_iam_service_linked_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ func resourceAwsIamServiceLinkedRole() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if strings.Contains(d.Get("aws_service_name").(string), ".application-autoscaling.") && new == "" {
return true
}
return false
},
},

"description": {
Expand Down
42 changes: 40 additions & 2 deletions aws/resource_aws_iam_service_linked_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ func TestDecodeIamServiceLinkedRoleID(t *testing.T) {
CustomSuffix: "custom-suffix",
ErrCount: 0,
},
{
Input: "arn:aws:iam::123456789012:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable",
ServiceName: "dynamodb.application-autoscaling.amazonaws.com",
RoleName: "AWSServiceRoleForApplicationAutoScaling_DynamoDBTable",
CustomSuffix: "DynamoDBTable",
ErrCount: 0,
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -158,7 +165,7 @@ func TestAccAWSIAMServiceLinkedRole_basic(t *testing.T) {
Config: testAccAWSIAMServiceLinkedRoleConfig(awsServiceName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSIAMServiceLinkedRoleExists(resourceName),
resource.TestMatchResourceAttr(resourceName, "arn", regexp.MustCompile(fmt.Sprintf("^arn:[^:]+:iam::[^:]+:role%s%s$", path, name))),
testAccCheckResourceAttrGlobalARN(resourceName, "arn", "iam", fmt.Sprintf("role%s%s", path, name)),
resource.TestCheckResourceAttr(resourceName, "aws_service_name", awsServiceName),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "name", name),
Expand Down Expand Up @@ -193,7 +200,38 @@ func TestAccAWSIAMServiceLinkedRole_CustomSuffix(t *testing.T) {
Config: testAccAWSIAMServiceLinkedRoleConfig_CustomSuffix(awsServiceName, customSuffix),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSIAMServiceLinkedRoleExists(resourceName),
resource.TestMatchResourceAttr(resourceName, "arn", regexp.MustCompile(fmt.Sprintf("^arn:[^:]+:iam::[^:]+:role%s%s$", path, name))),
testAccCheckResourceAttrGlobalARN(resourceName, "arn", "iam", fmt.Sprintf("role%s%s", path, name)),
resource.TestCheckResourceAttr(resourceName, "name", name),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

// Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/4439
func TestAccAWSIAMServiceLinkedRole_CustomSuffix_DiffSuppressFunc(t *testing.T) {
resourceName := "aws_iam_service_linked_role.test"
awsServiceName := "custom-resource.application-autoscaling.amazonaws.com"
name := "AWSServiceRoleForApplicationAutoScaling_CustomResource"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSIAMServiceLinkedRoleDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSIAMServiceLinkedRoleConfig(awsServiceName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSIAMServiceLinkedRoleExists(resourceName),
testAccCheckResourceAttrGlobalARN(resourceName, "arn", "iam", fmt.Sprintf("role/aws-service-role/%s/%s", awsServiceName, name)),
resource.TestCheckResourceAttr(resourceName, "custom_suffix", "CustomResource"),
resource.TestCheckResourceAttr(resourceName, "name", name),
),
},
Expand Down

0 comments on commit 0a04f07

Please sign in to comment.