Skip to content
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

r/datasync_s3_location - add validation agent_arns, s3_bucket_arn and s3_config. bucket_access_role_arn #21661

Merged
merged 3 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/21661.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_datasync_s3_location: Add validation to `agent_arns`, `s3_bucket_arn` and `s3_config.bucket_access_role_arn` arguments
```
9 changes: 6 additions & 3 deletions internal/service/datasync/location_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ func ResourceLocationS3() *schema.Resource {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: verify.ValidARN,
},
},
"s3_bucket_arn": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.NoZeroValues,
ValidateFunc: verify.ValidARN,
},
"s3_config": {
Type: schema.TypeList,
Expand All @@ -57,7 +60,7 @@ func ResourceLocationS3() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.NoZeroValues,
ValidateFunc: verify.ValidARN,
},
},
},
Expand Down
33 changes: 6 additions & 27 deletions internal/service/datasync/location_s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
tfdatasync "github.com/hashicorp/terraform-provider-aws/internal/service/datasync"
)

func TestAccDataSyncLocationS3_basic(t *testing.T) {
Expand Down Expand Up @@ -105,8 +106,8 @@ func TestAccDataSyncLocationS3_disappears(t *testing.T) {
Config: testAccLocationS3Config(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckLocationS3Exists(resourceName, &locationS31),
testAccCheckLocationS3Disappears(&locationS31),
),
acctest.CheckResourceDisappears(acctest.Provider, tfdatasync.ResourceLocationS3(), resourceName),
acctest.CheckResourceDisappears(acctest.Provider, tfdatasync.ResourceLocationS3(), resourceName)),
ExpectNonEmptyPlan: true,
},
},
Expand Down Expand Up @@ -215,20 +216,6 @@ func testAccCheckLocationS3Exists(resourceName string, locationS3 *datasync.Desc
}
}

func testAccCheckLocationS3Disappears(location *datasync.DescribeLocationS3Output) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).DataSyncConn

input := &datasync.DeleteLocationInput{
LocationArn: location.LocationArn,
}

_, err := conn.DeleteLocation(input)

return err
}
}

func testAccCheckLocationS3NotRecreated(i, j *datasync.DescribeLocationS3Output) resource.TestCheckFunc {
return func(s *terraform.State) error {
if !aws.TimeValue(i.CreationTime).Equal(aws.TimeValue(j.CreationTime)) {
Expand All @@ -242,7 +229,7 @@ func testAccCheckLocationS3NotRecreated(i, j *datasync.DescribeLocationS3Output)
func testAccLocationS3BaseConfig(rName string) string {
return fmt.Sprintf(`
resource "aws_iam_role" "test" {
name = %q
name = %[1]q

assume_role_policy = <<POLICY
{
Expand Down Expand Up @@ -280,10 +267,10 @@ POLICY
}

resource "aws_s3_bucket" "test" {
bucket = %q
bucket = %[1]q
force_destroy = true
}
`, rName, rName)
`, rName)
}

func testAccLocationS3Config(rName string) string {
Expand All @@ -295,8 +282,6 @@ resource "aws_datasync_location_s3" "test" {
s3_config {
bucket_access_role_arn = aws_iam_role.test.arn
}

depends_on = [aws_iam_role_policy.test]
}
`
}
Expand All @@ -311,8 +296,6 @@ resource "aws_datasync_location_s3" "test" {
s3_config {
bucket_access_role_arn = aws_iam_role.test.arn
}

depends_on = [aws_iam_role_policy.test]
}
`
}
Expand All @@ -330,8 +313,6 @@ resource "aws_datasync_location_s3" "test" {
tags = {
%q = %q
}

depends_on = [aws_iam_role_policy.test]
}
`, key1, value1)
}
Expand All @@ -350,8 +331,6 @@ resource "aws_datasync_location_s3" "test" {
%q = %q
%q = %q
}

depends_on = [aws_iam_role_policy.test]
}
`, key1, value1, key2, value2)
}