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
Hide 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:
...
@@ -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:
...
...
ee/spec/lib/ee/gitlab/ci/templates/templates_spec.rb
View file @
ec67ad9e
...
@@ -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
...
...
lib/gitlab/ci/templates/Terraform.gitlab-ci.yml
View file @
ec67ad9e
# 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
spec/lib/gitlab/ci/templates/templates_spec.rb
View file @
ec67ad9e
...
@@ -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
...
...
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