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
06a27ac8
Commit
06a27ac8
authored
Jul 17, 2020
by
Tiger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add docs for using Terraform state as a remote data source
parent
1b711e20
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
+44
-0
doc/user/infrastructure/index.md
doc/user/infrastructure/index.md
+44
-0
No files found.
doc/user/infrastructure/index.md
View file @
06a27ac8
...
@@ -383,3 +383,47 @@ production_plan:
...
@@ -383,3 +383,47 @@ production_plan:
artifacts
:
artifacts
:
name
:
Production
name
:
Production
```
```
## Using a GitLab managed Terraform state backend as a remote data source
You can use a GitLab-managed Terraform state as a
[
Terraform data source
](
https://www.terraform.io/docs/providers/terraform/d/remote_state.html
)
.
To use your existing Terraform state backend as a data source, provide the following details
as
[
Terraform input variables
](
https://www.terraform.io/docs/configuration/variables.html
)
:
-
**address**
: The URL of the remote state backend you want to use as a data source.
For example,
`https://gitlab.com/api/v4/projects/<TARGET-PROJECT-ID>/terraform/state/<TARGET-STATE-NAME>`
.
-
**username**
: The username to authenticate with the data source. If you are using a
[
Personal Access Token
](
../profile/personal_access_tokens.md
)
for
authentication, this is your GitLab username. If you are using GitLab CI, this is
`'gitlab-ci-token'`
.
-
**password**
: The password to authenticate with the data source. If you are using a Personal Access Token for
authentication, this is the token value. If you are using GitLab CI, it is the contents of the
`${CI_JOB_TOKEN}`
CI variable.
An example setup is shown below:
1.
Create a file named
`example.auto.tfvars`
with the following contents:
```
plaintext
example_remote_state_address=https://gitlab.com/api/v4/projects/<TARGET-PROJECT-ID>/terraform/state/<TARGET-STATE-NAME>
example_username=<GitLab username>
example_access_token=<GitLab Personal Acceess Token>
```
1.
Define the data source by adding the following code block in a
`.tf`
file (such as
`data.tf`
):
```
hcl
data
"terraform_remote_state"
"example"
{
backend
=
"http"
config
=
{
address
=
var
.
example_remote_state_address
username
=
var
.
example_username
password
=
var
.
example_access_token
}
}
```
Outputs from the data source can now be referenced within your Terraform resources
using
`data.terraform_remote_state.example.outputs.<OUTPUT-NAME>`
.
You need at least
[
developer access
](
../permissions.md
)
to the target project
to read the Terraform state.
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