diff --git a/aws/resource_aws_config_config_rule.go b/aws/resource_aws_config_config_rule.go index f957a7d430c..c3ee13d1b49 100644 --- a/aws/resource_aws_config_config_rule.go +++ b/aws/resource_aws_config_config_rule.go @@ -146,14 +146,10 @@ func resourceAwsConfigConfigRulePut(d *schema.ResourceData, meta interface{}) er name := d.Get("name").(string) ruleInput := configservice.ConfigRule{ ConfigRuleName: aws.String(name), + Scope: expandConfigRuleScope(d.Get("scope").([]interface{})), Source: expandConfigRuleSource(d.Get("source").([]interface{})), } - scopes := d.Get("scope").([]interface{}) - if len(scopes) > 0 { - ruleInput.Scope = expandConfigRuleScope(scopes[0].(map[string]interface{})) - } - if v, ok := d.GetOk("description"); ok { ruleInput.Description = aws.String(v.(string)) } diff --git a/aws/resource_aws_config_config_rule_test.go b/aws/resource_aws_config_config_rule_test.go index d8db29ba197..52e0802c195 100644 --- a/aws/resource_aws_config_config_rule_test.go +++ b/aws/resource_aws_config_config_rule_test.go @@ -159,6 +159,86 @@ func testAccConfigConfigRule_importLambda(t *testing.T) { }) } +func testAccConfigConfigRule_Scope_TagKey(t *testing.T) { + var configRule configservice.ConfigRule + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_config_config_rule.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckConfigConfigRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAccConfigConfigRuleConfig_Scope_TagKey(rName, "key1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckConfigConfigRuleExists(resourceName, &configRule), + resource.TestCheckResourceAttr(resourceName, "scope.#", "1"), + resource.TestCheckResourceAttr(resourceName, "scope.0.tag_key", "key1"), + ), + }, + { + Config: testAccConfigConfigRuleConfig_Scope_TagKey(rName, "key2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckConfigConfigRuleExists(resourceName, &configRule), + resource.TestCheckResourceAttr(resourceName, "scope.#", "1"), + resource.TestCheckResourceAttr(resourceName, "scope.0.tag_key", "key2"), + ), + }, + }, + }) +} + +func testAccConfigConfigRule_Scope_TagKey_Empty(t *testing.T) { + var configRule configservice.ConfigRule + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_config_config_rule.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckConfigConfigRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAccConfigConfigRuleConfig_Scope_TagKey(rName, ""), + Check: resource.ComposeTestCheckFunc( + testAccCheckConfigConfigRuleExists(resourceName, &configRule), + ), + }, + }, + }) +} + +func testAccConfigConfigRule_Scope_TagValue(t *testing.T) { + var configRule configservice.ConfigRule + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_config_config_rule.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckConfigConfigRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAccConfigConfigRuleConfig_Scope_TagValue(rName, "value1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckConfigConfigRuleExists(resourceName, &configRule), + resource.TestCheckResourceAttr(resourceName, "scope.#", "1"), + resource.TestCheckResourceAttr(resourceName, "scope.0.tag_value", "value1"), + ), + }, + { + Config: testAccConfigConfigRuleConfig_Scope_TagValue(rName, "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckConfigConfigRuleExists(resourceName, &configRule), + resource.TestCheckResourceAttr(resourceName, "scope.#", "1"), + resource.TestCheckResourceAttr(resourceName, "scope.0.tag_value", "value2"), + ), + }, + }, + }) +} + func testAccCheckConfigConfigRuleName(n, desired string, obj *configservice.ConfigRule) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -224,6 +304,42 @@ func testAccCheckConfigConfigRuleDestroy(s *terraform.State) error { return nil } +func testAccConfigConfigRuleConfig_base(rName string) string { + return fmt.Sprintf(` +data "aws_partition" "current" {} + +resource "aws_config_configuration_recorder" "test" { + name = %q + role_arn = "${aws_iam_role.test.arn}" +} + +resource "aws_iam_role" "test" { + name = %q + + assume_role_policy = <