From 058627711da78ffe5436a9c81fd7b73d3c3524af Mon Sep 17 00:00:00 2001 From: Max Lobur Date: Fri, 10 Nov 2023 22:44:09 +0200 Subject: [PATCH] Support AWS Provider V5 (#126) * Support AWS Provider V5 * Support AWS Provider V5 * remove deprecated API https://github.com/hashicorp/terraform-provider-aws/pull/17465 --- .github/renovate.json | 7 +-- .github/workflows/release-branch.yml | 1 + .github/workflows/release-published.yml | 2 +- README.md | 71 ++++++------------------- docs/terraform.md | 6 +-- examples/bitbucket/versions.tf | 10 ++++ examples/complete/versions.tf | 4 +- examples/vpc/main.tf | 18 ++++--- examples/vpc/versions.tf | 10 ++++ main.tf | 38 ++++++------- outputs.tf | 16 +++--- versions.tf | 4 +- 12 files changed, 82 insertions(+), 105 deletions(-) create mode 100644 examples/bitbucket/versions.tf create mode 100644 examples/vpc/versions.tf diff --git a/.github/renovate.json b/.github/renovate.json index b61ed24..909df09 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -1,13 +1,14 @@ { "extends": [ "config:base", - ":preserveSemverRanges" + ":preserveSemverRanges", + ":rebaseStalePrs" ], - "baseBranches": ["main", "master", "/^release\\/v\\d{1,2}$/"], + "baseBranches": ["main"], "labels": ["auto-update"], "dependencyDashboardAutoclose": true, "enabledManagers": ["terraform"], "terraform": { - "ignorePaths": ["**/context.tf", "examples/**"] + "ignorePaths": ["**/context.tf"] } } diff --git a/.github/workflows/release-branch.yml b/.github/workflows/release-branch.yml index 3f8fe62..b30901e 100644 --- a/.github/workflows/release-branch.yml +++ b/.github/workflows/release-branch.yml @@ -10,6 +10,7 @@ on: - 'docs/**' - 'examples/**' - 'test/**' + - 'README.*' permissions: contents: write diff --git a/.github/workflows/release-published.yml b/.github/workflows/release-published.yml index f86352b..b31232b 100644 --- a/.github/workflows/release-published.yml +++ b/.github/workflows/release-published.yml @@ -11,4 +11,4 @@ permissions: jobs: terraform-module: - uses: cloudposse/github-actions-workflows-terraform-module/.github/workflows/release.yml@main + uses: cloudposse/github-actions-workflows-terraform-module/.github/workflows/release-published.yml@main diff --git a/README.md b/README.md index 59ee59d..4a628fa 100644 --- a/README.md +++ b/README.md @@ -33,12 +33,6 @@ Terraform module to create AWS CodeBuild project for AWS CodePipeline. --- This project is part of our comprehensive ["SweetOps"](https://cpco.io/sweetops) approach towards DevOps. -[][share_email] -[][share_googleplus] -[][share_facebook] -[][share_reddit] -[][share_linkedin] -[][share_twitter] [![Terraform Open Source Modules](https://docs.cloudposse.com/images/terraform-open-source-modules.svg)][terraform_modules] @@ -88,10 +82,6 @@ We highly recommend that in your code you pin the version to the exact version y using so that your infrastructure remains stable, and update versions in a systematic way so that they do not catch you by surprise. -Also, because of a bug in the Terraform registry ([hashicorp/terraform#21417](https://github.com/hashicorp/terraform/issues/21417)), -the registry shows many of our inputs as required when in fact they are optional. -The table below correctly indicates which inputs are required. - Include this module in your existing terraform code: @@ -163,15 +153,15 @@ Available targets: | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.13.0 | -| [aws](#requirement\_aws) | >= 2.0 | +| [terraform](#requirement\_terraform) | >= 1.3 | +| [aws](#requirement\_aws) | >= 5.0 | | [random](#requirement\_random) | >= 2.1 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 2.0 | +| [aws](#provider\_aws) | >= 5.0 | | [random](#provider\_random) | >= 2.1 | ## Modules @@ -295,8 +285,6 @@ Available targets: Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/terraform-aws-codebuild)! (it helps us **a lot**) -Are you using this project or any of our other projects? Consider [leaving a testimonial][testimonial]. =) - ## Related Projects @@ -339,10 +327,6 @@ We deliver 10x the value for a fraction of the cost of a full-time engineer. Our Join our [Open Source Community][slack] on Slack. It's **FREE** for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally *sweet* infrastructure. -## Discourse Forums - -Participate in our [Discourse Forums][discourse]. Here you'll find answers to commonly asked questions. Most questions will be related to the enormous number of projects we support on our GitHub. Come here to collaborate on answers, find solutions, and get ideas about the products and services we value. It only takes a minute to get started! Just sign in with SSO using your GitHub account. - ## Newsletter Sign up for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover. @@ -353,7 +337,18 @@ Sign up for [our newsletter][newsletter] that covers everything on our technolog [![zoom](https://img.cloudposse.com/fit-in/200x200/https://cloudposse.com/wp-content/uploads/2019/08/Powered-by-Zoom.png")][office_hours] -## Contributing +## ✨ Contributing + + + +This project is under active development, and we encourage contributions from our community. +Many thanks to our outstanding contributors: + + + + + + ### Bug Reports & Feature Requests @@ -427,33 +422,7 @@ We're a [DevOps Professional Services][hire] company based in Los Angeles, CA. W We offer [paid support][commercial_support] on all of our projects. -Check out [our other projects][github], [follow us on twitter][twitter], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation. - - - -### Contributors - - -| [![Erik Osterman][osterman_avatar]][osterman_homepage]
[Erik Osterman][osterman_homepage] | [![Igor Rodionov][goruha_avatar]][goruha_homepage]
[Igor Rodionov][goruha_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]
[Andriy Knysh][aknysh_homepage] | [![Jamie Nelson][Jamie-BitFlight_avatar]][Jamie-BitFlight_homepage]
[Jamie Nelson][Jamie-BitFlight_homepage] | [![Sarkis Varozian][sarkis_avatar]][sarkis_homepage]
[Sarkis Varozian][sarkis_homepage] | [![Bircan Bilici][brcnblc_avatar]][brcnblc_homepage]
[Bircan Bilici][brcnblc_homepage] | [![RB][nitrocode_avatar]][nitrocode_homepage]
[RB][nitrocode_homepage] | -|---|---|---|---|---|---|---| - - - [osterman_homepage]: https://github.com/osterman - [osterman_avatar]: https://img.cloudposse.com/150x150/https://github.com/osterman.png - [goruha_homepage]: https://github.com/goruha - [goruha_avatar]: https://img.cloudposse.com/150x150/https://github.com/goruha.png - [aknysh_homepage]: https://github.com/aknysh - [aknysh_avatar]: https://img.cloudposse.com/150x150/https://github.com/aknysh.png - [Jamie-BitFlight_homepage]: https://github.com/Jamie-BitFlight - [Jamie-BitFlight_avatar]: https://img.cloudposse.com/150x150/https://github.com/Jamie-BitFlight.png - [sarkis_homepage]: https://github.com/sarkis - [sarkis_avatar]: https://img.cloudposse.com/150x150/https://github.com/sarkis.png - [brcnblc_homepage]: https://github.com/brcnblc - [brcnblc_avatar]: https://img.cloudposse.com/150x150/https://github.com/brcnblc.png - [nitrocode_homepage]: https://github.com/nitrocode - [nitrocode_avatar]: https://img.cloudposse.com/150x150/https://github.com/nitrocode.png - -[![README Footer][readme_footer_img]][readme_footer_link] +Check out [our other projects][github], [follow us on twitter][twitter], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation.[![README Footer][readme_footer_img]][readme_footer_link] [![Beacon][beacon]][website] [logo]: https://cloudposse.com/logo-300x69.svg @@ -463,12 +432,10 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply [jobs]: https://cpco.io/jobs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-codebuild&utm_content=jobs [hire]: https://cpco.io/hire?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-codebuild&utm_content=hire [slack]: https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-codebuild&utm_content=slack - [linkedin]: https://cpco.io/linkedin?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-codebuild&utm_content=linkedin [twitter]: https://cpco.io/twitter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-codebuild&utm_content=twitter [testimonial]: https://cpco.io/leave-testimonial?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-codebuild&utm_content=testimonial [office_hours]: https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-codebuild&utm_content=office_hours [newsletter]: https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-codebuild&utm_content=newsletter - [discourse]: https://ask.sweetops.com/?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-codebuild&utm_content=discourse [email]: https://cpco.io/email?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-codebuild&utm_content=email [commercial_support]: https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-codebuild&utm_content=commercial_support [we_love_open_source]: https://cpco.io/we-love-open-source?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-codebuild&utm_content=we_love_open_source @@ -479,11 +446,5 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply [readme_footer_link]: https://cloudposse.com/readme/footer/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-codebuild&utm_content=readme_footer_link [readme_commercial_support_img]: https://cloudposse.com/readme/commercial-support/img [readme_commercial_support_link]: https://cloudposse.com/readme/commercial-support/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-codebuild&utm_content=readme_commercial_support_link - [share_twitter]: https://twitter.com/intent/tweet/?text=terraform-aws-codebuild&url=https://github.com/cloudposse/terraform-aws-codebuild - [share_linkedin]: https://www.linkedin.com/shareArticle?mini=true&title=terraform-aws-codebuild&url=https://github.com/cloudposse/terraform-aws-codebuild - [share_reddit]: https://reddit.com/submit/?url=https://github.com/cloudposse/terraform-aws-codebuild - [share_facebook]: https://facebook.com/sharer/sharer.php?u=https://github.com/cloudposse/terraform-aws-codebuild - [share_googleplus]: https://plus.google.com/share?url=https://github.com/cloudposse/terraform-aws-codebuild - [share_email]: mailto:?subject=terraform-aws-codebuild&body=https://github.com/cloudposse/terraform-aws-codebuild [beacon]: https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse/terraform-aws-codebuild?pixel&cs=github&cm=readme&an=terraform-aws-codebuild diff --git a/docs/terraform.md b/docs/terraform.md index 6360ee3..e867b8a 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -3,15 +3,15 @@ | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.13.0 | -| [aws](#requirement\_aws) | >= 2.0 | +| [terraform](#requirement\_terraform) | >= 1.3 | +| [aws](#requirement\_aws) | >= 5.0 | | [random](#requirement\_random) | >= 2.1 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 2.0 | +| [aws](#provider\_aws) | >= 5.0 | | [random](#provider\_random) | >= 2.1 | ## Modules diff --git a/examples/bitbucket/versions.tf b/examples/bitbucket/versions.tf new file mode 100644 index 0000000..29ec41d --- /dev/null +++ b/examples/bitbucket/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 1.3" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.0" + } + } +} diff --git a/examples/complete/versions.tf b/examples/complete/versions.tf index 8715d8c..ca7739d 100644 --- a/examples/complete/versions.tf +++ b/examples/complete/versions.tf @@ -1,10 +1,10 @@ terraform { - required_version = ">= 0.13.0" + required_version = ">= 1.3" required_providers { aws = { source = "hashicorp/aws" - version = ">= 2.0" + version = ">= 5.0" } random = { source = "hashicorp/random" diff --git a/examples/vpc/main.tf b/examples/vpc/main.tf index 4bd8467..f64b0f4 100644 --- a/examples/vpc/main.tf +++ b/examples/vpc/main.tf @@ -3,21 +3,23 @@ provider "aws" { } module "vpc" { - source = "cloudposse/vpc/aws" - version = "0.21.1" - cidr_block = var.vpc_cidr_block + source = "cloudposse/vpc/aws" + version = "2.1.1" + + ipv4_primary_cidr_block = var.vpc_cidr_block context = module.this.context } module "subnets" { - source = "cloudposse/dynamic-subnets/aws" - version = "0.38.0" + source = "cloudposse/dynamic-subnets/aws" + version = "2.4.1" + availability_zones = var.availability_zones vpc_id = module.vpc.vpc_id - igw_id = module.vpc.igw_id - cidr_block = module.vpc.vpc_cidr_block - nat_gateway_enabled = true + igw_id = [module.vpc.igw_id] + ipv4_cidr_block = [module.vpc.vpc_cidr_block] + nat_gateway_enabled = false nat_instance_enabled = false context = module.this.context diff --git a/examples/vpc/versions.tf b/examples/vpc/versions.tf new file mode 100644 index 0000000..29ec41d --- /dev/null +++ b/examples/vpc/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 1.3" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.0" + } + } +} diff --git a/main.tf b/main.tf index edf6cf9..8630905 100644 --- a/main.tf +++ b/main.tf @@ -59,7 +59,7 @@ resource "random_string" "bucket_prefix" { } locals { - cache_bucket_name = "${module.this.id}${var.cache_bucket_suffix_enabled ? "-${join("", random_string.bucket_prefix.*.result)}" : ""}" + cache_bucket_name = "${module.this.id}${var.cache_bucket_suffix_enabled ? "-${join("", random_string.bucket_prefix[*].result)}" : ""}" ## Clean up the bucket name to use only hyphens, and trim its length to 63 characters. ## As per https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html @@ -71,7 +71,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("", aws_s3_bucket.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 @@ -134,7 +134,7 @@ resource "aws_iam_policy" "default_cache_bucket" { name = "${module.this.id}-cache-bucket" path = var.iam_policy_path - policy = join("", data.aws_iam_policy_document.permissions_cache_bucket.*.json) + policy = join("", data.aws_iam_policy_document.permissions_cache_bucket[*].json) tags = module.this.tags } @@ -187,8 +187,8 @@ data "aws_iam_policy_document" "permissions" { effect = "Allow" resources = [ - join("", data.aws_s3_bucket.secondary_artifact.*.arn), - "${join("", data.aws_s3_bucket.secondary_artifact.*.arn)}/*", + join("", data.aws_s3_bucket.secondary_artifact[*].arn), + "${join("", data.aws_s3_bucket.secondary_artifact[*].arn)}/*", ] } } @@ -248,8 +248,8 @@ data "aws_iam_policy_document" "vpc_permissions" { data "aws_iam_policy_document" "combined_permissions" { override_policy_documents = compact([ - join("", data.aws_iam_policy_document.permissions.*.json), - var.vpc_config != {} ? join("", data.aws_iam_policy_document.vpc_permissions.*.json) : null + join("", data.aws_iam_policy_document.permissions[*].json), + var.vpc_config != {} ? join("", data.aws_iam_policy_document.vpc_permissions[*].json) : null ]) } @@ -265,22 +265,22 @@ 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("", aws_s3_bucket.cache_bucket[*].arn), + "${join("", aws_s3_bucket.cache_bucket[*].arn)}/*", ] } } resource "aws_iam_role_policy_attachment" "default" { count = module.this.enabled ? 1 : 0 - policy_arn = join("", aws_iam_policy.default.*.arn) - role = join("", aws_iam_role.default.*.id) + policy_arn = join("", aws_iam_policy.default[*].arn) + role = join("", aws_iam_role.default[*].id) } resource "aws_iam_role_policy_attachment" "default_cache_bucket" { count = module.this.enabled && local.s3_cache_enabled ? 1 : 0 - policy_arn = join("", aws_iam_policy.default_cache_bucket.*.arn) - role = join("", aws_iam_role.default.*.id) + policy_arn = join("", aws_iam_policy.default_cache_bucket[*].arn) + role = join("", aws_iam_role.default[*].id) } resource "aws_codebuild_source_credential" "authorization" { @@ -296,7 +296,7 @@ resource "aws_codebuild_project" "default" { name = module.this.id description = var.description concurrent_build_limit = var.concurrent_build_limit - service_role = join("", aws_iam_role.default.*.arn) + service_role = join("", aws_iam_role.default[*].arn) badge_enabled = var.badge_enabled build_timeout = var.build_timeout source_version = var.source_version != "" ? var.source_version : null @@ -325,7 +325,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 @@ -411,14 +411,6 @@ resource "aws_codebuild_project" "default" { report_build_status = var.report_build_status git_clone_depth = var.git_clone_depth != null ? var.git_clone_depth : null - dynamic "auth" { - for_each = var.private_repository ? [""] : [] - content { - type = "OAUTH" - resource = join("", aws_codebuild_source_credential.authorization.*.id) - } - } - dynamic "git_submodules_config" { for_each = var.fetch_git_submodules ? [""] : [] content { diff --git a/outputs.tf b/outputs.tf index 72ad81f..a991912 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,39 +1,39 @@ output "project_name" { description = "Project name" - value = join("", aws_codebuild_project.default.*.name) + value = join("", aws_codebuild_project.default[*].name) } output "project_id" { description = "Project ID" - value = join("", aws_codebuild_project.default.*.id) + value = join("", aws_codebuild_project.default[*].id) } output "role_id" { description = "IAM Role ID" - value = join("", aws_iam_role.default.*.id) + value = join("", aws_iam_role.default[*].id) } output "role_arn" { description = "IAM Role ARN" - value = join("", aws_iam_role.default.*.arn) + value = join("", aws_iam_role.default[*].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("", aws_s3_bucket.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("", aws_s3_bucket.cache_bucket[*].arn) : "UNSET" } output "badge_url" { description = "The URL of the build badge when badge_enabled is enabled" - value = join("", aws_codebuild_project.default.*.badge_url) + value = join("", aws_codebuild_project.default[*].badge_url) } output "project_arn" { description = "Project ARN" - value = join("", aws_codebuild_project.default.*.arn) + value = join("", aws_codebuild_project.default[*].arn) } diff --git a/versions.tf b/versions.tf index 8715d8c..ca7739d 100644 --- a/versions.tf +++ b/versions.tf @@ -1,10 +1,10 @@ terraform { - required_version = ">= 0.13.0" + required_version = ">= 1.3" required_providers { aws = { source = "hashicorp/aws" - version = ">= 2.0" + version = ">= 5.0" } random = { source = "hashicorp/random"