Skip to content

Commit

Permalink
Update dependencies and links (#29)
Browse files Browse the repository at this point in the history
- Updates dependencies
- Updates links to Terramate
- Renames examples from Mineiros to Example
  • Loading branch information
zied-elouaer authored Feb 6, 2024
2 parents 0d0a8fa + c20d1f7 commit 6b7d84f
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 67 deletions.
13 changes: 2 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,12 @@ jobs:
fetch-depth: 0

- name: Set up Terramate
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"
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.2.3
terraform_version: 1.7.1
terraform_wrapper: false

- name: Check Terraform Formatting
Expand Down
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
terraform 1.2.3
terramate 0.2.0
terraform 1.7.1
terramate 0.4.4
53 changes: 24 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# 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:

- 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.

Expand All @@ -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.0`
- [Terramate](https://github.com/mineiros-io/terramate) `~> 0.1.11`
- 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:

Expand Down Expand Up @@ -90,68 +90,63 @@ 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 <your branch name>
```

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-<env>-<hash>-lz.a.run.app"
```

You can check the outputs with:

```
```sh
terramate run -- terraform output
```

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
```

Expand Down
2 changes: 1 addition & 1 deletion modules/cloud-run/cloud_run.tm.hcl
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion modules/service-account/service_account.tm.hcl
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion stacks/backend.tm.hcl
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions stacks/config.tm.hcl
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions stacks/prod/cloud-runs/app1/_terramate_generated_cloud_run.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

provider "google" {
project = "mineiros-terramate-prod"
project = "example-prod"
region = "europe-north1"
}
terraform {
Expand Down
4 changes: 2 additions & 2 deletions stacks/prod/cloud-runs/app2/_terramate_generated_cloud_run.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

provider "google" {
project = "mineiros-terramate-prod"
project = "example-prod"
region = "europe-north1"
}
terraform {
Expand Down
2 changes: 1 addition & 1 deletion stacks/prod/cloud-runs/import_cloud_run.tm.hcl
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

provider "google" {
project = "mineiros-terramate-prod"
project = "example-prod"
region = "europe-north1"
}
terraform {
Expand Down
2 changes: 1 addition & 1 deletion stacks/prod/service-accounts/import_service_account.tm.hcl
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion stacks/providers.tm.hcl
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

provider "google" {
project = "mineiros-terramate-staging"
project = "example-staging"
region = "europe-north1"
}
terraform {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

provider "google" {
project = "mineiros-terramate-staging"
project = "example-staging"
region = "europe-north1"
}
terraform {
Expand Down
2 changes: 1 addition & 1 deletion stacks/staging/cloud-runs/import_cloud_run.tm.hcl
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

provider "google" {
project = "mineiros-terramate-staging"
project = "example-staging"
region = "europe-north1"
}
terraform {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion terramate.tm.hcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terramate {
required_version = "~> 0.2.0"
required_version = "~> 0.4.0"

config {
run {
Expand Down

0 comments on commit 6b7d84f

Please sign in to comment.