From 3fb4df453b2e618dd8456043a3d6046bae2c4688 Mon Sep 17 00:00:00 2001 From: Soren Martius Date: Wed, 5 Jul 2023 22:56:49 +0100 Subject: [PATCH 1/3] docs: update links from mineiros-io to terramate-io organization --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d1ee64d..8e1f8f8 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # terramate-example-code-generation -![CI Status](https://github.com/mineiros-io/terramate-example-code-generation/actions/workflows/ci.yml/badge.svg) +![CI Status](https://github.com/terramate-io/terramate-example-code-generation/actions/workflows/ci.yml/badge.svg) [![Join Discord](https://img.shields.io/discord/1088753599951151154?label=Discord&logo=discord&logoColor=white)](https://terramate.io/discord) This project shows an example file/dir structure you can use with -[Terramate](https://github.com/mineiros-io/terramate) to keep your Terraform +[Terramate](https://github.com/terramate-io/terramate) to keep your Terraform code DRY. -Be sure to read through the [Terramate documentation](https://github.com/mineiros-io/terramate) +Be sure to read through the [Terramate documentation](https://github.com/terramate-io/terramate) to understand the features of Terramate used here. The example is organized as two environments, each environment will have: @@ -27,8 +27,8 @@ This is not production-ready code, so use at your own risk. ## Pre-Requisites -- [Terraform](https://www.terraform.io/) `~> 1.0` -- [Terramate](https://github.com/mineiros-io/terramate) `~> 0.1.11` +- [Terraform](https://www.terraform.io/) `~> 1.5` +- [Terramate](https://github.com/terramate-io/terramate) `~> 0.3.0` - Configure your GCP credentials using one of the supported [authentication mechanisms](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#authentication) - Google Cloud Provider account - At least one [GCP project](https://cloud.google.com/storage/docs/projects) From 3c7d29125a3f0d014bfb41f74729adbda047c4d7 Mon Sep 17 00:00:00 2001 From: Soren Martius Date: Wed, 5 Jul 2023 22:57:46 +0100 Subject: [PATCH 2/3] feat: upgrade to terramate to 0.4.0 chore: run terramate generate to update generated files chore: update links in comments ci: update links to terramate refactor: move project namespace to example --- .github/workflows/ci.yml | 8 ++-- .tool-versions | 4 +- README.md | 47 +++++++++---------- modules/cloud-run/cloud_run.tm.hcl | 2 +- .../service-account/service_account.tm.hcl | 2 +- stacks/backend.tm.hcl | 2 +- stacks/config.tm.hcl | 4 +- .../app1/_terramate_generated_cloud_run.tf | 4 +- .../app1/_terramate_generated_providers.tf | 2 +- .../app2/_terramate_generated_cloud_run.tf | 4 +- .../app2/_terramate_generated_providers.tf | 2 +- .../prod/cloud-runs/import_cloud_run.tm.hcl | 2 +- .../_terramate_generated_providers.tf | 2 +- .../import_service_account.tm.hcl | 2 +- stacks/providers.tm.hcl | 2 +- .../app1/_terramate_generated_cloud_run.tf | 4 +- .../app1/_terramate_generated_providers.tf | 2 +- .../app2/_terramate_generated_cloud_run.tf | 4 +- .../app2/_terramate_generated_providers.tf | 2 +- .../cloud-runs/import_cloud_run.tm.hcl | 2 +- .../_terramate_generated_providers.tf | 2 +- .../import_service_account.tm.hcl | 2 +- terramate.tm.hcl | 2 +- 23 files changed, 52 insertions(+), 57 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 409410a..50485ac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,9 +23,9 @@ jobs: uses: giantswarm/install-binary-action@e97402b0aa95939ddba5b36aa77f8abc58a37fd5 with: binary: terramate - version: 0.2.0 - # https://github.com/mineiros-io/terramate/releases/download/v${version}/terramate_${version}_${os}_${arch}.tar.gz - download_url: "https://github.com/mineiros-io/${binary}/releases/download/v${version}/terramate_${version}_linux_x86_64.tar.gz" + version: 0.3.0 + # https://github.com/terramate-io/terramate/releases/download/v${version}/terramate_${version}_${os}_${arch}.tar.gz + download_url: "https://github.com/terramate-io/${binary}/releases/download/v${version}/terramate_${version}_linux_x86_64.tar.gz" tarball_binary_path: "${binary}" - name: Clean Up Terramate Install Artifacts @@ -34,7 +34,7 @@ jobs: - name: Set up Terraform uses: hashicorp/setup-terraform@v1 with: - terraform_version: 1.2.3 + terraform_version: 1.5.1 terraform_wrapper: false - name: Check Terraform Formatting diff --git a/.tool-versions b/.tool-versions index 49bd132..007a3cc 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -terraform 1.2.3 -terramate 0.2.0 +terraform 1.7.1 +terramate 0.4.4 diff --git a/README.md b/README.md index 8e1f8f8..7353cdd 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ to understand the features of Terramate used here. The example is organized as two environments, each environment will have: -- Its own [GCP Project](https://cloud.google.com/storage/docs/projects). +- Its own [Google Cloud Project](https://cloud.google.com/storage/docs/projects). - Service account to be used when deploying Cloud Run services. - Two [Cloud Run](https://cloud.google.com/run) applications. @@ -21,20 +21,20 @@ echo servers that will be reachable through public URLs provided by [Cloud Run](https://cloud.google.com/run). Note: This code is solely for demonstration purposes. -This is not production-ready code, so use at your own risk. +This is not production-ready code, so use it at your own risk. -# How to use this project ? +# How to use this project? ## Pre-Requisites -- [Terraform](https://www.terraform.io/) `~> 1.5` -- [Terramate](https://github.com/terramate-io/terramate) `~> 0.3.0` -- Configure your GCP credentials using one of the supported [authentication mechanisms](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#authentication) +- [Terraform](https://www.terraform.io/) `~> 1.7` +- [Terramate](https://github.com/terramate-io/terramate) `~> 0.4.0` +- Configure your Google Cloud credentials using one of the supported [authentication mechanisms](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#authentication) - Google Cloud Provider account -- At least one [GCP project](https://cloud.google.com/storage/docs/projects) -- GCP project has a proper billing account configured +- At least one [Google Cloud project](https://cloud.google.com/storage/docs/projects) +- The Google Cloud project has a proper billing account configured -# How is the code organized ? +# How is the code organized? This is the overall structure of the project: @@ -90,27 +90,22 @@ Later we are going to use the same mechanism to create and destroy all stacks. ## Deploying Stacks Before we try to deploy any stacks, beware that this will require you -to have [GCP credentials](https://cloud.google.com/docs/authentication/getting-started) -and deploying infrastructure will incur into costs (check the +to have [Google Cloud credentials](https://cloud.google.com/docs/authentication/getting-started) +and deploying infrastructure will incur costs (check the [pre-requisites](#pre-requisites) section for more details). On `stacks/config.tm.hcl` you will find the `terraform_google_provider_project` global which configures the project where infrastructure will be created. -It is important to change that to a [GCP project](https://cloud.google.com/storage/docs/projects) +It is important to change that to a [Google Cloud project](https://cloud.google.com/storage/docs/projects) where you have appropriate permissions. Once the configuration is changed we need to update the generated code by running: - -```sh -terramate generate -``` - -At this point since our project has uncommitted changes Terramate will prevent us +At this point, since our project has uncommitted changes Terramate will prevent us from running any commands. Create a branch (or use the flag `--disable-check-git-uncommitted` to disable the git checks): -``` +```sh git checkout -b ``` @@ -118,32 +113,32 @@ And commit all the changed files. Now we initialize all our stacks: -``` +```sh terramate run -- terraform init ``` Check how their plans look like: -``` +```sh terramate run -- terraform plan ``` And apply them: -``` +```sh terramate run -- terraform apply ``` -For each Cloud Run service deployed there will be an output with the URL to +For each Cloud Run service deployed, there will be an output with the URL to the deployed service, like this: -``` +```sh url = "https://terramate-app1---lz.a.run.app" ``` You can check the outputs with: -``` +```sh terramate run -- terraform output ``` @@ -151,7 +146,7 @@ Open the URL on the browser to check the running service. To avoid unnecessary charges to your account let's destroy all stacks: -``` +```sh terramate run --reverse -- terraform destroy ``` diff --git a/modules/cloud-run/cloud_run.tm.hcl b/modules/cloud-run/cloud_run.tm.hcl index f8f8a47..9d1e0a2 100644 --- a/modules/cloud-run/cloud_run.tm.hcl +++ b/modules/cloud-run/cloud_run.tm.hcl @@ -1,6 +1,6 @@ # This file is part of Terramate Configuration. # Terramate is an orchestrator and code generator for Terraform. -# Please see https://github.com/mineiros-io/terramate for more information. +# Please see https://github.com/terramate-io/terramate for more information. # # To generate/update Terraform code within the stacks # run `terramate generate` from root directory of the repository. diff --git a/modules/service-account/service_account.tm.hcl b/modules/service-account/service_account.tm.hcl index dc8a1df..4f43e3e 100644 --- a/modules/service-account/service_account.tm.hcl +++ b/modules/service-account/service_account.tm.hcl @@ -1,6 +1,6 @@ # This file is part of Terramate Configuration. # Terramate is an orchestrator and code generator for Terraform. -# Please see https://github.com/mineiros-io/terramate for more information. +# Please see https://github.com/terramate-io/terramate for more information. # # To generate/update Terraform code within the stacks # run `terramate generate` from root directory of the repository. diff --git a/stacks/backend.tm.hcl b/stacks/backend.tm.hcl index a5828fe..94c6498 100644 --- a/stacks/backend.tm.hcl +++ b/stacks/backend.tm.hcl @@ -1,6 +1,6 @@ # This file is part of Terramate Configuration. # Terramate is an orchestrator and code generator for Terraform. -# Please see https://github.com/mineiros-io/terramate for more information. +# Please see https://github.com/terramate-io/terramate for more information. # # To generate/update Terraform code within the stacks # run `terramate generate` from root directory of the repository. diff --git a/stacks/config.tm.hcl b/stacks/config.tm.hcl index 82c0a47..5571b83 100644 --- a/stacks/config.tm.hcl +++ b/stacks/config.tm.hcl @@ -1,6 +1,6 @@ # This file is part of Terramate Configuration. # Terramate is an orchestrator and code generator for Terraform. -# Please see https://github.com/mineiros-io/terramate for more information. +# Please see https://github.com/terramate-io/terramate for more information. # # To generate/update Terraform code within the stacks # run `terramate generate` from root directory of the repository. @@ -20,7 +20,7 @@ globals { terraform_google_provider_region = "europe-north1" # this should be adjusted when testing actual deployemnts - terraform_google_provider_project = "mineiros-terramate-${global.environment}" + terraform_google_provider_project = "example-${global.environment}" ### global variables for use when generating backend # all variables defined here can be overwritten in any sub-directory and on the diff --git a/stacks/prod/cloud-runs/app1/_terramate_generated_cloud_run.tf b/stacks/prod/cloud-runs/app1/_terramate_generated_cloud_run.tf index 7195c4a..94400a3 100644 --- a/stacks/prod/cloud-runs/app1/_terramate_generated_cloud_run.tf +++ b/stacks/prod/cloud-runs/app1/_terramate_generated_cloud_run.tf @@ -12,8 +12,8 @@ module "cloud_run_app" { image = "gcr.io/cloudrun/hello:latest" location = "europe-north1" name = "terramate-app1-prod" - project = "mineiros-terramate-prod" - service_account_name = "cloud-run@mineiros-terramate-prod.iam.gserviceaccount.com" + project = "example-prod" + service_account_name = "cloud-run@example-prod.iam.gserviceaccount.com" source = "../../../../modules/cloud-run" } output "url" { diff --git a/stacks/prod/cloud-runs/app1/_terramate_generated_providers.tf b/stacks/prod/cloud-runs/app1/_terramate_generated_providers.tf index d240cdb..084349a 100644 --- a/stacks/prod/cloud-runs/app1/_terramate_generated_providers.tf +++ b/stacks/prod/cloud-runs/app1/_terramate_generated_providers.tf @@ -1,7 +1,7 @@ // TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT provider "google" { - project = "mineiros-terramate-prod" + project = "example-prod" region = "europe-north1" } terraform { diff --git a/stacks/prod/cloud-runs/app2/_terramate_generated_cloud_run.tf b/stacks/prod/cloud-runs/app2/_terramate_generated_cloud_run.tf index 06b44c1..9e1c4f6 100644 --- a/stacks/prod/cloud-runs/app2/_terramate_generated_cloud_run.tf +++ b/stacks/prod/cloud-runs/app2/_terramate_generated_cloud_run.tf @@ -12,8 +12,8 @@ module "cloud_run_app" { image = "gcr.io/kubernetes-e2e-test-images/echoserver:2.2" location = "europe-north1" name = "terramate-app2-prod" - project = "mineiros-terramate-prod" - service_account_name = "cloud-run@mineiros-terramate-prod.iam.gserviceaccount.com" + project = "example-prod" + service_account_name = "cloud-run@example-prod.iam.gserviceaccount.com" source = "../../../../modules/cloud-run" } output "url" { diff --git a/stacks/prod/cloud-runs/app2/_terramate_generated_providers.tf b/stacks/prod/cloud-runs/app2/_terramate_generated_providers.tf index d240cdb..084349a 100644 --- a/stacks/prod/cloud-runs/app2/_terramate_generated_providers.tf +++ b/stacks/prod/cloud-runs/app2/_terramate_generated_providers.tf @@ -1,7 +1,7 @@ // TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT provider "google" { - project = "mineiros-terramate-prod" + project = "example-prod" region = "europe-north1" } terraform { diff --git a/stacks/prod/cloud-runs/import_cloud_run.tm.hcl b/stacks/prod/cloud-runs/import_cloud_run.tm.hcl index 36df676..8db101a 100644 --- a/stacks/prod/cloud-runs/import_cloud_run.tm.hcl +++ b/stacks/prod/cloud-runs/import_cloud_run.tm.hcl @@ -1,6 +1,6 @@ # This file is part of Terramate Configuration. # Terramate is an orchestrator and code generator for Terraform. -# Please see https://github.com/mineiros-io/terramate for more information. +# Please see https://github.com/terramate-io/terramate for more information. # # To generate/update Terraform code within the stacks # run `terramate generate` from root directory of the repository. diff --git a/stacks/prod/service-accounts/cloud-run/_terramate_generated_providers.tf b/stacks/prod/service-accounts/cloud-run/_terramate_generated_providers.tf index d240cdb..084349a 100644 --- a/stacks/prod/service-accounts/cloud-run/_terramate_generated_providers.tf +++ b/stacks/prod/service-accounts/cloud-run/_terramate_generated_providers.tf @@ -1,7 +1,7 @@ // TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT provider "google" { - project = "mineiros-terramate-prod" + project = "example-prod" region = "europe-north1" } terraform { diff --git a/stacks/prod/service-accounts/import_service_account.tm.hcl b/stacks/prod/service-accounts/import_service_account.tm.hcl index fcfba4d..c693bf5 100644 --- a/stacks/prod/service-accounts/import_service_account.tm.hcl +++ b/stacks/prod/service-accounts/import_service_account.tm.hcl @@ -1,6 +1,6 @@ # This file is part of Terramate Configuration. # Terramate is an orchestrator and code generator for Terraform. -# Please see https://github.com/mineiros-io/terramate for more information. +# Please see https://github.com/terramate-io/terramate for more information. # # To generate/update Terraform code within the stacks # run `terramate generate` from root directory of the repository. diff --git a/stacks/providers.tm.hcl b/stacks/providers.tm.hcl index a3c8bf0..f0bc6a7 100644 --- a/stacks/providers.tm.hcl +++ b/stacks/providers.tm.hcl @@ -1,6 +1,6 @@ # This file is part of Terramate Configuration. # Terramate is an orchestrator and code generator for Terraform. -# Please see https://github.com/mineiros-io/terramate for more information. +# Please see https://github.com/terramate-io/terramate for more information. # # To generate/update Terraform code within the stacks # run `terramate generate` from root directory of the repository. diff --git a/stacks/staging/cloud-runs/app1/_terramate_generated_cloud_run.tf b/stacks/staging/cloud-runs/app1/_terramate_generated_cloud_run.tf index ac783f8..3f0f669 100644 --- a/stacks/staging/cloud-runs/app1/_terramate_generated_cloud_run.tf +++ b/stacks/staging/cloud-runs/app1/_terramate_generated_cloud_run.tf @@ -12,8 +12,8 @@ module "cloud_run_app" { image = "gcr.io/cloudrun/hello:latest" location = "europe-north1" name = "terramate-app1-staging" - project = "mineiros-terramate-staging" - service_account_name = "cloud-run@mineiros-terramate-staging.iam.gserviceaccount.com" + project = "example-staging" + service_account_name = "cloud-run@example-staging.iam.gserviceaccount.com" source = "../../../../modules/cloud-run" } output "url" { diff --git a/stacks/staging/cloud-runs/app1/_terramate_generated_providers.tf b/stacks/staging/cloud-runs/app1/_terramate_generated_providers.tf index 225ffb9..ddbe1cc 100644 --- a/stacks/staging/cloud-runs/app1/_terramate_generated_providers.tf +++ b/stacks/staging/cloud-runs/app1/_terramate_generated_providers.tf @@ -1,7 +1,7 @@ // TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT provider "google" { - project = "mineiros-terramate-staging" + project = "example-staging" region = "europe-north1" } terraform { diff --git a/stacks/staging/cloud-runs/app2/_terramate_generated_cloud_run.tf b/stacks/staging/cloud-runs/app2/_terramate_generated_cloud_run.tf index a6c139f..02735cf 100644 --- a/stacks/staging/cloud-runs/app2/_terramate_generated_cloud_run.tf +++ b/stacks/staging/cloud-runs/app2/_terramate_generated_cloud_run.tf @@ -12,8 +12,8 @@ module "cloud_run_app" { image = "gcr.io/kubernetes-e2e-test-images/echoserver:2.2" location = "europe-north1" name = "terramate-app2-staging" - project = "mineiros-terramate-staging" - service_account_name = "cloud-run@mineiros-terramate-staging.iam.gserviceaccount.com" + project = "example-staging" + service_account_name = "cloud-run@example-staging.iam.gserviceaccount.com" source = "../../../../modules/cloud-run" } output "url" { diff --git a/stacks/staging/cloud-runs/app2/_terramate_generated_providers.tf b/stacks/staging/cloud-runs/app2/_terramate_generated_providers.tf index 225ffb9..ddbe1cc 100644 --- a/stacks/staging/cloud-runs/app2/_terramate_generated_providers.tf +++ b/stacks/staging/cloud-runs/app2/_terramate_generated_providers.tf @@ -1,7 +1,7 @@ // TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT provider "google" { - project = "mineiros-terramate-staging" + project = "example-staging" region = "europe-north1" } terraform { diff --git a/stacks/staging/cloud-runs/import_cloud_run.tm.hcl b/stacks/staging/cloud-runs/import_cloud_run.tm.hcl index 36df676..8db101a 100644 --- a/stacks/staging/cloud-runs/import_cloud_run.tm.hcl +++ b/stacks/staging/cloud-runs/import_cloud_run.tm.hcl @@ -1,6 +1,6 @@ # This file is part of Terramate Configuration. # Terramate is an orchestrator and code generator for Terraform. -# Please see https://github.com/mineiros-io/terramate for more information. +# Please see https://github.com/terramate-io/terramate for more information. # # To generate/update Terraform code within the stacks # run `terramate generate` from root directory of the repository. diff --git a/stacks/staging/service-accounts/cloud-run/_terramate_generated_providers.tf b/stacks/staging/service-accounts/cloud-run/_terramate_generated_providers.tf index 225ffb9..ddbe1cc 100644 --- a/stacks/staging/service-accounts/cloud-run/_terramate_generated_providers.tf +++ b/stacks/staging/service-accounts/cloud-run/_terramate_generated_providers.tf @@ -1,7 +1,7 @@ // TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT provider "google" { - project = "mineiros-terramate-staging" + project = "example-staging" region = "europe-north1" } terraform { diff --git a/stacks/staging/service-accounts/import_service_account.tm.hcl b/stacks/staging/service-accounts/import_service_account.tm.hcl index fcfba4d..c693bf5 100644 --- a/stacks/staging/service-accounts/import_service_account.tm.hcl +++ b/stacks/staging/service-accounts/import_service_account.tm.hcl @@ -1,6 +1,6 @@ # This file is part of Terramate Configuration. # Terramate is an orchestrator and code generator for Terraform. -# Please see https://github.com/mineiros-io/terramate for more information. +# Please see https://github.com/terramate-io/terramate for more information. # # To generate/update Terraform code within the stacks # run `terramate generate` from root directory of the repository. diff --git a/terramate.tm.hcl b/terramate.tm.hcl index 66ec049..29d5d64 100644 --- a/terramate.tm.hcl +++ b/terramate.tm.hcl @@ -1,5 +1,5 @@ terramate { - required_version = "~> 0.2.0" + required_version = "~> 0.4.0" config { run { From c20d1f7f1547aa4ef0496f4427812d714b346a1a Mon Sep 17 00:00:00 2001 From: Soren Martius Date: Mon, 5 Feb 2024 14:10:31 +0100 Subject: [PATCH 3/3] ci: update pipeline to install correct required versions --- .github/workflows/ci.yml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 50485ac..35a1a0b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,21 +20,12 @@ jobs: fetch-depth: 0 - name: Set up Terramate - uses: giantswarm/install-binary-action@e97402b0aa95939ddba5b36aa77f8abc58a37fd5 - with: - binary: terramate - version: 0.3.0 - # https://github.com/terramate-io/terramate/releases/download/v${version}/terramate_${version}_${os}_${arch}.tar.gz - download_url: "https://github.com/terramate-io/${binary}/releases/download/v${version}/terramate_${version}_linux_x86_64.tar.gz" - tarball_binary_path: "${binary}" - - - name: Clean Up Terramate Install Artifacts - run: rm -rf terramate + uses: terramate-io/terramate-action@v1 - name: Set up Terraform uses: hashicorp/setup-terraform@v1 with: - terraform_version: 1.5.1 + terraform_version: 1.7.1 terraform_wrapper: false - name: Check Terraform Formatting