Skip to content

Commit

Permalink
tests/provider: Update resource testing to 0.12 syntax (S3/Sa Resources)
Browse files Browse the repository at this point in the history
  • Loading branch information
YakDriver committed Aug 17, 2020
1 parent 6a468af commit 1e77ea9
Show file tree
Hide file tree
Showing 15 changed files with 793 additions and 693 deletions.
77 changes: 44 additions & 33 deletions aws/resource_aws_s3_access_point_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,32 +171,43 @@ func TestAccAWSS3AccessPoint_Policy(t *testing.T) {
resourceName := "aws_s3_access_point.test"

expectedPolicyText1 := func() string {
return fmt.Sprintf(`
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "",
"Effect": "Allow",
"Principal": {"AWS":"*"},
"Action": "s3:GetObjectTagging",
"Resource": ["arn:%s:s3:%s:%s:accesspoint/%s/object/*"]
}]
}
`, testAccGetPartition(), testAccGetRegion(), testAccGetAccountID(), rName)
return fmt.Sprintf(`{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObjectTagging",
"Resource": [
"arn:%s:s3:%s:%s:accesspoint/%s/object/*"
]
}
]
}`, testAccGetPartition(), testAccGetRegion(), testAccGetAccountID(), rName)
}
expectedPolicyText2 := func() string {
return fmt.Sprintf(`
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "",
"Effect": "Allow",
"Principal": {"AWS":"*"},
"Action": ["s3:GetObjectLegalHold","s3:GetObjectRetention"],
"Resource": ["arn:%s:s3:%s:%s:accesspoint/%s/object/*"]
}]
}
`, testAccGetPartition(), testAccGetRegion(), testAccGetAccountID(), rName)
return fmt.Sprintf(`{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"s3:GetObjectLegalHold",
"s3:GetObjectRetention"
],
"Resource": [
"arn:%s:s3:%s:%s:accesspoint/%s/object/*"
]
}
]
}`, testAccGetPartition(), testAccGetRegion(), testAccGetAccountID(), rName)
}

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -460,7 +471,7 @@ resource "aws_s3_bucket" "test" {
}
resource "aws_s3_access_point" "test" {
bucket = "${aws_s3_bucket.test.bucket}"
bucket = aws_s3_bucket.test.bucket
name = %[2]q
}
`, bucketName, accessPointName)
Expand All @@ -473,9 +484,9 @@ resource "aws_s3_bucket" "test" {
}
resource "aws_s3_access_point" "test" {
bucket = "${aws_s3_bucket.test.bucket}"
bucket = aws_s3_bucket.test.bucket
name = %[1]q
policy = "${data.aws_iam_policy_document.test.json}"
policy = data.aws_iam_policy_document.test.json
public_access_block_configuration {
block_public_acls = true
Expand Down Expand Up @@ -517,9 +528,9 @@ resource "aws_s3_bucket" "test" {
}
resource "aws_s3_access_point" "test" {
bucket = "${aws_s3_bucket.test.bucket}"
bucket = aws_s3_bucket.test.bucket
name = %[1]q
policy = "${data.aws_iam_policy_document.test.json}"
policy = data.aws_iam_policy_document.test.json
public_access_block_configuration {
block_public_acls = true
Expand Down Expand Up @@ -562,7 +573,7 @@ resource "aws_s3_bucket" "test" {
}
resource "aws_s3_access_point" "test" {
bucket = "${aws_s3_bucket.test.bucket}"
bucket = aws_s3_bucket.test.bucket
name = %[1]q
public_access_block_configuration {
Expand All @@ -582,7 +593,7 @@ resource "aws_s3_bucket" "test" {
}
resource "aws_s3_access_point" "test" {
bucket = "${aws_s3_bucket.test.bucket}"
bucket = aws_s3_bucket.test.bucket
name = %[1]q
public_access_block_configuration {
Expand Down Expand Up @@ -610,11 +621,11 @@ resource "aws_s3_bucket" "test" {
}
resource "aws_s3_access_point" "test" {
bucket = "${aws_s3_bucket.test.bucket}"
bucket = aws_s3_bucket.test.bucket
name = %[1]q
vpc_configuration {
vpc_id = "${aws_vpc.test.id}"
vpc_id = aws_vpc.test.id
}
}
`, rName)
Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_s3_account_public_access_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func testAccAWSS3AccountPublicAccessBlockConfigAccountId() string {
data "aws_caller_identity" "test" {}
resource "aws_s3_account_public_access_block" "test" {
account_id = "${data.aws_caller_identity.test.account_id}"
account_id = data.aws_caller_identity.test.account_id
}
`
}
Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_s3_bucket_analytics_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ resource "aws_s3_bucket_analytics_configuration" "test" {
storage_class_analysis {
data_export {
output_schema_version = "V_1"
destination {
s3_bucket_destination {
format = "CSV"
Expand Down Expand Up @@ -1167,7 +1168,6 @@ func TestFlattenS3StorageClassAnalysis(t *testing.T) {
map[string]interface{}{
"s3_bucket_destination": []interface{}{
map[string]interface{}{

"bucket_arn": "arn:aws:s3",
"format": s3.AnalyticsS3ExportFileFormatCsv,
},
Expand Down
16 changes: 8 additions & 8 deletions aws/resource_aws_s3_bucket_inventory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func testAccAWSS3BucketInventoryConfig(bucketName, inventoryName string) string
data "aws_caller_identity" "current" {}
resource "aws_s3_bucket_inventory" "test" {
bucket = "${aws_s3_bucket.test.id}"
bucket = aws_s3_bucket.test.id
name = %[1]q
included_object_versions = "All"
Expand All @@ -224,8 +224,8 @@ resource "aws_s3_bucket_inventory" "test" {
destination {
bucket {
format = "ORC"
bucket_arn = "${aws_s3_bucket.test.arn}"
account_id = "${data.aws_caller_identity.current.account_id}"
bucket_arn = aws_s3_bucket.test.arn
account_id = data.aws_caller_identity.current.account_id
prefix = "inventory"
}
}
Expand All @@ -236,7 +236,7 @@ resource "aws_s3_bucket_inventory" "test" {
func testAccAWSS3BucketInventoryConfigEncryptWithSSES3(bucketName, inventoryName string) string {
return testAccAWSS3BucketInventoryConfigBucket(bucketName) + fmt.Sprintf(`
resource "aws_s3_bucket_inventory" "test" {
bucket = "${aws_s3_bucket.test.id}"
bucket = aws_s3_bucket.test.id
name = %[1]q
included_object_versions = "Current"
Expand All @@ -248,7 +248,7 @@ resource "aws_s3_bucket_inventory" "test" {
destination {
bucket {
format = "CSV"
bucket_arn = "${aws_s3_bucket.test.arn}"
bucket_arn = aws_s3_bucket.test.arn
encryption {
sse_s3 {}
Expand All @@ -267,7 +267,7 @@ resource "aws_kms_key" "test" {
}
resource "aws_s3_bucket_inventory" "test" {
bucket = "${aws_s3_bucket.test.id}"
bucket = aws_s3_bucket.test.id
name = %[2]q
included_object_versions = "Current"
Expand All @@ -279,11 +279,11 @@ resource "aws_s3_bucket_inventory" "test" {
destination {
bucket {
format = "Parquet"
bucket_arn = "${aws_s3_bucket.test.arn}"
bucket_arn = aws_s3_bucket.test.arn
encryption {
sse_kms {
key_id = "${aws_kms_key.test.arn}"
key_id = aws_kms_key.test.arn
}
}
}
Expand Down
17 changes: 9 additions & 8 deletions aws/resource_aws_s3_bucket_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,9 @@ func testAccAWSS3BucketMetricsConfigWithEmptyFilter(bucketName, metricName strin
%s
resource "aws_s3_bucket_metric" "test" {
bucket = "${aws_s3_bucket.bucket.id}"
name = "%s"
bucket = aws_s3_bucket.bucket.id
name = "%s"
filter {}
}
`, testAccAWSS3BucketMetricsConfigBucket(bucketName), metricName)
Expand All @@ -648,7 +649,7 @@ func testAccAWSS3BucketMetricsConfigWithFilterPrefix(bucketName, metricName, pre
%s
resource "aws_s3_bucket_metric" "test" {
bucket = "${aws_s3_bucket.bucket.id}"
bucket = aws_s3_bucket.bucket.id
name = "%s"
filter {
Expand All @@ -663,7 +664,7 @@ func testAccAWSS3BucketMetricsConfigWithFilterPrefixAndMultipleTags(bucketName,
%s
resource "aws_s3_bucket_metric" "test" {
bucket = "${aws_s3_bucket.bucket.id}"
bucket = aws_s3_bucket.bucket.id
name = "%s"
filter {
Expand All @@ -683,7 +684,7 @@ func testAccAWSS3BucketMetricsConfigWithFilterPrefixAndSingleTag(bucketName, met
%s
resource "aws_s3_bucket_metric" "test" {
bucket = "${aws_s3_bucket.bucket.id}"
bucket = aws_s3_bucket.bucket.id
name = "%s"
filter {
Expand All @@ -702,7 +703,7 @@ func testAccAWSS3BucketMetricsConfigWithFilterMultipleTags(bucketName, metricNam
%s
resource "aws_s3_bucket_metric" "test" {
bucket = "${aws_s3_bucket.bucket.id}"
bucket = aws_s3_bucket.bucket.id
name = "%s"
filter {
Expand All @@ -720,7 +721,7 @@ func testAccAWSS3BucketMetricsConfigWithFilterSingleTag(bucketName, metricName,
%s
resource "aws_s3_bucket_metric" "test" {
bucket = "${aws_s3_bucket.bucket.id}"
bucket = aws_s3_bucket.bucket.id
name = "%s"
filter {
Expand All @@ -737,7 +738,7 @@ func testAccAWSS3BucketMetricsConfigWithoutFilter(bucketName, metricName string)
%s
resource "aws_s3_bucket_metric" "test" {
bucket = "${aws_s3_bucket.bucket.id}"
bucket = aws_s3_bucket.bucket.id
name = "%s"
}
`, testAccAWSS3BucketMetricsConfigBucket(bucketName), metricName)
Expand Down
Loading

0 comments on commit 1e77ea9

Please sign in to comment.