summaryrefslogtreecommitdiff
path: root/doc/user/infrastructure/iac/terraform_template_recipes.md
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 19:00:14 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 19:00:14 +0000
commit05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch)
tree11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /doc/user/infrastructure/iac/terraform_template_recipes.md
parentec73467c23693d0db63a797d10194da9e72a74af (diff)
downloadgitlab-ce-05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2.tar.gz
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'doc/user/infrastructure/iac/terraform_template_recipes.md')
-rw-r--r--doc/user/infrastructure/iac/terraform_template_recipes.md48
1 files changed, 48 insertions, 0 deletions
diff --git a/doc/user/infrastructure/iac/terraform_template_recipes.md b/doc/user/infrastructure/iac/terraform_template_recipes.md
index ab2c8c1c48a..0d1b56ae979 100644
--- a/doc/user/infrastructure/iac/terraform_template_recipes.md
+++ b/doc/user/infrastructure/iac/terraform_template_recipes.md
@@ -181,3 +181,51 @@ deploy:
```
For an example repository, see the [GitLab Terraform template usage project](https://gitlab.com/gitlab-org/configure/examples/terraform-template-usage).
+
+## Deploy Terraform to multiple environments
+
+You can run pipelines in multiple environments, each with a unique Terraform state.
+
+```yaml
+stages:
+ - validate
+ - test
+ - build
+ - deploy
+
+include:
+ - template: Terraform/Base.latest.gitlab-ci.yml
+ - template: Jobs/SAST-IaC.latest.gitlab-ci.yml
+
+variables:
+ # x prevents TF_STATE_NAME from beeing empty for non environment jobs like validate
+ # wait for https://gitlab.com/groups/gitlab-org/-/epics/7437 to use variable defaults
+ TF_STATE_NAME: x${CI_ENVIRONMENT_NAME}
+ TF_CLI_ARGS_plan: "-var-file=vars/${CI_ENVIRONMENT_NAME}.tfvars"
+
+fmt:
+ extends: .terraform:fmt
+validate:
+ extends: .terraform:validate
+
+plan dev:
+ extends: .terraform:build
+ environment:
+ name: dev
+plan prod:
+ extends: .terraform:build
+ environment:
+ name: prod
+
+apply dev:
+ extends: .terraform:deploy
+ environment:
+ name: dev
+
+apply prod:
+ extends: .terraform:deploy
+ environment:
+ name: prod
+```
+
+This configuration is modified from the [base GitLab template](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Terraform/Base.gitlab-ci.yml).