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
provider/aws: reading multiple pages of aws_efs_file_system tags #12328
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,15 +149,34 @@ func resourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) erro | |
return fmt.Errorf("EFS file system %q could not be found.", d.Id()) | ||
} | ||
|
||
tagsResp, err := conn.DescribeTags(&efs.DescribeTagsInput{ | ||
FileSystemId: aws.String(d.Id()), | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("Error retrieving EC2 tags for EFS file system (%q): %s", | ||
d.Id(), err.Error()) | ||
tags := make([]*efs.Tag, 0) | ||
var marker string | ||
for { | ||
params := &efs.DescribeTagsInput{ | ||
FileSystemId: aws.String(d.Id()), | ||
} | ||
if marker != "" { | ||
params.Marker = aws.String(marker) | ||
} | ||
|
||
tagsResp, err := conn.DescribeTags(params) | ||
if err != nil { | ||
return fmt.Errorf("Error retrieving EC2 tags for EFS file system (%q): %s", | ||
d.Id(), err.Error()) | ||
} | ||
|
||
for _, tag := range tagsResp.Tags { | ||
tags = append(tags, tag) | ||
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. style nit: instead of a
|
||
} | ||
|
||
if tagsResp.NextMarker != nil { | ||
marker = *tagsResp.NextMarker | ||
} else { | ||
break | ||
} | ||
} | ||
|
||
err = d.Set("tags", tagsToMapEFS(tagsResp.Tags)) | ||
err = d.Set("tags", tagsToMapEFS(tags)) | ||
if err != nil { | ||
return err | ||
} | ||
|
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 |
---|---|---|
|
@@ -87,7 +87,7 @@ func TestAccAWSEFSFileSystem_basic(t *testing.T) { | |
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckEfsFileSystemDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
{ | ||
Config: testAccAWSEFSFileSystemConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
|
@@ -103,7 +103,7 @@ func TestAccAWSEFSFileSystem_basic(t *testing.T) { | |
), | ||
), | ||
}, | ||
resource.TestStep{ | ||
{ | ||
Config: testAccAWSEFSFileSystemConfigWithTags, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckEfsFileSystem( | ||
|
@@ -122,7 +122,7 @@ func TestAccAWSEFSFileSystem_basic(t *testing.T) { | |
), | ||
), | ||
}, | ||
resource.TestStep{ | ||
{ | ||
Config: testAccAWSEFSFileSystemConfigWithPerformanceMode, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckEfsFileSystem( | ||
|
@@ -142,6 +142,32 @@ func TestAccAWSEFSFileSystem_basic(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccAWSEFSFileSystem_pagedTags(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckEfsFileSystemDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAWSEFSFileSystemConfigPagedTags, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
"aws_efs_file_system.foo", | ||
"tags.%", | ||
"11"), | ||
//testAccCheckEfsFileSystem( | ||
// "aws_efs_file_system.foo", | ||
//), | ||
//testAccCheckEfsFileSystemPerformanceMode( | ||
// "aws_efs_file_system.foo", | ||
// "generalPurpose", | ||
//), | ||
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. dead code |
||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckEfsFileSystemDestroy(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).efsconn | ||
for _, rs := range s.RootModule().Resources { | ||
|
@@ -286,6 +312,25 @@ resource "aws_efs_file_system" "foo" { | |
} | ||
` | ||
|
||
const testAccAWSEFSFileSystemConfigPagedTags = ` | ||
resource "aws_efs_file_system" "foo" { | ||
creation_token = "radeksimko" | ||
tags { | ||
Name = "foo-efs" | ||
Another = "tag" | ||
Test = "yes" | ||
User = "root" | ||
Page = "1" | ||
Environment = "prod" | ||
CostCenter = "terraform" | ||
AcceptanceTest = "PagedTags" | ||
CreationToken = "radek" | ||
PerfMode = "max" | ||
Region = "us-west-2" | ||
} | ||
} | ||
` | ||
|
||
const testAccAWSEFSFileSystemConfigWithTags = ` | ||
resource "aws_efs_file_system" "foo-with-tags" { | ||
creation_token = "yada_yada" | ||
|
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.
A thought: log the failure but
break
out of thefor
instead of returning an error. This could allow Terraform to continue creating all the things, but possibly show a diff later because there was some error in retrieving all the tags.Just a thought, maybe you feel erring when failing to retrieve tags here is correct, so I trust/defer to your call here