From 26926aca7723a6441655be2607d2dde535f301b7 Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Wed, 1 Mar 2017 22:09:13 +0000 Subject: [PATCH] provider/aws: reading multiple pages of aws_efs_file_system tags (#12328) Fixes: #12232 ``` % make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSEFSFileSystem_pagedTags' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSEFSFileSystem_pagedTags -timeout 120m === RUN TestAccAWSEFSFileSystem_pagedTags --- PASS: TestAccAWSEFSFileSystem_pagedTags (39.51s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 39.537s ``` --- .../aws/resource_aws_efs_file_system.go | 33 +++++++++--- .../aws/resource_aws_efs_file_system_test.go | 51 +++++++++++++++++-- 2 files changed, 74 insertions(+), 10 deletions(-) diff --git a/builtin/providers/aws/resource_aws_efs_file_system.go b/builtin/providers/aws/resource_aws_efs_file_system.go index 7a4591b03..445242d4d 100644 --- a/builtin/providers/aws/resource_aws_efs_file_system.go +++ b/builtin/providers/aws/resource_aws_efs_file_system.go @@ -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) + } + + 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 } diff --git a/builtin/providers/aws/resource_aws_efs_file_system_test.go b/builtin/providers/aws/resource_aws_efs_file_system_test.go index 764b98a89..c404679c2 100644 --- a/builtin/providers/aws/resource_aws_efs_file_system_test.go +++ b/builtin/providers/aws/resource_aws_efs_file_system_test.go @@ -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", + //), + ), + }, + }, + }) +} + 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"