@@ -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,23 +80,6 @@ Your output should be similar to the one below:
95
80
```
96
81
```
97
82
98
- ## Add IAM Policy Binding to Google Cloud Organization
99
-
100
- Run the following command in terminal:
101
- ``` 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"
109
- ```
110
-
111
- Your output should be similar to the one below:
112
- ```
113
- ```
114
-
115
83
## Create Terraform Configurations Using TerraHub
116
84
117
85
Run the following commands in terminal:
@@ -123,80 +91,144 @@ Your output should be similar to the one below:
123
91
```
124
92
Usage: terrahub [command] [options]
125
93
126
- terrahub@0.1.28 (built: 2019-02-08T17:17:41.912Z )
94
+ terrahub@0.0.1 (built: 2018-04-07T19:15:39.787Z )
127
95
```
128
96
129
97
> NOTE: If you don't have TerraHub CLI, check out this
130
98
[ installation guide] ( https://www.npmjs.com/package/terrahub )
131
99
132
100
Run the following command in terminal:
133
101
``` shell
134
- mkdir demo-terraform-google
135
- cd demo-terraform-google
136
- terrahub project -n demo-terraform-google
102
+ mkdir demo-terraform-automation- google
103
+ cd demo-terraform-automation- google
104
+ terrahub project -n demo-terraform-automation- google
137
105
```
138
106
139
107
Your output should be similar to the one below:
140
108
```
141
109
✅ Project successfully initialized
142
110
```
143
111
144
- ## Create TerraHub Components
112
+ ## Create TerraHub Components from Templates
145
113
146
114
Run the following command in terminal:
147
115
``` 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
116
+ terrahub component -t google_storage_bucket -n google_storage \
117
+ && terrahub component -t google_cloudfunctions_function -n google_function -o ../google_storage
154
118
```
155
119
156
120
Your output should be similar to the one below:
157
121
```
158
122
✅ Done
159
123
```
160
124
161
- ## Visualize TerraHub Components
125
+ ## Update Project Config
162
126
163
127
Run the following command in terminal:
164
128
``` shell
165
- terrahub graph
129
+ terrahub configure -c terraform.version=0.11.11
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} "
166
133
```
167
134
168
135
Your output should be similar to the one below:
169
136
```
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]
137
+ ✅ Done
177
138
```
178
139
179
- ## Update Project Config
140
+ ## Customize TerraHub Component for Storage Bucket
180
141
181
142
Run the following command in terminal:
182
143
``` 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} "
144
+ terrahub configure -i google_storage -c component.template.terraform.backend.local.path=' /tmp/.terrahub/local_backend/google_storage/terraform.tfstate'
145
+ terrahub configure -i google_storage -c component.template.resource.google_storage_bucket.google_storage.name=' demo_terraform_automation_${local.project["code"]}'
146
+ terrahub configure -i google_storage -c component.template.resource.google_storage_bucket.google_storage.location=' US'
147
+ terrahub configure -i google_storage -c component.template.resource.google_storage_bucket.google_storage.project=' ${local.google_project_id}'
148
+ terrahub configure -i google_storage -c component.template.variable -D -y
186
149
```
187
150
188
151
Your output should be similar to the one below:
189
152
```
190
153
✅ Done
191
154
```
192
155
156
+ ## Customize TerraHub Component for Google Cloud Function
157
+
158
+ Run the following command in terminal:
159
+ ``` shell
160
+ terrahub configure -i google_function -c component.template.terraform.backend.local.path=' /tmp/.terrahub/local_backend/google_function/terraform.tfstate'
161
+ terrahub configure -i google_function -c component.template.data.terraform_remote_state.storage.backend=' local'
162
+ terrahub configure -i google_function -c component.template.data.terraform_remote_state.storage.config.path=' /tmp/.terrahub/local_backend/google_storage/terraform.tfstate'
163
+ terrahub configure -i google_function -c component.template.resource.google_storage_bucket_object.google_storage_object.name=' demo.zip'
164
+ terrahub configure -i google_function -c component.template.resource.google_storage_bucket_object.google_storage_object.bucket=' ${data.terraform_remote_state.storage.thub_id}'
165
+ terrahub configure -i google_function -c component.template.resource.google_storage_bucket_object.google_storage_object.source=' ./demo.zip'
166
+ terrahub configure -i google_function -c component.template.resource.google_cloudfunctions_function.google_function.depends_on[0]=' google_storage_bucket_object.google_storage_object'
167
+ terrahub configure -i google_function -c component.template.resource.google_cloudfunctions_function.google_function.name=' demofunction${local.project["code"]}'
168
+ terrahub configure -i google_function -c component.template.resource.google_cloudfunctions_function.google_function.region=' us-central1'
169
+ terrahub configure -i google_function -c component.template.resource.google_cloudfunctions_function.google_function.runtime=' nodejs8'
170
+ terrahub configure -i google_function -c component.template.resource.google_cloudfunctions_function.google_function.description=' My demo function'
171
+ terrahub configure -i google_function -c component.template.resource.google_cloudfunctions_function.google_function.available_memory_mb=128
172
+ terrahub configure -i google_function -c component.template.resource.google_cloudfunctions_function.google_function.source_archive_bucket=' ${data.terraform_remote_state.storage.thub_id}'
173
+ terrahub configure -i google_function -c component.template.resource.google_cloudfunctions_function.google_function.source_archive_object=' ${google_storage_bucket_object.google_storage_object.name}'
174
+ terrahub configure -i google_function -c component.template.resource.google_cloudfunctions_function.google_function.trigger_http=true
175
+ terrahub configure -i google_function -c component.template.resource.google_cloudfunctions_function.google_function.timeout=60
176
+ terrahub configure -i google_function -c component.template.resource.google_cloudfunctions_function.google_function.entry_point=' helloGET'
177
+ terrahub configure -i google_function -c component.template.variable -D -y
178
+ terrahub configure -i google_function -c component.template.output -D -y
179
+ terrahub configure -i google_function -c component.template.output.id.value=' ${google_cloudfunctions_function.google_function.id}'
180
+ terrahub configure -i google_function -c component.template.output.trigger_url.value=' ${google_cloudfunctions_function.google_function.https_trigger_url}'
181
+ terrahub configure -i google_function -c build.env.variables.THUB_FUNCTION_ZIP=' demo.zip'
182
+ terrahub configure -i google_function -c build.env.variables.THUB_BUILD_PATH=' ..'
183
+ terrahub configure -i google_function -c build.env.variables.THUB_FUNCTION_TXT=' demo.txt'
184
+ terrahub configure -i google_function -c build.env.variables.THUB_BUILD_OK=' true'
185
+ terrahub configure -i google_function -c build.phases.pre_build.commands[0]=' echo "BUILD: Running pre_build step"'
186
+ terrahub configure -i google_function -c build.phases.pre_build.commands[1]=' if [ ! -e "$THUB_FUNCTION_TXT" ]; then touch "$THUB_FUNCTION_TXT"; fi'
187
+ terrahub configure -i google_function -c build.phases.pre_build.finally[0]=' echo "BUILD: pre_build step successful"'
188
+ terrahub configure -i google_function -c build.phases.build.commands[0]=' echo "BUILD: Running build step"'
189
+ terrahub configure -i google_function -c build.phases.build.commands[1]=' if [ "$(head -n 1 "$THUB_FUNCTION_TXT")" != "$(stat -c %y "${THUB_BUILD_PATH}/index.js")" ]; then zip -j ${THUB_FUNCTION_ZIP} ${THUB_BUILD_PATH}/index.js; fi'
190
+ terrahub configure -i google_function -c build.phases.build.commands[2]=' if [ "$(head -n 1 "$THUB_FUNCTION_TXT")" != "$(stat -c %y "${THUB_BUILD_PATH}/index.js")" ]; then terrahub configure -i google_function -c component.template.resource.google_storage_bucket_object.google_storage_object.name=$(date +%s).zip; fi'
191
+ terrahub configure -i google_function -c build.phases.build.finally[0]=' echo "BUILD: build step successful"'
192
+ terrahub configure -i google_function -c build.phases.post_build.commands[0]=' echo "BUILD: Running post_build step"'
193
+ terrahub configure -i google_function -c build.phases.post_build.commands[1]=' echo $(stat -c %y "${THUB_BUILD_PATH}/index.js") > "$THUB_FUNCTION_TXT"'
194
+ terrahub configure -i google_function -c build.phases.post_build.finally[0]=' echo "BUILD: post_build step successful"'
195
+ ```
196
+
197
+ Your output should be similar to the one below:
198
+ ```
199
+ ✅ Done
200
+ ```
201
+
202
+ ## Visualize TerraHub Components
203
+
204
+ Run the following command in terminal:
205
+ ``` shell
206
+ terrahub graph
207
+ ```
208
+
209
+ Your output should be similar to the one below:
210
+ ```
211
+ Project: demo-terraform-automation-google
212
+ └─ google_storage [path: ./google_storage]
213
+ └─ google_function [path: ./google_function]
214
+ ```
215
+
216
+
193
217
## Run TerraHub Automation
194
218
195
219
Run the following command in terminal:
196
220
``` shell
221
+ terrahub build -i google_function
197
222
terrahub run -a -y
198
223
```
199
224
200
225
Your output should be similar to the one below:
201
226
```
202
227
```
228
+
229
+ ## Run Test Command
230
+
231
+ Run the following command in terminal:
232
+ ```
233
+ curl https://us-central1-terrahub-123456.cloudfunctions.net/demofunctionxxxxxxxx
234
+ ```
0 commit comments