diff --git a/cloudtruth/resource_aws_integration.go b/cloudtruth/resource_aws_integration.go index 86259e8..1896298 100644 --- a/cloudtruth/resource_aws_integration.go +++ b/cloudtruth/resource_aws_integration.go @@ -205,7 +205,7 @@ func resourceAWSIntegrationRead(ctx context.Context, d *schema.ResourceData, met } resourceTags := integration.GetResourceTags() if resourceTags != nil { - err = d.Set("resourceTags", resourceTags) + err = d.Set("resource_tags", resourceTags) if err != nil { return diag.FromErr(err) } diff --git a/cloudtruth/resource_aws_integration_test.go b/cloudtruth/resource_aws_integration_test.go index 8660588..f73e258 100644 --- a/cloudtruth/resource_aws_integration_test.go +++ b/cloudtruth/resource_aws_integration_test.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "math/rand" + "strings" "testing" ) @@ -13,28 +14,49 @@ func TestAccResourceAWSIntegrationBasic(t *testing.T) { rand.Int63n(1e12)), fmt.Sprintf("%012d", rand.Int63n(1e12)) role, updateRole := "SomeAWSRole", "SomeOtherRole" kmsKeyID, updateKMSKeyID := "10bfd420-0369-4be3-8546-20f21d7bf2a7", "XXXfd420-0369-4be3-8546-20f21d7bf2a7" + resourceTags := map[string]string{ + "tag1": "tag1Val", + } + updateResourceTags := map[string]string{ + "tag1": "tag1ValUpdated", + "tag2": "tag1Val", + } resource.Test(t, resource.TestCase{ ProviderFactories: testProviderFactories, PreCheck: func() { testAccPreCheck(t) }, Steps: []resource.TestStep{ { - Config: testAccResourceAWSIntegrationBasic(resourceName, accountID, role, kmsKeyID, true), + Config: testAccResourceAWSIntegrationBasic(resourceName, accountID, role, kmsKeyID, true, resourceTags), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "account_id", accountID), resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "role", role), resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "kms_key_id", kmsKeyID), resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "writable", fmt.Sprint(true)), + resource.TestCheckResourceAttrSet(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "resource_tags.tag1"), resource.TestCheckResourceAttrSet(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "external_id"), ), SkipFunc: isSelfHostedOrStaging, }, { - Config: testAccResourceAWSIntegrationBasic(resourceName, updateAccountID, updateRole, updateKMSKeyID, false), + Config: testAccResourceAWSIntegrationBasic(resourceName, updateAccountID, updateRole, updateKMSKeyID, false, updateResourceTags), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "account_id", updateAccountID), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "role", updateRole), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "kms_key_id", updateKMSKeyID), + resource.TestCheckResourceAttrSet(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "resource_tags.tag1"), + resource.TestCheckResourceAttrSet(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "resource_tags.tag2"), + resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "writable", fmt.Sprint(false)), + ), + SkipFunc: isSelfHostedOrStaging, + }, + { + Config: testAccResourceAWSIntegrationBasic(resourceName, updateAccountID, updateRole, updateKMSKeyID, false, nil), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "account_id", updateAccountID), resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "role", updateRole), resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "kms_key_id", updateKMSKeyID), + resource.TestCheckNoResourceAttr(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "resource_tags.tag1"), resource.TestCheckResourceAttr(fmt.Sprintf("cloudtruth_aws_integration.%s", resourceName), "writable", fmt.Sprint(false)), ), SkipFunc: isSelfHostedOrStaging, @@ -43,7 +65,17 @@ func TestAccResourceAWSIntegrationBasic(t *testing.T) { }) } -func testAccResourceAWSIntegrationBasic(resource, accountID, role, kmsKeyID string, writable bool) string { +func testAccResourceAWSIntegrationBasic(resource, accountID, role, kmsKeyID string, writable bool, resourceTags map[string]string) string { + resourceTagsStr := "" + if len(resourceTags) > 0 { + var tags []string + for k, v := range resourceTags { + tags = append(tags, fmt.Sprintf(`%s = "%s"`, k, v)) + } + resourceTagsStr = fmt.Sprintf("resource_tags = {\n %s\n }\n", strings.Join(tags, "\n ")) + } else { + resourceTagsStr = "" + } return fmt.Sprintf(` resource "cloudtruth_aws_integration" "%s" { account_id = "%s" @@ -52,6 +84,7 @@ func testAccResourceAWSIntegrationBasic(resource, accountID, role, kmsKeyID stri writable = "%t" aws_enabled_regions = ["us-east-2", "us-east-1"] aws_enabled_services = ["secretsmanager", "ssm"] + %s } - `, resource, accountID, role, kmsKeyID, writable) + `, resource, accountID, role, kmsKeyID, writable, resourceTagsStr) }