Skip to content

Commit

Permalink
fix: Correct S3 bucket access permission to try user provided S3 buck…
Browse files Browse the repository at this point in the history
…et ARNs first before falling back to default (#8)

Co-authored-by: Bryant Biggs <bryantbiggs@gmail.com>
  • Loading branch information
JannatBawa and bryantbiggs committed Jun 10, 2023
1 parent d987b8d commit ae366ed
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.79.1
rev: v1.80.0
hooks:
- id: terraform_fmt
- id: terraform_validate
Expand Down
8 changes: 4 additions & 4 deletions examples/private-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ Note that this example may create resources which will incur monetary charges on
| <a name="module_emr_disabled"></a> [emr\_disabled](#module\_emr\_disabled) | ../.. | n/a |
| <a name="module_emr_instance_fleet"></a> [emr\_instance\_fleet](#module\_emr\_instance\_fleet) | ../.. | n/a |
| <a name="module_emr_instance_group"></a> [emr\_instance\_group](#module\_emr\_instance\_group) | ../.. | n/a |
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> v3.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
| <a name="module_vpc_endpoints"></a> [vpc\_endpoints](#module\_vpc\_endpoints) | terraform-aws-modules/vpc/aws//modules/vpc-endpoints | ~> 3.0 |
| <a name="module_vpc_endpoints_sg"></a> [vpc\_endpoints\_sg](#module\_vpc\_endpoints\_sg) | terraform-aws-modules/security-group/aws | ~> 4.0 |
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> 3.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
| <a name="module_vpc_endpoints"></a> [vpc\_endpoints](#module\_vpc\_endpoints) | terraform-aws-modules/vpc/aws//modules/vpc-endpoints | ~> 5.0 |
| <a name="module_vpc_endpoints_sg"></a> [vpc\_endpoints\_sg](#module\_vpc\_endpoints\_sg) | terraform-aws-modules/security-group/aws | ~> 5.0 |

## Resources

Expand Down
13 changes: 6 additions & 7 deletions examples/private-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ module "emr_disabled" {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 3.0"
version = "~> 5.0"

name = local.name
cidr = local.vpc_cidr
Expand All @@ -258,9 +258,8 @@ module "vpc" {
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)]
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 10)]

enable_nat_gateway = true
single_nat_gateway = true
enable_dns_hostnames = true
enable_nat_gateway = true
single_nat_gateway = true

# https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-managed-iam-policies.html#manually-tagged-resources
# Tag if you want EMR to create the security groups for you
Expand All @@ -274,7 +273,7 @@ module "vpc" {

module "vpc_endpoints" {
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
version = "~> 3.0"
version = "~> 5.0"

vpc_id = module.vpc.vpc_id
security_group_ids = [module.vpc_endpoints_sg.security_group_id]
Expand Down Expand Up @@ -304,7 +303,7 @@ module "vpc_endpoints" {

module "vpc_endpoints_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "~> 4.0"
version = "~> 5.0"

name = "${local.name}-vpc-endpoints"
description = "Security group for VPC endpoint access"
Expand All @@ -323,7 +322,7 @@ module "vpc_endpoints_sg" {

module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "~> v3.0"
version = "~> 3.0"

bucket_prefix = "${local.name}-"

Expand Down
4 changes: 2 additions & 2 deletions examples/public-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ Note that this example may create resources which will incur monetary charges on
|------|--------|---------|
| <a name="module_emr_instance_fleet"></a> [emr\_instance\_fleet](#module\_emr\_instance\_fleet) | ../.. | n/a |
| <a name="module_emr_instance_group"></a> [emr\_instance\_group](#module\_emr\_instance\_group) | ../.. | n/a |
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> v3.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> 3.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |

## Resources

Expand Down
7 changes: 3 additions & 4 deletions examples/public-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,15 @@ module "emr_instance_group" {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 3.0"
version = "~> 5.0"

name = local.name
cidr = local.vpc_cidr

azs = local.azs
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)]

enable_nat_gateway = false
enable_dns_hostnames = true
enable_nat_gateway = false

# https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-managed-iam-policies.html#manually-tagged-resources
# Tag if you want EMR to create the security groups for you
Expand All @@ -271,7 +270,7 @@ module "vpc" {

module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "~> v3.0"
version = "~> 3.0"

bucket_prefix = "${local.name}-"

Expand Down
2 changes: 1 addition & 1 deletion examples/serverless-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Note that this example may create resources which will incur monetary charges on
| <a name="module_emr_serverless_disabled"></a> [emr\_serverless\_disabled](#module\_emr\_serverless\_disabled) | ../../modules/serverless | n/a |
| <a name="module_emr_serverless_hive"></a> [emr\_serverless\_hive](#module\_emr\_serverless\_hive) | ../../modules/serverless | n/a |
| <a name="module_emr_serverless_spark"></a> [emr\_serverless\_spark](#module\_emr\_serverless\_spark) | ../../modules/serverless | n/a |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |

## Resources

Expand Down
7 changes: 3 additions & 4 deletions examples/serverless-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ module "emr_serverless_disabled" {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 3.0"
version = "~> 5.0"

name = local.name
cidr = local.vpc_cidr
Expand All @@ -141,9 +141,8 @@ module "vpc" {
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)]
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 10)]

enable_nat_gateway = true
single_nat_gateway = true
enable_dns_hostnames = true
enable_nat_gateway = true
single_nat_gateway = true

tags = local.tags
}
4 changes: 2 additions & 2 deletions examples/studio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ $ terraform apply
| <a name="module_emr_studio_disabled"></a> [emr\_studio\_disabled](#module\_emr\_studio\_disabled) | ../../modules/studio | n/a |
| <a name="module_emr_studio_iam"></a> [emr\_studio\_iam](#module\_emr\_studio\_iam) | ../../modules/studio | n/a |
| <a name="module_emr_studio_sso"></a> [emr\_studio\_sso](#module\_emr\_studio\_sso) | ../../modules/studio | n/a |
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> v3.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> 3.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |

## Resources

Expand Down
4 changes: 2 additions & 2 deletions examples/studio/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ module "emr_studio_disabled" {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 3.0"
version = "~> 5.0"

name = local.name
cidr = local.vpc_cidr
Expand All @@ -172,7 +172,7 @@ module "vpc" {

module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "~> v3.0"
version = "~> 3.0"

bucket_prefix = "${local.name}-"

Expand Down
10 changes: 5 additions & 5 deletions examples/virtual-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ aws emr-containers list-virtual-clusters --region us-west-2 --states ARRESTED \
| <a name="module_complete"></a> [complete](#module\_complete) | ../../modules/virtual-cluster | n/a |
| <a name="module_default"></a> [default](#module\_default) | ../../modules/virtual-cluster | n/a |
| <a name="module_disabled"></a> [disabled](#module\_disabled) | ../../modules/virtual-cluster | n/a |
| <a name="module_eks"></a> [eks](#module\_eks) | terraform-aws-modules/eks/aws | ~> 19.10 |
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> v3.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
| <a name="module_vpc_endpoints"></a> [vpc\_endpoints](#module\_vpc\_endpoints) | terraform-aws-modules/vpc/aws//modules/vpc-endpoints | ~> 3.0 |
| <a name="module_vpc_endpoints_sg"></a> [vpc\_endpoints\_sg](#module\_vpc\_endpoints\_sg) | terraform-aws-modules/security-group/aws | ~> 4.0 |
| <a name="module_eks"></a> [eks](#module\_eks) | terraform-aws-modules/eks/aws | ~> 19.13 |
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> 3.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
| <a name="module_vpc_endpoints"></a> [vpc\_endpoints](#module\_vpc\_endpoints) | terraform-aws-modules/vpc/aws//modules/vpc-endpoints | ~> 5.0 |
| <a name="module_vpc_endpoints_sg"></a> [vpc\_endpoints\_sg](#module\_vpc\_endpoints\_sg) | terraform-aws-modules/security-group/aws | ~> 5.0 |

## Resources

Expand Down
17 changes: 8 additions & 9 deletions examples/virtual-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ resource "null_resource" "start_job_run" {

module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "~> 19.10"
version = "~> 19.13"

cluster_name = local.name
cluster_version = "1.24"
cluster_version = "1.27"
cluster_endpoint_public_access = true

cluster_addons = {
Expand Down Expand Up @@ -221,7 +221,7 @@ module "eks" {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 3.0"
version = "~> 5.0"

name = local.name
cidr = local.vpc_cidr
Expand All @@ -230,9 +230,8 @@ module "vpc" {
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)]
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 10)]

enable_nat_gateway = true
single_nat_gateway = true
enable_dns_hostnames = true
enable_nat_gateway = true
single_nat_gateway = true

public_subnet_tags = {
"kubernetes.io/role/elb" = 1
Expand All @@ -247,7 +246,7 @@ module "vpc" {

module "vpc_endpoints" {
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
version = "~> 3.0"
version = "~> 5.0"

vpc_id = module.vpc.vpc_id
security_group_ids = [module.vpc_endpoints_sg.security_group_id]
Expand Down Expand Up @@ -277,7 +276,7 @@ module "vpc_endpoints" {

module "vpc_endpoints_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "~> 4.0"
version = "~> 5.0"

name = "${local.name}-vpc-endpoints"
description = "Security group for VPC endpoint access"
Expand All @@ -296,7 +295,7 @@ module "vpc_endpoints_sg" {

module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "~> v3.0"
version = "~> 3.0"

bucket_prefix = "${local.name}-"

Expand Down
4 changes: 2 additions & 2 deletions modules/studio/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ data "aws_iam_policy_document" "service" {
"s3:DeleteObject",
]
resources = coalescelist(
["arn:${local.partition}:s3:::*"],
var.service_role_s3_bucket_arns
[var.service_role_s3_bucket_arns],
["arn:${local.partition}:s3:::*"]
)
}

Expand Down

0 comments on commit ae366ed

Please sign in to comment.