Skip to content

Commit 4b4ca56

Browse files
rootroot
authored andcommitted
change structure
1 parent d7a4400 commit 4b4ca56

File tree

5 files changed

+73
-104
lines changed

5 files changed

+73
-104
lines changed

README.md

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ Your output should be similar to the one below:
114114
Run the following command in terminal:
115115
```shell
116116
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
117+
&& terrahub component -t google_cloudfunctions_function -n demo_function -o ../demo_storage_bucket
119118
```
120119

121120
Your output should be similar to the one below:
@@ -145,7 +144,7 @@ Run the following command in terminal:
145144
terrahub configure -i demo_storage_bucket -c component.template.terraform.backend.local.path='/tmp/.terrahub/local_backend/demo_storage_bucket/terraform.tfstate'
146145
terrahub configure -i demo_storage_bucket -c component.template.resource.google_storage_bucket.demo_storage_bucket.name='demo_storage_bucket_${local.project["code"]}'
147146
terrahub configure -i demo_storage_bucket -c component.template.resource.google_storage_bucket.demo_storage_bucket.location='US'
148-
terrahub configure -i demo_storage_bucket -c component.template.resource.google_storage_bucket.demo_storage_bucket.project="${GOOGLE_CLOUD_PROJECT}"
147+
terrahub configure -i demo_storage_bucket -c component.template.resource.google_storage_bucket.demo_storage_bucket.project='${local.google_project_id}'
149148
terrahub configure -i demo_storage_bucket -c component.template.variable -D -y
150149
```
151150

@@ -154,56 +153,45 @@ Your output should be similar to the one below:
154153
✅ Done
155154
```
156155

157-
## Customize TerraHub Component for Storage Bucket Object
158-
159-
Run the following command in terminal:
160-
```shell
161-
terrahub configure -i demo_object -c component.template.terraform.backend.local.path='/tmp/.terrahub/local_backend/demo_object/terraform.tfstate'
162-
terrahub configure -i demo_object -c component.template.data.terraform_remote_state.storage.backend='local'
163-
terrahub configure -i demo_object -c component.template.data.terraform_remote_state.storage.config.path='/tmp/.terrahub/local_backend/demo_storage_bucket/terraform.tfstate'
164-
terrahub configure -i demo_object -c component.template.resource.google_storage_bucket_object.demo_object.name='demo.zip'
165-
terrahub configure -i demo_object -c component.template.resource.google_storage_bucket_object.demo_object.bucket='${data.terraform_remote_state.storage.thub_id}'
166-
terrahub configure -i demo_object -c component.template.resource.google_storage_bucket_object.demo_object.source='./demo.zip'
167-
terrahub configure -i demo_object -c component.template.variable -D -y
168-
terrahub configure -i demo_object -c build.env.variables.THUB_LAMBDA_ZIP='demo.zip'
169-
terrahub configure -i demo_object -c build.env.variables.THUB_BUILD_PATH='..'
170-
terrahub configure -i demo_object -c build.env.variables.THUB_BUILD_OK='true'
171-
terrahub configure -i demo_object -c build.phases.build.commands[0]='echo "BUILD: Running build step"'
172-
terrahub configure -i demo_object -c build.phases.build.commands[1]='zip -j ${THUB_LAMBDA_ZIP} ${THUB_BUILD_PATH}/index.js'
173-
terrahub configure -i demo_object -c build.phases.build.finally[0]='echo "BUILD: build step successful"'
174-
terrahub configure -i demo_object -c build.phases.post_build.commands[0]='echo "BUILD: Running post_build step"'
175-
terrahub configure -i demo_object -c build.phases.post_build.commands[1]='rm -rf ./nodejs-docs-samples'
176-
terrahub configure -i demo_object -c build.phases.post_build.finally[0]='echo "BUILD: post_build step successful"'
177-
```
178-
179-
Your output should be similar to the one below:
180-
```
181-
✅ Done
182-
```
183-
184156
## Customize TerraHub Component for Google Cloud Function
185157

186158
Run the following command in terminal:
187159
```shell
188160
terrahub configure -i demo_function -c component.template.terraform.backend.local.path='/tmp/.terrahub/local_backend/demo_function/terraform.tfstate'
189161
terrahub configure -i demo_function -c component.template.data.terraform_remote_state.storage.backend='local'
190162
terrahub configure -i demo_function -c component.template.data.terraform_remote_state.storage.config.path='/tmp/.terrahub/local_backend/demo_storage_bucket/terraform.tfstate'
191-
terrahub configure -i demo_function -c component.template.data.terraform_remote_state.object.backend='local'
192-
terrahub configure -i demo_function -c component.template.data.terraform_remote_state.object.config.path='/tmp/.terrahub/local_backend/demo_object/terraform.tfstate'
163+
terrahub configure -i demo_function -c component.template.resource.google_storage_bucket_object.demo_object.name='demo.zip'
164+
terrahub configure -i demo_function -c component.template.resource.google_storage_bucket_object.demo_object.bucket='${data.terraform_remote_state.storage.thub_id}'
165+
terrahub configure -i demo_function -c component.template.resource.google_storage_bucket_object.demo_object.source='./demo.zip'
166+
terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.depends_on[0]='google_storage_bucket_object.demo_object'
193167
terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.name='demofunction${local.project["code"]}'
194168
terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.region='us-central1'
195169
terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.runtime='nodejs8'
196-
terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.description='My demo function ${data.terraform_remote_state.object.md5hash}'
170+
terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.description='My demo function'
197171
terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.available_memory_mb=128
198172
terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.source_archive_bucket='${data.terraform_remote_state.storage.thub_id}'
199-
terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.source_archive_object='${data.terraform_remote_state.object.output_name}'
173+
terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.source_archive_object='${google_storage_bucket_object.demo_object.name}'
200174
terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.trigger_http=true
201175
terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.timeout=60
202176
terrahub configure -i demo_function -c component.template.resource.google_cloudfunctions_function.demo_function.entry_point='helloGET'
203177
terrahub configure -i demo_function -c component.template.variable -D -y
204178
terrahub configure -i demo_function -c component.template.output -D -y
205179
terrahub configure -i demo_function -c component.template.output.id.value='${google_cloudfunctions_function.demo_function.id}'
206180
terrahub configure -i demo_function -c component.template.output.trigger_url.value='${google_cloudfunctions_function.demo_function.https_trigger_url}'
181+
terrahub configure -i demo_function -c build.env.variables.THUB_FUNCTION_ZIP='demo.zip'
182+
terrahub configure -i demo_function -c build.env.variables.THUB_BUILD_PATH='..'
183+
terrahub configure -i demo_function -c build.env.variables.THUB_FUNCTION_TXT='demo.txt'
184+
terrahub configure -i demo_function -c build.env.variables.THUB_BUILD_OK='true'
185+
terrahub configure -i demo_function -c build.phases.pre_build.commands[0]='echo "BUILD: Running pre_build step"'
186+
terrahub configure -i demo_function -c build.phases.pre_build.commands[1]='if [ ! -e "$THUB_FUNCTION_TXT" ]; then touch "$THUB_FUNCTION_TXT"; fi'
187+
terrahub configure -i demo_function -c build.phases.pre_build.finally[0]='echo "BUILD: pre_build step successful"'
188+
terrahub configure -i demo_function -c build.phases.build.commands[0]='echo "BUILD: Running build step"'
189+
terrahub configure -i demo_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 demo_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 demo_function -c component.template.resource.google_storage_bucket_object.demo_object.name=$(date +%s).zip; fi'
191+
terrahub configure -i demo_function -c build.phases.build.finally[0]='echo "BUILD: build step successful"'
192+
terrahub configure -i demo_function -c build.phases.post_build.commands[0]='echo "BUILD: Running post_build step"'
193+
terrahub configure -i demo_function -c build.phases.post_build.commands[1]='echo $(stat -c %y "${THUB_BUILD_PATH}/index.js") > "$THUB_FUNCTION_TXT"'
194+
terrahub configure -i demo_function -c build.phases.post_build.finally[0]='echo "BUILD: post_build step successful"'
207195
```
208196

209197
Your output should be similar to the one below:
@@ -222,16 +210,15 @@ Your output should be similar to the one below:
222210
```
223211
Project: demo-terraform-automation-google
224212
└─ demo_storage_bucket_7b3c5d2c [path: ./demo_storage_bucket_7b3c5d2c]
225-
└─ demo_object_7b3c5d2c [path: ./demo_object_7b3c5d2c]
226-
└─ demo_function_7b3c5d2c [path: ./demo_function_7b3c5d2c]
213+
└─ demo_function_7b3c5d2c [path: ./demo_function_7b3c5d2c]
227214
```
228215

229216

230217
## Run TerraHub Automation
231218

232219
Run the following command in terminal:
233220
```shell
234-
terrahub build -i demo_object
221+
terrahub build -i demo_function
235222
terrahub run -a -y
236223
```
237224

demo_function/.terrahub.yml

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,28 @@ component:
33
mapping:
44
- .
55
dependsOn:
6-
- ../demo_object
6+
- ../demo_storage_bucket
77
template:
88
resource:
99
google_cloudfunctions_function:
1010
demo_function:
1111
name: 'demofunction${local.project["code"]}'
12+
depends_on:
13+
- google_storage_bucket_object.demo_object
1214
region: us-central1
1315
runtime: nodejs8
14-
description: 'My demo function ${data.terraform_remote_state.object.md5hash}'
16+
description: My demo function
1517
available_memory_mb: 128
1618
source_archive_bucket: '${data.terraform_remote_state.storage.thub_id}'
17-
source_archive_object: '${data.terraform_remote_state.object.output_name}'
19+
source_archive_object: '${google_storage_bucket_object.demo_object.name}'
1820
trigger_http: true
1921
timeout: 60
2022
entry_point: helloGET
23+
google_storage_bucket_object:
24+
demo_object:
25+
name: demo.zip
26+
bucket: '${data.terraform_remote_state.storage.thub_id}'
27+
source: ./demo.zip
2128
terraform:
2229
backend:
2330
local:
@@ -28,12 +35,45 @@ component:
2835
backend: local
2936
config:
3037
path: /tmp/.terrahub/local_backend/demo_storage_bucket/terraform.tfstate
31-
object:
32-
backend: local
33-
config:
34-
path: /tmp/.terrahub/local_backend/demo_object/terraform.tfstate
3538
output:
3639
id:
3740
value: '${google_cloudfunctions_function.demo_function.id}'
3841
trigger_url:
3942
value: '${google_cloudfunctions_function.demo_function.https_trigger_url}'
43+
build:
44+
env:
45+
variables:
46+
THUB_FUNCTION_ZIP: demo.zip
47+
THUB_BUILD_PATH: ..
48+
THUB_FUNCTION_TXT: demo.txt
49+
THUB_BUILD_OK: true
50+
phases:
51+
pre_build:
52+
commands:
53+
- 'echo "BUILD: Running pre_build step"'
54+
- 'if [ ! -e "$THUB_FUNCTION_TXT" ]; then touch "$THUB_FUNCTION_TXT"; fi'
55+
finally:
56+
- 'echo "BUILD: pre_build step successful"'
57+
build:
58+
commands:
59+
- 'echo "BUILD: Running build step"'
60+
- >-
61+
if [ "$(head -n 1 "$THUB_FUNCTION_TXT")" != "$(stat -c %y
62+
"${THUB_BUILD_PATH}/index.js")" ]; then zip -j ${THUB_FUNCTION_ZIP}
63+
${THUB_BUILD_PATH}/index.js; fi
64+
- >-
65+
if [ "$(head -n 1 "$THUB_FUNCTION_TXT")" != "$(stat -c %y
66+
"${THUB_BUILD_PATH}/index.js")" ]; then terrahub configure -i
67+
demo_function -c
68+
component.template.resource.google_storage_bucket_object.demo_object.name=$(date
69+
+%s).zip; fi
70+
finally:
71+
- 'echo "BUILD: build step successful"'
72+
post_build:
73+
commands:
74+
- 'echo "BUILD: Running post_build step"'
75+
- >-
76+
echo $(stat -c %y "${THUB_BUILD_PATH}/index.js") >
77+
"$THUB_FUNCTION_TXT"
78+
finally:
79+
- 'echo "BUILD: post_build step successful"'

demo_object/.terrahub.yml

Lines changed: 0 additions & 59 deletions
This file was deleted.

demo_storage_bucket/.terrahub.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ component:
88
demo_storage_bucket:
99
name: 'demo_storage_bucket_${local.project["code"]}'
1010
location: US
11-
project: terrahub-123456
11+
project: '${local.google_project_id}'
1212
output:
1313
id:
1414
value: '${google_storage_bucket.demo_storage_bucket.id}'

test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2019-03-01 21:33:02.852158600 +0100

0 commit comments

Comments
 (0)