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

Aws v4 refactor #113

Closed
Closed
Show file tree
Hide file tree
Changes from 6 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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,21 @@ Available targets:
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.21.0 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.1 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.21.0 |
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.1 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_cache_bucket"></a> [cache\_bucket](#module\_cache\_bucket) | cloudposse/s3-bucket/aws | 2.0.3 |
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |

## Resources
Expand All @@ -191,7 +192,6 @@ Available targets:
| [aws_iam_role.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
| [aws_iam_role_policy_attachment.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [aws_iam_role_policy_attachment.default_cache_bucket](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [aws_s3_bucket.cache_bucket](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
| [random_string.bucket_prefix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
| [aws_caller_identity.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_iam_policy_document.combined_permissions](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
Expand Down
6 changes: 3 additions & 3 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.21.0 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.1 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.21.0 |
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.1 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_cache_bucket"></a> [cache\_bucket](#module\_cache\_bucket) | cloudposse/s3-bucket/aws | 2.0.3 |
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |

## Resources
Expand All @@ -31,7 +32,6 @@
| [aws_iam_role.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
| [aws_iam_role_policy_attachment.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [aws_iam_role_policy_attachment.default_cache_bucket](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
| [aws_s3_bucket.cache_bucket](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
| [random_string.bucket_prefix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
| [aws_caller_identity.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_iam_policy_document.combined_permissions](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
Expand Down
4 changes: 2 additions & 2 deletions examples/bitbucket/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,13 @@ variable "logs_config" {
}

variable "extra_permissions" {
type = list
type = list(any)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type = list(any)
type = list(string)

default = []
description = "List of action strings which will be added to IAM service account permissions."
}

# Log tracker
variable "log_tracker" {
type = map
type = map(any)
default = {}
}
2 changes: 1 addition & 1 deletion examples/complete/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 2.0"
version = ">= 4.22.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was changed added after 4.9.0 that requires a later version?

Suggested change
version = ">= 4.22.0"
version = ">= 4.9.0"

}
random = {
source = "hashicorp/random"
Expand Down
79 changes: 35 additions & 44 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,44 @@ data "aws_caller_identity" "default" {}

data "aws_region" "default" {}

resource "aws_s3_bucket" "cache_bucket" {
module "cache_bucket" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually when we create a breaking change like this, we release a "minor" release but we also include with it some kind of "migration" document which we create by first applying the current release, then running through terraform state moves and other API changes, then we can apply the new version (this version) and make sure it returns "no changes".

Those steps are documented inside of docs/ and added to the README.yaml so other people will know how to safely migrate from version 0.x to version 0.y.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the tests below just to make sure you were on the correct path with the current proposed changes but I think a migration doc is the right way to go.

cc: @Nuru

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a migration doc @nitrocode
Can you please review?

#bridgecrew:skip=BC_AWS_S3_13:Skipping `Enable S3 Bucket Logging` check until bridgecrew will support dynamic blocks (https://github.com/bridgecrewio/checkov/issues/776).
#bridgecrew:skip=BC_AWS_S3_14:Skipping `Ensure all data stored in the S3 bucket is securely encrypted at rest` check until bridgecrew will support dynamic blocks (https://github.com/bridgecrewio/checkov/issues/776).
#bridgecrew:skip=CKV_AWS_52:Skipping `Ensure S3 bucket has MFA delete enabled` due to issue in terraform (https://github.com/hashicorp/terraform-provider-aws/issues/629).
count = module.this.enabled && local.create_s3_cache_bucket ? 1 : 0
bucket = local.cache_bucket_name_normalised
acl = "private"
force_destroy = true
tags = module.this.tags

versioning {
enabled = var.versioning_enabled
source = "cloudposse/s3-bucket/aws"
version = "2.0.3"

count = module.this.enabled && local.create_s3_cache_bucket ? 1 : 0
bucket_name = local.cache_bucket_name_normalised

acl = true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
acl = true
acl = "private"

force_destroy = true
tags = module.this.tags
versioning_enabled = var.versioning_enabled
logging = {
bucket_name = var.access_log_bucket_name
prefix = "logs/${module.this.id}/"
}

dynamic "logging" {
for_each = var.access_log_bucket_name != "" ? [1] : []
content {
target_bucket = var.access_log_bucket_name
target_prefix = "logs/${module.this.id}/"
}
}

lifecycle_rule {
id = "codebuildcache"
enabled = true

prefix = "/"
tags = module.this.tags

expiration {
days = var.cache_expiration_days
}
}

dynamic "server_side_encryption_configuration" {
for_each = var.encryption_enabled ? ["true"] : []

content {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
lifecycle_configuration_rules = [
# Be sure to cover https://github.com/cloudposse/terraform-aws-s3-bucket/issues/137
{
enabled = true
id = "codebuildcache"
abort_incomplete_multipart_upload_days = 1
prefix = "/"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix is not a recognized element of lifecycle_configuration_rules. If needed, add to filter_and instead, but since prefix is / for the rule, no filter is needed.

Suggested change
prefix = "/"

tags = module.this.tags
filter_and = {}
noncurrent_version_expiration = {}
noncurrent_version_transition = []
transition = [{}]
expiration = {
days = var.cache_expiration_days
expired_object_delete_marker = null
}
}
}
]
bucket_key_enabled = true
}

resource "random_string" "bucket_prefix" {
count = module.this.enabled ? 1 : 0
length = 12
Expand All @@ -71,7 +62,7 @@ locals {

s3_cache_enabled = var.cache_type == "S3"
create_s3_cache_bucket = local.s3_cache_enabled && var.s3_cache_bucket_name == null
s3_bucket_name = local.create_s3_cache_bucket ? join("", aws_s3_bucket.cache_bucket.*.bucket) : var.s3_cache_bucket_name
s3_bucket_name = local.create_s3_cache_bucket ? join("", module.cache_bucket.*.bucket) : var.s3_cache_bucket_name

## This is the magic where a map of a list of maps is generated
## and used to conditionally add the cache bucket option to the
Expand Down Expand Up @@ -265,8 +256,8 @@ data "aws_iam_policy_document" "permissions_cache_bucket" {
effect = "Allow"

resources = [
join("", aws_s3_bucket.cache_bucket.*.arn),
"${join("", aws_s3_bucket.cache_bucket.*.arn)}/*",
join("", module.cache_bucket.*.bucket_arn),
"${join("", module.cache_bucket.*.bucket_arn)}/*",
]
}
}
Expand Down Expand Up @@ -325,7 +316,7 @@ resource "aws_codebuild_project" "default" {
type = "S3"
location = var.secondary_artifact_location
artifact_identifier = var.secondary_artifact_identifier
encryption_disabled = ! var.secondary_artifact_encryption_enabled
encryption_disabled = !var.secondary_artifact_encryption_enabled
# According to AWS documention, in order to have the artifacts written
# to the root of the bucket, the 'namespace_type' should be 'NONE'
# (which is the default), 'name' should be '/', and 'path' should be
Expand Down
4 changes: 2 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ output "role_arn" {

output "cache_bucket_name" {
description = "Cache S3 bucket name"
value = module.this.enabled && local.s3_cache_enabled ? join("", aws_s3_bucket.cache_bucket.*.bucket) : "UNSET"
value = module.this.enabled && local.s3_cache_enabled ? join("", module.cache_bucket.*.bucket) : "UNSET"
}

output "cache_bucket_arn" {
description = "Cache S3 bucket ARN"
value = module.this.enabled && local.s3_cache_enabled ? join("", aws_s3_bucket.cache_bucket.*.arn) : "UNSET"
value = module.this.enabled && local.s3_cache_enabled ? join("", module.cache_bucket.*.bucket_arn) : "UNSET"
}

output "badge_url" {
Expand Down
4 changes: 2 additions & 2 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
terraform {
required_version = ">= 0.13.0"
required_version = ">= 1.0.0"
nitrocode marked this conversation as resolved.
Show resolved Hide resolved

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 2.0"
version = ">= 4.21.0"
nitrocode marked this conversation as resolved.
Show resolved Hide resolved
}
random = {
source = "hashicorp/random"
Expand Down