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
1a28b177
Commit
1a28b177
authored
Aug 06, 2020
by
Matt Kasa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document Terraform state name without project name
Relates to
https://gitlab.com/gitlab-org/gitlab/-/issues/222380
parent
241b49f5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
14 deletions
+15
-14
doc/user/infrastructure/index.md
doc/user/infrastructure/index.md
+15
-14
No files found.
doc/user/infrastructure/index.md
View file @
1a28b177
...
...
@@ -65,16 +65,16 @@ local machine, this is a simple way to get started:
the
`api`
scope.
1.
On your local machine, run
`terraform init`
, passing in the following options,
replacing
`<YOUR-
PROJECT
-NAME>`
,
`<YOUR-PROJECT-ID>`
,
`<YOUR-USERNAME>`
and
replacing
`<YOUR-
STATE
-NAME>`
,
`<YOUR-PROJECT-ID>`
,
`<YOUR-USERNAME>`
and
`<YOUR-ACCESS-TOKEN>`
with the relevant values. This command initializes your
Terraform state, and stores that state within your GitLab project. This example
uses
`gitlab.com`
:
```
shell
terraform init
\
-backend-config
=
"address=https://gitlab.com/api/v4/projects/<YOUR-PROJECT-ID>/terraform/state/<YOUR-
PROJECT
-NAME>"
\
-backend-config
=
"lock_address=https://gitlab.com/api/v4/projects/<YOUR-PROJECT-ID>/terraform/state/<YOUR-
PROJECT
-NAME>/lock"
\
-backend-config
=
"unlock_address=https://gitlab.com/api/v4/projects/<YOUR-PROJECT-ID>/terraform/state/<YOUR-
PROJECT
-NAME>/lock"
\
-backend-config
=
"address=https://gitlab.com/api/v4/projects/<YOUR-PROJECT-ID>/terraform/state/<YOUR-
STATE
-NAME>"
\
-backend-config
=
"lock_address=https://gitlab.com/api/v4/projects/<YOUR-PROJECT-ID>/terraform/state/<YOUR-
STATE
-NAME>/lock"
\
-backend-config
=
"unlock_address=https://gitlab.com/api/v4/projects/<YOUR-PROJECT-ID>/terraform/state/<YOUR-
STATE
-NAME>/lock"
\
-backend-config
=
"username=<YOUR-USERNAME>"
\
-backend-config
=
"password=<YOUR-ACCESS-TOKEN>"
\
-backend-config
=
"lock_method=POST"
\
...
...
@@ -82,7 +82,7 @@ local machine, this is a simple way to get started:
-backend-config
=
"retry_wait_min=5"
```
Next,
[
configure the backend
](
#configure-the-backend
)
.
You can now run
`terraform plan`
and
`terraform apply`
as you normally would
.
## Get started using GitLab CI
...
...
@@ -121,17 +121,18 @@ and the CI YAML file:
commands must be executed,
`TF_ADDRESS`
is the URL to the state on the GitLab
instance where this pipeline runs, and the final path segment in
`TF_ADDRESS`
is the name of the Terraform state. Projects may have multiple states, and
this name is arbitrary, so in this example we will set it to the name of the
project, and we will ensure that the
`.terraform`
directory is cached between
jobs in the pipeline using a cache key based on the state name:
this name is arbitrary, so in this example we set it to
`example-production`
which corresponds with the directory we're using as our
`TF_ROOT`
, and we
ensure that the
`.terraform`
directory is cached between jobs in the pipeline
using a cache key based on the state name (
`example-production`
):
```
yaml
variables
:
TF_ROOT
:
${CI_PROJECT_DIR}/environments/
cloudflar
e/production
TF_ADDRESS
:
${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/
${CI_PROJECT_NAME}
TF_ROOT
:
${CI_PROJECT_DIR}/environments/
exampl
e/production
TF_ADDRESS
:
${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/
example-production
cache
:
key
:
${CI_PROJECT_NAME}
key
:
example-production
paths
:
-
${TF_ROOT}/.terraform
```
...
...
@@ -275,11 +276,11 @@ can configure this manually as follows:
image
:
registry.gitlab.com/gitlab-org/terraform-images/stable:latest
variables
:
TF_ROOT
:
${CI_PROJECT_DIR}/environments/
cloudflar
e/production
TF_ADDRESS
:
${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/
${CI_PROJECT_NAME}
TF_ROOT
:
${CI_PROJECT_DIR}/environments/
exampl
e/production
TF_ADDRESS
:
${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/
example-production
cache
:
key
:
${CI_PROJECT_NAME}
key
:
example-production
paths
:
-
${TF_ROOT}/.terraform
...
...
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