Skip to content

Commit

Permalink
Fix build (#1069)
Browse files Browse the repository at this point in the history
* Make terraform-aws-s3-example compatible with AWS provider v4

* Fix output

* Do not run TestParallelism in parallel
  • Loading branch information
yorinasub17 authored Feb 25, 2022
1 parent d051c30 commit 876f127
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 41 deletions.
91 changes: 54 additions & 37 deletions examples/terraform-aws-s3-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,60 @@ terraform {
# See test/terraform_aws_s3_example_test.go for how to write automated tests for this code.
# ---------------------------------------------------------------------------------------------------------------------

# Deploy and configure test S3 bucket with versioning and access log
resource "aws_s3_bucket" "test_bucket" {
bucket = "${local.aws_account_id}-${var.tag_bucket_name}"

tags = {
Name = var.tag_bucket_name
Environment = var.tag_bucket_environment
}
}

resource "aws_s3_bucket_logging" "test_bucket" {
bucket = aws_s3_bucket.test_bucket.id
target_bucket = aws_s3_bucket.test_bucket_logs.id
target_prefix = "TFStateLogs/"
}

resource "aws_s3_bucket_versioning" "test_bucket" {
bucket = aws_s3_bucket.test_bucket.id
versioning_configuration {
status = "Enabled"
}
}

resource "aws_s3_bucket_acl" "test_bucket" {
bucket = aws_s3_bucket.test_bucket.id
acl = "private"
}


# Deploy S3 bucket to collect access logs for test bucket
resource "aws_s3_bucket" "test_bucket_logs" {
bucket = "${local.aws_account_id}-${var.tag_bucket_name}-logs"

tags = {
Name = "${local.aws_account_id}-${var.tag_bucket_name}-logs"
Environment = var.tag_bucket_environment
}

force_destroy = true
}

resource "aws_s3_bucket_acl" "test_bucket_logs" {
bucket = aws_s3_bucket.test_bucket_logs.id
acl = "log-delivery-write"
}

# Configure bucket access policies

resource "aws_s3_bucket_policy" "bucket_access_policy" {
count = var.with_policy ? 1 : 0
bucket = aws_s3_bucket.test_bucket.id
policy = data.aws_iam_policy_document.s3_bucket_policy.json
}

data "aws_iam_policy_document" "s3_bucket_policy" {
statement {
effect = "Allow"
Expand Down Expand Up @@ -56,43 +110,6 @@ data "aws_iam_policy_document" "s3_bucket_policy" {
}
}

resource "aws_s3_bucket" "test_bucket_logs" {
bucket = "${local.aws_account_id}-${var.tag_bucket_name}-logs"
acl = "log-delivery-write"

tags = {
Name = "${local.aws_account_id}-${var.tag_bucket_name}-logs"
Environment = var.tag_bucket_environment
}

force_destroy = true
}

resource "aws_s3_bucket" "test_bucket" {
bucket = "${local.aws_account_id}-${var.tag_bucket_name}"
acl = "private"

versioning {
enabled = true
}

logging {
target_bucket = aws_s3_bucket.test_bucket_logs.id
target_prefix = "TFStateLogs/"
}

tags = {
Name = var.tag_bucket_name
Environment = var.tag_bucket_environment
}
}

resource "aws_s3_bucket_policy" "bucket_access_policy" {
count = var.with_policy ? 1 : 0
bucket = aws_s3_bucket.test_bucket.id
policy = data.aws_iam_policy_document.s3_bucket_policy.json
}

# ---------------------------------------------------------------------------------------------------------------------
# LOCALS
# Used to represent any data that requires complex expressions/interpolations
Expand Down
6 changes: 3 additions & 3 deletions examples/terraform-aws-s3-example/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ output "bucket_arn" {
}

output "logging_target_bucket" {
value = tolist(aws_s3_bucket.test_bucket.logging)[0].target_bucket
value = aws_s3_bucket_logging.test_bucket.target_bucket
}

output "logging_target_prefix" {
value = tolist(aws_s3_bucket.test_bucket.logging)[0].target_prefix
}
value = aws_s3_bucket_logging.test_bucket.target_prefix
}
3 changes: 2 additions & 1 deletion modules/terraform/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ func TestIdempotentWithChanges(t *testing.T) {
}

func TestParallelism(t *testing.T) {
t.Parallel()
// This test depends on precise timing of the concurrent parallel calls in terraform, so we need to run this test
// serially by itself so that other concurrent test runs won't influence the timing.

testFolder, err := files.CopyTerraformFolderToTemp("../../test/fixtures/terraform-parallelism", t.Name())
require.NoError(t, err)
Expand Down

0 comments on commit 876f127

Please sign in to comment.