-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Add Tag Support to Resource Group Resource #10640
Merged
bflad
merged 11 commits into
hashicorp:master
from
DrFaust92:resourcegroups-tag-support
Nov 19, 2019
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c0f6d5e
Merge pull request #5 from terraform-providers/master
DrFaust92 07ddc49
Merge pull request #6 from terraform-providers/master
DrFaust92 653c81e
Merge pull request #7 from terraform-providers/master
DrFaust92 e5b7302
Merge pull request #8 from terraform-providers/master
DrFaust92 199b669
Merge pull request #9 from terraform-providers/master
DrFaust92 d94bf3f
Merge pull request #10 from terraform-providers/master
DrFaust92 ccc05a6
Merge pull request #11 from terraform-providers/master
DrFaust92 45a3c82
Merge pull request #12 from terraform-providers/master
DrFaust92 b059888
add resource groups support in keyvaluetags lib
DrFaust92 f2f4d09
add tag support for resource groups
DrFaust92 0bf3214
remove keyvaluetags change
DrFaust92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,25 +12,13 @@ import ( | |
) | ||
|
||
func TestAccAWSResourceGroup_basic(t *testing.T) { | ||
var v resourcegroups.Group | ||
resourceName := "aws_resourcegroups_group.test" | ||
n := fmt.Sprintf("test-group-%d", acctest.RandInt()) | ||
|
||
desc1 := "Hello World" | ||
desc2 := "Foo Bar" | ||
|
||
query1 := `{ | ||
"ResourceTypeFilters": [ | ||
"AWS::EC2::Instance" | ||
], | ||
"TagFilters": [ | ||
{ | ||
"Key": "Stage", | ||
"Values": ["Test"] | ||
} | ||
] | ||
} | ||
` | ||
|
||
query2 := `{ | ||
"ResourceTypeFilters": [ | ||
"AWS::EC2::Instance" | ||
|
@@ -50,12 +38,12 @@ func TestAccAWSResourceGroup_basic(t *testing.T) { | |
CheckDestroy: testAccCheckAWSResourceGroupDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSResourceGroupConfig_basic(n, desc1, query1), | ||
Config: testAccAWSResourceGroupConfig_basic(n, desc1, testAccAWSResourceGroupConfigQuery), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSResourceGroupExists(resourceName), | ||
testAccCheckAWSResourceGroupExists(resourceName, &v), | ||
resource.TestCheckResourceAttr(resourceName, "name", n), | ||
resource.TestCheckResourceAttr(resourceName, "description", desc1), | ||
resource.TestCheckResourceAttr(resourceName, "resource_query.0.query", query1+"\n"), | ||
resource.TestCheckResourceAttr(resourceName, "resource_query.0.query", testAccAWSResourceGroupConfigQuery+"\n"), | ||
resource.TestCheckResourceAttrSet(resourceName, "arn"), | ||
), | ||
}, | ||
|
@@ -75,7 +63,52 @@ func TestAccAWSResourceGroup_basic(t *testing.T) { | |
}) | ||
} | ||
|
||
func testAccCheckAWSResourceGroupExists(n string) resource.TestCheckFunc { | ||
func TestAccAWSResourceGroup_tags(t *testing.T) { | ||
var v resourcegroups.Group | ||
resourceName := "aws_resourcegroups_group.test" | ||
n := fmt.Sprintf("test-group-%d", acctest.RandInt()) | ||
desc1 := "Hello World" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSResourceGroupDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSResourceGroupConfigTags1(n, desc1, testAccAWSResourceGroupConfigQuery, "key1", "value1"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSResourceGroupExists(resourceName, &v), | ||
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), | ||
resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), | ||
), | ||
}, | ||
{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
{ | ||
Config: testAccAWSResourceGroupConfigTags2(n, desc1, testAccAWSResourceGroupConfigQuery, "key1", "value1updated", "key2", "value2"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSResourceGroupExists(resourceName, &v), | ||
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), | ||
resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1updated"), | ||
resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), | ||
), | ||
}, | ||
{ | ||
Config: testAccAWSResourceGroupConfigTags1(n, desc1, testAccAWSResourceGroupConfigQuery, "key2", "value2"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSResourceGroupExists(resourceName, &v), | ||
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), | ||
resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAWSResourceGroupExists(n string, v *resourcegroups.Group) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
|
@@ -88,17 +121,26 @@ func testAccCheckAWSResourceGroupExists(n string) resource.TestCheckFunc { | |
|
||
conn := testAccProvider.Meta().(*AWSClient).resourcegroupsconn | ||
|
||
_, err := conn.GetGroup(&resourcegroups.GetGroupInput{ | ||
resp, err := conn.GetGroup(&resourcegroups.GetGroupInput{ | ||
GroupName: aws.String(rs.Primary.ID), | ||
}) | ||
|
||
return err | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if *resp.Group.Name == rs.Primary.ID { | ||
*v = *resp.Group | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("Resource Group (%s) not found", rs.Primary.ID) | ||
} | ||
} | ||
|
||
func testAccCheckAWSResourceGroupDestroy(s *terraform.State) error { | ||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "aws_waf_rule_group" { | ||
if rs.Type != "aws_resourcegroups_group" { | ||
continue | ||
} | ||
|
||
|
@@ -124,7 +166,20 @@ func testAccCheckAWSResourceGroupDestroy(s *terraform.State) error { | |
return nil | ||
} | ||
|
||
func testAccAWSResourceGroupConfig_basic(rName string, desc string, query string) string { | ||
const testAccAWSResourceGroupConfigQuery = `{ | ||
"ResourceTypeFilters": [ | ||
"AWS::EC2::Instance" | ||
], | ||
"TagFilters": [ | ||
{ | ||
"Key": "Stage", | ||
"Values": ["Test"] | ||
} | ||
] | ||
} | ||
` | ||
|
||
func testAccAWSResourceGroupConfig_basic(rName, desc, query string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_resourcegroups_group" "test" { | ||
name = "%s" | ||
|
@@ -138,3 +193,42 @@ JSON | |
} | ||
`, rName, desc, query) | ||
} | ||
|
||
func testAccAWSResourceGroupConfigTags1(rName, desc, query, tag1Key, tag1Value string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_resourcegroups_group" "test" { | ||
name = "%s" | ||
description = "%s" | ||
|
||
resource_query { | ||
query = <<JSON | ||
%s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: We prefer to hardcode values like these into the test configurations so they can more easily be copy-pasted for manual Terraform CLI usage. |
||
JSON | ||
} | ||
|
||
tags = { | ||
%q = %q | ||
} | ||
} | ||
`, rName, desc, query, tag1Key, tag1Value) | ||
} | ||
|
||
func testAccAWSResourceGroupConfigTags2(rName, desc, query, tag1Key, tag1Value, tag2Key, tag2Value string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_resourcegroups_group" "test" { | ||
name = "%s" | ||
description = "%s" | ||
|
||
resource_query { | ||
query = <<JSON | ||
%s | ||
JSON | ||
} | ||
|
||
tags = { | ||
%q = %q | ||
%q = %q | ||
} | ||
} | ||
`, rName, desc, query, tag1Key, tag1Value, tag2Key, tag2Value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This acceptance testing does not need to verify anything with this attribute, so it should omitted or hardcoded in the test configurations.