Commit 49e51d0c authored by Matija Čupić's avatar Matija Čupić

Merge branch 'nicholasklick-master-patch-72529' into 'master'

Update Terraform.gitlab-ci.yml to use Terraform/Base.latest.gitlab-ci.yml

See merge request gitlab-org/gitlab!63896
parents 6bcc37b3 ec67ad9e
...@@ -20,7 +20,7 @@ for GitLab versions 13.5 and later: ...@@ -20,7 +20,7 @@ for GitLab versions 13.5 and later:
```yaml ```yaml
include: include:
- template: Terraform.latest.gitlab-ci.yml - template: Terraform.gitlab-ci.yml
variables: variables:
# If not using GitLab's HTTP backend, remove this line and specify TF_HTTP_* variables # If not using GitLab's HTTP backend, remove this line and specify TF_HTTP_* variables
...@@ -30,15 +30,14 @@ variables: ...@@ -30,15 +30,14 @@ variables:
# TF_ROOT: terraform/production # TF_ROOT: terraform/production
``` ```
This template uses `.latest.`, instead of stable, and may include breaking changes. This template includes some opinionated decisions, which you can override:
This template also includes some opinionated decisions, which you can override:
- Including the latest [GitLab Terraform Image](https://gitlab.com/gitlab-org/terraform-images). - Including the latest [GitLab Terraform Image](https://gitlab.com/gitlab-org/terraform-images).
- Using the [GitLab managed Terraform State](#gitlab-managed-terraform-state) as - Using the [GitLab managed Terraform State](#gitlab-managed-terraform-state) as
the Terraform state storage backend. the Terraform state storage backend.
- Creating [four pipeline stages](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Terraform.latest.gitlab-ci.yml): - Creating [four pipeline stages](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Terraform.gitlab-ci.yml):
`init`, `validate`, `build`, and `deploy`. These stages `init`, `validate`, `build`, and `deploy`. These stages
[run the Terraform commands](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Terraform/Base.latest.gitlab-ci.yml) [run the Terraform commands](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Terraform/Base.gitlab-ci.yml)
`init`, `validate`, `plan`, `plan-json`, and `apply`. The `apply` command only runs on `master`. `init`, `validate`, `plan`, `plan-json`, and `apply`. The `apply` command only runs on `master`.
This video from January 2021 walks you through all the GitLab Terraform integration features: This video from January 2021 walks you through all the GitLab Terraform integration features:
......
...@@ -29,7 +29,7 @@ RSpec.describe "CI YML Templates" do ...@@ -29,7 +29,7 @@ RSpec.describe "CI YML Templates" do
] ]
where(:template_name) do where(:template_name) do
all_templates - non_autodevops_templates all_templates - non_autodevops_templates - ["Terraform.gitlab-ci.yml"]
end end
with_them do with_them do
......
# Official image for Hashicorp's Terraform. It uses light image which is Alpine include:
# based as it is much lighter. - template: Terraform/Base.latest.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/ci/templates/Terraform/Base.latest.gitlab-ci.yml
#
# Entrypoint is also needed as image by default set `terraform` binary as an
# entrypoint.
image:
name: registry.gitlab.com/gitlab-org/gitlab-build-images:terraform
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
# Default output file for Terraform plan
variables:
PLAN: plan.tfplan
JSON_PLAN_FILE: tfplan.json
cache:
paths:
- .terraform
- .terraform.lock.hcl
before_script:
- alias convert_report="jq -r '([.resource_changes[]?.change.actions?]|flatten)|{\"create\":(map(select(.==\"create\"))|length),\"update\":(map(select(.==\"update\"))|length),\"delete\":(map(select(.==\"delete\"))|length)}'"
- terraform --version
- terraform init
stages: stages:
- init
- validate - validate
- build - build
- test
- deploy - deploy
init:
extends: .init
validate: validate:
stage: validate extends: .validate
script:
- terraform validate
plan: build:
stage: build extends: .build
script:
- terraform plan -out=$PLAN
- "terraform show --json $PLAN | convert_report > $JSON_PLAN_FILE"
artifacts:
paths:
- $PLAN
reports:
terraform: $JSON_PLAN_FILE
# Separate apply job for manual launching Terraform as it can be destructive deploy:
# action. extends: .deploy
apply:
stage: deploy
environment:
name: production
script:
- terraform apply -input=false $PLAN
dependencies: dependencies:
- plan - build
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual
...@@ -7,9 +7,10 @@ RSpec.describe 'CI YML Templates' do ...@@ -7,9 +7,10 @@ RSpec.describe 'CI YML Templates' do
let(:all_templates) { Gitlab::Template::GitlabCiYmlTemplate.all.map(&:full_name) } let(:all_templates) { Gitlab::Template::GitlabCiYmlTemplate.all.map(&:full_name) }
let(:excluded_templates) do let(:excluded_templates) do
all_templates.select do |name| excluded = all_templates.select do |name|
Gitlab::Template::GitlabCiYmlTemplate.excluded_patterns.any? { |pattern| pattern.match?(name) } Gitlab::Template::GitlabCiYmlTemplate.excluded_patterns.any? { |pattern| pattern.match?(name) }
end end
excluded + ["Terraform.gitlab-ci.yml"]
end end
before do before do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment