@@ -16,23 +16,11 @@ Manual Setup (set values in double quotes and run the following command in termi
16
16
``` shell
17
17
export GOOGLE_CLOUD_PROJECT=" " # # e.g. terrahub-123456
18
18
export GOOGLE_APPLICATION_CREDENTIALS=" " # # e.g. ${HOME}/.config/gcloud/terraform.json
19
- export ORG_ID=" " # # e.g. 123456789012
20
19
export BILLING_ID=" " # # e.g. 123456-ABCDEF-ZYXWVU
21
20
export PROJECT_NAME=" " # # e.g. TerraHub
22
21
export IAM_NAME=" " # # e.g. terraform
23
22
export IAM_DESC=" " # # e.g. terraform service account
24
23
```
25
-
26
- ### Setup ORG_ID Programmatically
27
-
28
- Automated Setup (run the following command in terminal):
29
- ``` shell
30
- export ORG_ID=" $( gcloud organizations list --format=json | jq ' .[0].name[14:]' ) "
31
- ```
32
-
33
- > NOTE: If you don't have JQ CLI, check out this
34
- [ installation guide] ( https://stedolan.github.io/jq/download/ )
35
-
36
24
### Setup BILLING_ID Programmatically
37
25
38
26
Automated Setup (run the following command in terminal):
@@ -49,18 +37,15 @@ Run the following command in terminal:
49
37
``` shell
50
38
gcloud projects create ${GOOGLE_CLOUD_PROJECT} \
51
39
--name=" ${PROJECT_NAME} " \
52
- --organization=" ${ORG_ID} " \
53
40
--set-as-default
54
41
55
- gcloud config set project ${GOOGLE_CLOUD_PROJECT}
42
+ gcloud beta billing projects link ${GOOGLE_CLOUD_PROJECT} \
43
+ --billing-account=" ${BILLING_ID} "
56
44
57
45
gcloud services enable cloudresourcemanager.googleapis.com
58
46
gcloud services enable cloudbilling.googleapis.com
59
47
gcloud services enable iam.googleapis.com
60
- gcloud services enable compute.googleapis.com
61
-
62
- gcloud beta billing projects link ${GOOGLE_CLOUD_PROJECT} \
63
- --billing-account=" ${BILLING_ID} "
48
+ gcloud services enable cloudfunctions.googleapis.com
64
49
```
65
50
66
51
Your output should be similar to the one below:
@@ -95,108 +80,174 @@ Your output should be similar to the one below:
95
80
```
96
81
```
97
82
98
- ## Add IAM Policy Binding to Google Cloud Organization
83
+ ## Create Terraform Configurations Using TerraHub
99
84
100
- Run the following command in terminal:
85
+ Run the following commands in terminal:
101
86
``` shell
102
- gcloud organizations add-iam-policy-binding ${ORG_ID} \
103
- --member=" serviceAccount:${IAM_NAME} @${GOOGLE_CLOUD_PROJECT} .iam.gserviceaccount.com" \
104
- --role=" roles/resourcemanager.projectCreator"
105
-
106
- gcloud organizations add-iam-policy-binding ${ORG_ID} \
107
- --member=" serviceAccount:${IAM_NAME} @${GOOGLE_CLOUD_PROJECT} .iam.gserviceaccount.com" \
108
- --role=" roles/billing.user"
87
+ terrahub --help | head -3
109
88
```
110
89
111
90
Your output should be similar to the one below:
112
91
```
92
+ Usage: terrahub [command] [options]
93
+
94
+ terrahub@0.2.2 (built: 2019-02-28T13:32:40.386Z)
113
95
```
114
96
115
- ## Create Terraform Configurations Using TerraHub
97
+ > NOTE: If you don't have TerraHub CLI, check out this
98
+ [ installation guide] ( https://www.npmjs.com/package/terrahub )
116
99
117
- Run the following commands in terminal:
100
+ Run the following command in terminal:
118
101
``` shell
119
- terrahub --help | head -3
102
+ mkdir demo-terraform-automation-google
103
+ cd demo-terraform-automation-google
104
+ terrahub project -n demo-terraform-automation-google
120
105
```
121
106
122
107
Your output should be similar to the one below:
123
108
```
124
- Usage: terrahub [command] [options]
109
+ ✅ Project successfully initialized
110
+ ```
111
+
112
+ ## Create TerraHub Components from Templates
125
113
126
- terrahub@0.1.28 (built: 2019-02-08T17:17:41.912Z)
114
+ Run the following command in terminal:
115
+ ``` shell
116
+ terrahub component -t google_storage_bucket -n demo_storage_bucket && \
117
+ terrahub component -t google_storage_bucket_object -n demo_object -o ../demo_storage_bucket && \
118
+ terrahub component -t google_cloudfunctions_function -n demo_function -o ../demo_object
127
119
```
128
120
129
- > NOTE: If you don't have TerraHub CLI, check out this
130
- [ installation guide] ( https://www.npmjs.com/package/terrahub )
121
+ Your output should be similar to the one below:
122
+ ```
123
+ ✅ Done
124
+ ```
125
+
126
+ ## Update Project Config
131
127
132
128
Run the following command in terminal:
133
129
``` shell
134
- mkdir demo-terraform- google
135
- cd demo-terraform-google
136
- terrahub project -n demo-terraform-google
130
+ terrahub configure -c template.provider. google={}
131
+ terrahub configure -c template.locals.google_project_id= " ${GOOGLE_CLOUD_PROJECT} "
132
+ terrahub configure -c template.locals.google_billing_account= " ${BILLING_ID} "
137
133
```
138
134
139
135
Your output should be similar to the one below:
140
136
```
141
- ✅ Project successfully initialized
137
+ ✅ Done
142
138
```
143
139
144
- ## Create TerraHub Components
140
+ ## Customize TerraHub Component for Storage Bucket
145
141
146
142
Run the following command in terminal:
147
143
``` shell
148
- terrahub component -t google_project -n project
149
- terrahub component -t google_service_account -n service_account -o ../project
150
- terrahub component -t google_service_account_key -n service_account_key -o ../service_account
151
- terrahub component -t google_project_iam_member -n project_iam_member -o ../project
152
- terrahub component -t google_project_iam_binding -n project_iam_policy_binding_storage_admin -o ../project_iam_member
153
- terrahub component -t google_project_iam_binding -n project_iam_policy_binding_compute_admin -o ../project_iam_member
144
+ terrahub configure -i demo_storage_bucket -c component.template.terraform.backend.local.path=' /tmp/.terrahub/local_backend/demo_storage_bucket/terraform.tfstate'
145
+ terrahub configure -i demo_storage_bucket -c component.template.resource.google_storage_bucket.demo_storage_bucket.name=' demo_storage_bucket_${local.project["code"]}'
146
+ terrahub configure -i demo_storage_bucket -c component.template.resource.google_storage_bucket.demo_storage_bucket.location=' US'
147
+ terrahub configure -i demo_storage_bucket -c component.template.resource.google_storage_bucket.demo_storage_bucket.project=" ${GOOGLE_CLOUD_PROJECT} "
148
+ terrahub configure -i demo_storage_bucket -c component.template.variable -D -y
154
149
```
155
150
156
151
Your output should be similar to the one below:
157
152
```
158
153
✅ Done
159
154
```
160
155
161
- ## Visualize TerraHub Components
156
+ ## Customize TerraHub Component for Storage Bucket Object
162
157
163
158
Run the following command in terminal:
164
159
``` shell
165
- terrahub graph
160
+ terrahub configure -i demo_object -c component.template.terraform.backend.local.path=' /tmp/.terrahub/local_backend/demo_object/terraform.tfstate'
161
+ terrahub configure -i demo_object -c component.template.data.terraform_remote_state.storage.backend=' local'
162
+ terrahub configure -i demo_object -c component.template.data.terraform_remote_state.storage.config.path=' /tmp/.terrahub/local_backend/demo_storage_bucket/terraform.tfstate'
163
+ terrahub configure -i demo_object -c component.template.resource.google_storage_bucket_object.demo_object.name=' demo.zip'
164
+ terrahub configure -i demo_object -c component.template.resource.google_storage_bucket_object.demo_object.bucket=' ${data.terraform_remote_state.storage.thub_id}'
165
+ terrahub configure -i demo_object -c component.template.resource.google_storage_bucket_object.demo_object.source=' ./demo.zip'
166
+ terrahub configure -i demo_object -c component.template.variable -D -y
167
+ terrahub configure -i demo_object -c build.env.variables.THUB_LAMBDA_ZIP=' demo.zip'
168
+ terrahub configure -i demo_object -c build.env.variables.THUB_BUILD_PATH=' ..'
169
+ terrahub configure -i demo_object -c build.env.variables.THUB_BUILD_OK=' true'
170
+ terrahub configure -i demo_object -c build.phases.build.commands[0]=' echo "BUILD: Running build step"'
171
+ terrahub configure -i demo_object -c build.phases.build.commands[1]=' zip -j ${THUB_LAMBDA_ZIP} ${THUB_BUILD_PATH}/index.js'
172
+ terrahub configure -i demo_object -c build.phases.build.finally[0]=' echo "BUILD: build step successful"'
173
+ terrahub configure -i demo_object -c build.phases.post_build.commands[0]=' echo "BUILD: Running post_build step"'
174
+ terrahub configure -i demo_object -c build.phases.post_build.commands[1]=' rm -rf ./nodejs-docs-samples'
175
+ terrahub configure -i demo_object -c build.phases.post_build.finally[0]=' echo "BUILD: post_build step successful"'
166
176
```
167
177
168
178
Your output should be similar to the one below:
169
179
```
170
- Project: demo-terraform-google
171
- └─ project [path: ./project]
172
- ├─ project_iam_member [path: ./project_iam_member]
173
- │ ├─ project_iam_binding_compute_admin [path: ./project_iam_binding_compute_admin]
174
- │ └─ project_iam_binding_storage_admin [path: ./project_iam_binding_storage_admin]
175
- └─ service_account [path: ./service_account]
176
- └─ service_account_key [path: ./service_account_key]
180
+ ✅ Done
177
181
```
178
182
179
- ## Update Project Config
183
+ ## Customize TerraHub Component for Google Cloud Function
180
184
181
185
Run the following command in terminal:
182
186
``` shell
183
- terrahub configure -c template.locals.google_org_id=" ${ORG_ID} "
184
- terrahub configure -c template.locals.google_billing_account=" ${BILLING_ID} "
185
- terrahub configure -c template.locals.google_project_id=" ${GOOGLE_CLOUD_PROJECT} "
187
+ terrahub configure -i demo_function -c component.template.terraform.backend.local.path=' /tmp/.terrahub/local_backend/demo_function/terraform.tfstate'
188
+ terrahub configure -i demo_function -c component.template.data.terraform_remote_state.storage.backend=' local'
189
+ terrahub configure -i demo_function -c component.template.data.terraform_remote_state.storage.config.path=' /tmp/.terrahub/local_backend/demo_storage_bucket/terraform.tfstate'
190
+ terrahub configure -i demo_function -c component.template.data.terraform_remote_state.object.backend=' local'
191
+ terrahub configure -i demo_function -c component.template.data.terraform_remote_state.object.config.path=' /tmp/.terrahub/local_backend/demo_object/terraform.tfstate'
192
+ terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.name=' demofunction${local.project["code"]}'
193
+ terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.region=' us-central1'
194
+ terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.runtime=' nodejs8'
195
+ terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.description=' My demo function ${data.terraform_remote_state.object.md5hash}'
196
+ terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.available_memory_mb=128
197
+ terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.source_archive_bucket=' ${data.terraform_remote_state.storage.thub_id}'
198
+ terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.source_archive_object=' ${data.terraform_remote_state.object.output_name}'
199
+ terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.trigger_http=true
200
+ terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.timeout=60
201
+ terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.entry_point=' helloGET'
202
+ terrahub configure -i demo_function -c component.template.variable -D -y
203
+ terrahub configure -i demo_function -c component.template.output -D -y
204
+ terrahub configure -i demo_function -c component.template.output.id.value=' ${google_cloudfunctions_function.demo_function.id}'
205
+ terrahub configure -i demo_function -c component.template.output.trigger_url.value=' ${google_cloudfunctions_function.demo_function.https_trigger_url}'
206
+ terrahub configure -i demo_function -c build.env.variables.THUB_LAMBDA_ZIP=' demo.zip'
207
+ terrahub configure -i demo_function -c build.env.variables.THUB_BUILD_PATH=' ../demo_object'
208
+ terrahub configure -i demo_function -c build.env.variables.THUB_BUILD_OK=' true'
209
+ terrahub configure -i demo_function -c build.phases.post_build.commands[0]=' echo "BUILD: Running post_build step"'
210
+ terrahub configure -i demo_function -c build.phases.post_build.commands[1]=' rm ${THUB_BUILD_PATH}/${THUB_LAMBDA_ZIP}'
211
+ terrahub configure -i demo_function -c build.phases.post_build.finally[0]=' echo "BUILD: post_build step successful"'
186
212
```
187
213
188
214
Your output should be similar to the one below:
189
215
```
190
216
✅ Done
191
217
```
192
218
219
+ ## Visualize TerraHub Components
220
+
221
+ Run the following command in terminal:
222
+ ``` shell
223
+ terrahub graph
224
+ ```
225
+
226
+ Your output should be similar to the one below:
227
+ ```
228
+ Project: demo-terraform-automation-google
229
+ └─ demo_storage_bucket_7b3c5d2c [path: ./demo_storage_bucket_7b3c5d2c]
230
+ └─ demo_object_7b3c5d2c [path: ./demo_object_7b3c5d2c]
231
+ └─ demo_function_7b3c5d2c [path: ./demo_function_7b3c5d2c]
232
+ ```
233
+
234
+
193
235
## Run TerraHub Automation
194
236
195
237
Run the following command in terminal:
196
238
``` shell
197
- terrahub run -a -y
239
+ terrahub build -i=demo_object && \
240
+ terrahub run -a -y && \
241
+ terrahub build -i=demo_function
198
242
```
199
243
200
244
Your output should be similar to the one below:
201
245
```
202
246
```
247
+
248
+ ## Run Test Command
249
+
250
+ Run the following command in terminal:
251
+ ```
252
+ curl https://us-central1-terrahub-demo-xxxxxxxx.cloudfunctions.net/demofunctionxxxxxxxx
253
+ ```
0 commit comments