@@ -6,7 +6,7 @@ This allows deployments to be made from anywhere that can access the state
6
6
without corrupting or conflicting with any existing resources from previous
7
7
deployments.
8
8
9
- Using remote state is therefore strongly recommended for environments which
9
+ Using remote state is therefore strongly recommended for environments which
10
10
should only be instantiated once, e.g. ` production ` and ` staging ` .
11
11
12
12
This page provides guidance for configuring remote states using backends
@@ -31,20 +31,20 @@ but includes some missing details and is modified for common appliance workflows
31
31
32
32
1 . Create the backend file:
33
33
34
- ``` shell
35
- cp environments/site/tofu/example-backends/gitlab.tf environments/$ENV /tofu
36
- ```
34
+ ``` shell
35
+ cp environments/site/tofu/example-backends/gitlab.tf environments/$ENV /tofu
36
+ ```
37
37
38
38
2 . Modify ` environments/$ENV/tofu/gitlab.tf ` to set the default for the
39
39
project ID. This can be found by clicking the 3-dot menu at the top right of
40
40
the GitLab project page.
41
41
42
- ` ` ` terraform
43
- # environments/$ENV/tofu/backend.tf:
44
- terraform {
45
- backend " http" {}
46
- }
47
- ` ` `
42
+ ``` terraform
43
+ # environments/$ENV/tofu/backend.tf:
44
+ terraform {
45
+ backend "http" {}
46
+ }
47
+ ```
48
48
49
49
3 . Commit it.
50
50
@@ -55,12 +55,12 @@ but includes some missing details and is modified for common appliance workflows
55
55
1 . Create an access token in the GitLab UI, using either:
56
56
57
57
a. If project access tokens are available, create one via
58
- Project > Settings > Access tokens.
59
- The token must have ` Maintainer` role and ` api` scope.
58
+ Project > Settings > Access tokens.
59
+ The token must have ` Maintainer ` role and ` api ` scope.
60
60
61
61
b. Otherwise create a personal access token via
62
- User profile > Preferences > Access tokens.
63
- The token must have ` api` scope.
62
+ User profile > Preferences > Access tokens.
63
+ The token must have ` api ` scope.
64
64
65
65
Copy the generated secret and set an environment variable:
66
66
@@ -74,17 +74,17 @@ but includes some missing details and is modified for common appliance workflows
74
74
export TF_VAR_gitlab_username=$your_username
75
75
```
76
76
77
- 4 . With the environment activated, initialise OpenTofu.
77
+ 3 . With the environment activated, initialise OpenTofu.
78
78
79
- If no local state exists run:
79
+ If no local state exists run:
80
80
81
- ` ` ` shell
82
- cd environments/$ENV /tofu/
83
- tofu init
84
- ` ` `
85
-
86
- otherwise append ` -migrate-state` to the ` init` command to attempt to copy
87
- local state to the new backend.
81
+ ``` shell
82
+ cd environments/$ENV /tofu/
83
+ tofu init
84
+ ```
85
+
86
+ otherwise append ` -migrate-state ` to the ` init ` command to attempt to copy
87
+ local state to the new backend.
88
88
89
89
OpenTofu is now configured to use GitLab to store state for this environment.
90
90
@@ -111,60 +111,61 @@ per-checkout configuration is required.
111
111
112
112
1 . Create an S3 bucket with a name ` ${cluster_name}-${environment_name}-tfstate `
113
113
where:
114
- - ` CLUSTER_NAME` is defined in ` environments/$ENV /tofu/main.tf`
115
- - ` $ENVIRONMENT_NAME ` is the name of the environment directory
116
114
117
- e.g.
115
+ - ` CLUSTER_NAME ` is defined in ` environments/$ENV/tofu/main.tf `
116
+ - ` $ENVIRONMENT_NAME ` is the name of the environment directory
117
+
118
+ e.g.
118
119
119
- ` ` ` shell
120
- openstack container create research-staging-tfstate
121
- ` ` `
120
+ ``` shell
121
+ openstack container create research-staging-tfstate
122
+ ```
122
123
123
124
2 . Create ` ec2 ` credentials:
124
125
125
- ` ` ` shell
126
- openstack ec2 credentials create
127
- ` ` `
126
+ ``` shell
127
+ openstack ec2 credentials create
128
+ ```
128
129
129
- and make a note of the ` access` field returned.
130
+ and make a note of the ` access ` field returned.
130
131
131
132
3 . Create the backend file:
132
133
133
- ` ` ` shell
134
- cp environments/site/tofu/example-backends/s3.tf environments/$ENV /tofu
135
- ` ` `
134
+ ``` shell
135
+ cp environments/site/tofu/example-backends/s3.tf environments/$ENV /tofu
136
+ ```
136
137
137
138
4 . Modify ` environments/$ENV/tofu/s3.tf ` to set the default for ` s3_backend_endpoint ` .
138
139
This is the radosgw address. If not known it can be determined by creating a
139
140
public bucket, and then getting the URL using
140
- Project > Containers > (your public bucket) > Link
141
+ Project > Containers > (your public bucket) > Link
141
142
which provides a URL of the form ` https://$ENDPOINT/swift/... ` .
142
143
143
144
5 . Add the following to ` environments/$ENV/activate ` :
144
145
145
- ` ` ` bash
146
- export AWS_ACCESS_KEY_ID=$EC2_CREDENTIALS_ACCESS
147
- export AWS_SECRET_ACCESS_KEY=$( openstack ec2 credentials show $AWS_ACCESS_KEY_ID -f value -c secret)
148
- ` ` `
149
-
150
- replacing ` $EC2_CREDENTIALS_ACCESS ` with the ` access` field of the created
151
- credentials.
146
+ ``` bash
147
+ export AWS_ACCESS_KEY_ID=$EC2_CREDENTIALS_ACCESS
148
+ export AWS_SECRET_ACCESS_KEY=$( openstack ec2 credentials show $AWS_ACCESS_KEY_ID -f value -c secret)
149
+ ```
152
150
153
- This avoids these credentials being persisted in local files.
151
+ replacing ` $EC2_CREDENTIALS_ACCESS ` with the ` access ` field of the created
152
+ credentials.
153
+
154
+ This avoids these credentials being persisted in local files.
154
155
155
156
6 . Copy the lines above into your shell to set them for your current shell.
156
157
157
158
7 . With the environment activated, initialise OpenTofu.
158
159
159
- If no local state exists run:
160
+ If no local state exists run:
161
+
162
+ ``` shell
163
+ cd environments/$ENV /tofu/
164
+ tofu init
165
+ ```
160
166
161
- ` ` ` shell
162
- cd environments/$ENV /tofu/
163
- tofu init
164
- ` ` `
165
-
166
- otherwise append ` -migrate-state` to the ` init` command to attempt to copy
167
- local state to the new backend.
167
+ otherwise append ` -migrate-state ` to the ` init ` command to attempt to copy
168
+ local state to the new backend.
168
169
169
170
8 . If this fails, try setting ` use_path_style = true ` in ` environments/$ENV/tofu/s3.tf ` .
170
171
0 commit comments