Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ec67ad9e
Commit
ec67ad9e
authored
Jun 15, 2021
by
Nicholas Klick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Terraform.gitlab-ci.yml to use Base.latest
parent
5dc89c8d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
58 deletions
+19
-58
doc/user/infrastructure/index.md
doc/user/infrastructure/index.md
+4
-5
ee/spec/lib/ee/gitlab/ci/templates/templates_spec.rb
ee/spec/lib/ee/gitlab/ci/templates/templates_spec.rb
+1
-1
lib/gitlab/ci/templates/Terraform.gitlab-ci.yml
lib/gitlab/ci/templates/Terraform.gitlab-ci.yml
+12
-51
spec/lib/gitlab/ci/templates/templates_spec.rb
spec/lib/gitlab/ci/templates/templates_spec.rb
+2
-1
No files found.
doc/user/infrastructure/index.md
View file @
ec67ad9e
...
...
@@ -20,7 +20,7 @@ for GitLab versions 13.5 and later:
```
yaml
include
:
-
template
:
Terraform.
latest.
gitlab-ci.yml
-
template
:
Terraform.gitlab-ci.yml
variables
:
# If not using GitLab's HTTP backend, remove this line and specify TF_HTTP_* variables
...
...
@@ -30,15 +30,14 @@ variables:
# TF_ROOT: terraform/production
```
This template uses
`.latest.`
, instead of stable, and may include breaking changes.
This template also includes some opinionated decisions, which you can override:
This template includes some opinionated decisions, which you can override:
-
Including the latest
[
GitLab Terraform Image
](
https://gitlab.com/gitlab-org/terraform-images
)
.
-
Using the
[
GitLab managed Terraform State
](
#gitlab-managed-terraform-state
)
as
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
[
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`
.
This video from January 2021 walks you through all the GitLab Terraform integration features:
...
...
ee/spec/lib/ee/gitlab/ci/templates/templates_spec.rb
View file @
ec67ad9e
...
...
@@ -29,7 +29,7 @@ RSpec.describe "CI YML Templates" do
]
where
(
:template_name
)
do
all_templates
-
non_autodevops_templates
all_templates
-
non_autodevops_templates
-
[
"Terraform.gitlab-ci.yml"
]
end
with_them
do
...
...
lib/gitlab/ci/templates/Terraform.gitlab-ci.yml
View file @
ec67ad9e
# Official image for Hashicorp's Terraform. It uses light image which is Alpine
# based as it is much lighter.
#
# 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
include
:
-
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
stages
:
-
init
-
validate
-
build
-
test
-
deploy
init
:
extends
:
.init
validate
:
stage
:
validate
script
:
-
terraform validate
extends
:
.validate
plan
:
stage
:
build
script
:
-
terraform plan -out=$PLAN
-
"
terraform
show
--json
$PLAN
|
convert_report
>
$JSON_PLAN_FILE"
artifacts
:
paths
:
-
$PLAN
reports
:
terraform
:
$JSON_PLAN_FILE
build
:
extends
:
.build
# Separate apply job for manual launching Terraform as it can be destructive
# action.
apply
:
stage
:
deploy
environment
:
name
:
production
script
:
-
terraform apply -input=false $PLAN
deploy
:
extends
:
.deploy
dependencies
:
-
plan
rules
:
-
if
:
$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when
:
manual
-
build
spec/lib/gitlab/ci/templates/templates_spec.rb
View file @
ec67ad9e
...
...
@@ -7,9 +7,10 @@ RSpec.describe 'CI YML Templates' do
let
(
:all_templates
)
{
Gitlab
::
Template
::
GitlabCiYmlTemplate
.
all
.
map
(
&
:full_name
)
}
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
)
}
end
excluded
+
[
"Terraform.gitlab-ci.yml"
]
end
before
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment