Skip to content

Commit f8f83d9

Browse files
rootroot
authored andcommitted
add components for google_static_website
1 parent 541713b commit f8f83d9

File tree

6 files changed

+53
-174
lines changed

6 files changed

+53
-174
lines changed

README.md

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,20 @@ Your output should be similar to the one below:
110110
✅ Project successfully initialized
111111
```
112112

113+
> NOTE: For this demo we have added "index.js" file which you have to copy in "demo-terraform-automation-google" dir
114+
115+
> NOTE: For this demo we have run the following command in terminal
116+
git clone https://github.com/TerraHubCorp/www.git \
117+
&& rm -rf ./www/.terrahub*
118+
113119
## Create TerraHub Components from Templates
114120

115121
Run the following command in terminal:
116122
```shell
117123
terrahub component -t google_storage_bucket -n google_storage \
118124
&& terrahub component -t google_cloudfunctions_function -n google_function -o ../google_storage \
119-
&& terrahub component -t google_storage_bucket -n google_static_website
125+
&& terrahub component -t google_storage_bucket -n google_static_website -d ./www/.terrahub \
126+
&& terrahub component -t google_storage_bucket_iam_member -n iam_member_object_viewer -d ./www/.terrahub -o ../google_static_website
120127
```
121128

122129
Your output should be similar to the one below:
@@ -213,7 +220,6 @@ Your output should be similar to the one below:
213220

214221
Run the following command in terminal:
215222
```shell
216-
git clone https://github.com/TerraHubCorp/www.git
217223
terrahub configure -i google_static_website -c component.template.terraform.backend.local.path='/tmp/.terrahub/local_backend/google_static_website/terraform.tfstate'
218224
terrahub configure -i google_static_website -c component.template.resource.google_storage_bucket.google_static_website.name="${GOOGLE_STORAGE_BUCKET}_website"
219225
terrahub configure -i google_static_website -c component.template.resource.google_storage_bucket.google_static_website.location='US'
@@ -222,6 +228,44 @@ terrahub configure -i google_static_website -c component.template.resource.googl
222228
terrahub configure -i google_static_website -c component.template.resource.google_storage_bucket.google_static_website.website.main_page_suffix='index.html'
223229
terrahub configure -i google_static_website -c component.template.resource.google_storage_bucket.google_static_website.website.not_found_page='/404.html'
224230
terrahub configure -i google_static_website -c component.template.variable -D -y
231+
terrahub configure -i google_static_website -c build.env.variables.THUB_ENV='dev'
232+
terrahub configure -i google_static_website -c build.env.variables.THUB_INDEX_FILE='www.txt'
233+
terrahub configure -i google_static_website -c build.env.variables.THUB_S3_PATH="gs://${GOOGLE_STORAGE_BUCKET}_website"
234+
terrahub configure -i google_static_website -c build.env.variables.THUB_ROBOTS='../../robots.dev.txt'
235+
terrahub configure -i google_static_website -c build.env.variables.THUB_BUILD_PATH='../../build'
236+
terrahub configure -i google_static_website -c build.env.variables.THUB_SOURCE_PATH='../../assets ../../static/fonts ../../static/img ../../views'
237+
terrahub configure -i google_static_website -c build.env.variables.THUB_BUILD_OK='false'
238+
terrahub configure -i google_static_website -c build.env.variables.THUB_MAX_AGE='600'
239+
terrahub configure -i google_static_website -c build.phases.pre_build.commands[0]='echo "BUILD: Running pre_build step"'
240+
terrahub configure -i google_static_website -c build.phases.pre_build.commands[1]='./scripts/download.sh $THUB_INDEX_FILE $THUB_S3_PATH/$THUB_INDEX_FILE'
241+
terrahub configure -i google_static_website -c build.phases.pre_build.commands[2]='./scripts/compare.sh $THUB_INDEX_FILE $THUB_SOURCE_PATH'
242+
terrahub configure -i google_static_website -c build.phases.pre_build.finally[0]='echo "BUILD: pre_build step successful"'
243+
terrahub configure -i google_static_website -c build.phases.build.commands[0]='echo "BUILD: Running build step"'
244+
terrahub configure -i google_static_website -c build.phases.build.commands[1]='../../bin/compile.sh'
245+
terrahub configure -i google_static_website -c build.phases.build.finally[0]='echo "BUILD: build step successful"'
246+
terrahub configure -i google_static_website -c build.phases.post_build.commands[0]='echo "BUILD: Running post_build step"'
247+
terrahub configure -i google_static_website -c build.phases.post_build.commands[1]='./scripts/shasum.sh $THUB_BUILD_PATH/$THUB_INDEX_FILE'
248+
terrahub configure -i google_static_website -c build.phases.post_build.commands[2]='./scripts/upload.sh $THUB_BUILD_PATH $THUB_S3_PATH --cache-control max-age=$THUB_MAX_AGE'
249+
terrahub configure -i google_static_website -c build.phases.post_build.commands[3]='rm -f .terrahub_build.env $THUB_INDEX_FILE'
250+
terrahub configure -i google_static_website -c build.phases.post_build.finally[0]='echo "BUILD: post_build step successful"'
251+
```
252+
253+
Your output should be similar to the one below:
254+
```
255+
✅ Done
256+
```
257+
258+
## Customize TerraHub Component for IAM Member Object Viewer
259+
260+
Run the following command in terminal:
261+
```shell
262+
terrahub configure -i iam_member_object_viewer -c component.template.terraform.backend.local.path='/tmp/.terrahub/local_backend/iam_member_object_viewer/terraform.tfstate'
263+
terrahub configure -i iam_member_object_viewer -c component.template.data.terraform_remote_state.storage.backend='local'
264+
terrahub configure -i iam_member_object_viewer -c component.template.data.terraform_remote_state.storage.config.path='/tmp/.terrahub/local_backend/google_static_website/terraform.tfstate'
265+
terrahub configure -i iam_member_object_viewer -c component.template.resource.google_storage_bucket_iam_member.iam_member_object_viewer.bucket="${GOOGLE_STORAGE_BUCKET}_website"
266+
terrahub configure -i iam_member_object_viewer -c component.template.resource.google_storage_bucket_iam_member.iam_member_object_viewer.role="roles/storage.objectViewer"
267+
terrahub configure -i iam_member_object_viewer -c component.template.resource.google_storage_bucket_iam_member.iam_member_object_viewer.member="allUsers"
268+
terrahub configure -i iam_member_object_viewer -c component.template.variable -D -y
225269
```
226270

227271
Your output should be similar to the one below:
@@ -239,17 +283,19 @@ terrahub graph
239283
Your output should be similar to the one below:
240284
```
241285
Project: demo-terraform-automation-google
242-
└─ google_storage [path: ./google_storage]
243-
└─ google_function [path: ./google_function]
286+
├─ google_storage [path: ./google_storage]
287+
│ └─ google_function [path: ./google_function]
288+
└─ google_static_website [path: ./www/.terrahub/google_static_website]
289+
└─ iam_member_object_viewer [path: ./www/.terrahub/iam_member_object_viewer]
244290
```
245291

246292

247293
## Run TerraHub Automation
248294

249295
Run the following command in terminal:
250296
```shell
251-
terrahub run -a -y -i google_storage
252-
terrahub build -i google_function
297+
terrahub run -a -y -i google_storage,google_static_website
298+
terrahub build -i google_function,google_static_website
253299
terrahub run -a -y
254300
```
255301

@@ -262,4 +308,5 @@ Your output should be similar to the one below:
262308
Run the following command in terminal:
263309
```
264310
curl https://us-central1-terrahub-123456.cloudfunctions.net/demofunctionxxxxxxxx
311+
curl https://${GOOGLE_STORAGE_BUCKET}_website.storage.googleapis.com/index.html
265312
```

google_static_website/.terrahub.yml

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

google_static_website/scripts/compare.sh

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

google_static_website/scripts/download.sh

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

google_static_website/scripts/shasum.sh

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

google_static_website/scripts/upload.sh

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

0 commit comments

Comments
 (0)