Skip to content

Commit a7c7fc6

Browse files
authored
Merge pull request #15 from TerraHubCorp/dev
Transform HCL into TerraHub config with template
2 parents 6b6cebd + 4799574 commit a7c7fc6

File tree

1 file changed

+74
-5
lines changed

1 file changed

+74
-5
lines changed

README.md

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ gcloud services enable cloudresourcemanager.googleapis.com
4747
gcloud services enable cloudbilling.googleapis.com
4848
gcloud services enable iam.googleapis.com
4949
gcloud services enable cloudfunctions.googleapis.com
50+
gcloud services enable storage-component.googleapis.com
5051
```
5152

5253
Your output should be similar to the one below:
@@ -110,12 +111,20 @@ Your output should be similar to the one below:
110111
✅ Project successfully initialized
111112
```
112113

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

115122
Run the following command in terminal:
116123
```shell
117124
terrahub component -t google_storage_bucket -n google_storage \
118-
&& terrahub component -t google_cloudfunctions_function -n google_function -o ../google_storage
125+
&& terrahub component -t google_cloudfunctions_function -n google_function -o ../google_storage \
126+
&& terrahub component -t google_storage_bucket -n google_static_website -d ./www/.terrahub \
127+
&& terrahub component -t google_storage_bucket_iam_member -n iam_member_object_viewer -d ./www/.terrahub -o ../google_static_website
119128
```
120129

121130
Your output should be similar to the one below:
@@ -208,6 +217,63 @@ Your output should be similar to the one below:
208217
✅ Done
209218
```
210219

220+
## Customize TerraHub Component for Google Cloud Static WebSite
221+
222+
Run the following command in terminal:
223+
```shell
224+
terrahub configure -i google_static_website -c component.template.terraform.backend.local.path='/tmp/.terrahub/local_backend/google_static_website/terraform.tfstate'
225+
terrahub configure -i google_static_website -c component.template.resource.google_storage_bucket.google_static_website.name="${STORAGE_BUCKET}_website"
226+
terrahub configure -i google_static_website -c component.template.resource.google_storage_bucket.google_static_website.location='US'
227+
terrahub configure -i google_static_website -c component.template.resource.google_storage_bucket.google_static_website.force_destroy='true'
228+
terrahub configure -i google_static_website -c component.template.resource.google_storage_bucket.google_static_website.project='${local.google_project_id}'
229+
terrahub configure -i google_static_website -c component.template.resource.google_storage_bucket.google_static_website.website.main_page_suffix='index.html'
230+
terrahub configure -i google_static_website -c component.template.resource.google_storage_bucket.google_static_website.website.not_found_page='/404.html'
231+
terrahub configure -i google_static_website -c component.template.variable -D -y
232+
terrahub configure -i google_static_website -c build.env.variables.THUB_ENV='dev'
233+
terrahub configure -i google_static_website -c build.env.variables.THUB_INDEX_FILE='www.txt'
234+
terrahub configure -i google_static_website -c build.env.variables.THUB_S3_PATH="gs://${STORAGE_BUCKET}_website"
235+
terrahub configure -i google_static_website -c build.env.variables.THUB_ROBOTS='../../robots.dev.txt'
236+
terrahub configure -i google_static_website -c build.env.variables.THUB_BUILD_PATH='../../build'
237+
terrahub configure -i google_static_website -c build.env.variables.THUB_SOURCE_PATH='../../assets ../../static/fonts ../../static/img ../../views'
238+
terrahub configure -i google_static_website -c build.env.variables.THUB_BUILD_OK='false'
239+
terrahub configure -i google_static_website -c build.env.variables.THUB_MAX_AGE='600'
240+
terrahub configure -i google_static_website -c build.phases.pre_build.commands[0]='echo "BUILD: Running pre_build step"'
241+
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'
242+
terrahub configure -i google_static_website -c build.phases.pre_build.commands[2]='./scripts/compare.sh $THUB_INDEX_FILE $THUB_SOURCE_PATH'
243+
terrahub configure -i google_static_website -c build.phases.pre_build.finally[0]='echo "BUILD: pre_build step successful"'
244+
terrahub configure -i google_static_website -c build.phases.build.commands[0]='echo "BUILD: Running build step"'
245+
terrahub configure -i google_static_website -c build.phases.build.commands[1]='../../bin/compile.sh'
246+
terrahub configure -i google_static_website -c build.phases.build.finally[0]='echo "BUILD: build step successful"'
247+
terrahub configure -i google_static_website -c build.phases.post_build.commands[0]='echo "BUILD: Running post_build step"'
248+
terrahub configure -i google_static_website -c build.phases.post_build.commands[1]='./scripts/shasum.sh $THUB_BUILD_PATH/$THUB_INDEX_FILE'
249+
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'
250+
terrahub configure -i google_static_website -c build.phases.post_build.commands[3]='rm -f .terrahub_build.env $THUB_INDEX_FILE'
251+
terrahub configure -i google_static_website -c build.phases.post_build.finally[0]='echo "BUILD: post_build step successful"'
252+
```
253+
254+
Your output should be similar to the one below:
255+
```
256+
✅ Done
257+
```
258+
259+
## Customize TerraHub Component for IAM Member Object Viewer
260+
261+
Run the following command in terminal:
262+
```shell
263+
terrahub configure -i iam_member_object_viewer -c component.template.terraform.backend.local.path='/tmp/.terrahub/local_backend/iam_member_object_viewer/terraform.tfstate'
264+
terrahub configure -i iam_member_object_viewer -c component.template.data.terraform_remote_state.storage.backend='local'
265+
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'
266+
terrahub configure -i iam_member_object_viewer -c component.template.resource.google_storage_bucket_iam_member.iam_member_object_viewer.bucket="${STORAGE_BUCKET}_website"
267+
terrahub configure -i iam_member_object_viewer -c component.template.resource.google_storage_bucket_iam_member.iam_member_object_viewer.role="roles/storage.objectViewer"
268+
terrahub configure -i iam_member_object_viewer -c component.template.resource.google_storage_bucket_iam_member.iam_member_object_viewer.member="allUsers"
269+
terrahub configure -i iam_member_object_viewer -c component.template.variable -D -y
270+
```
271+
272+
Your output should be similar to the one below:
273+
```
274+
✅ Done
275+
```
276+
211277
## Visualize TerraHub Components
212278

213279
Run the following command in terminal:
@@ -218,17 +284,19 @@ terrahub graph
218284
Your output should be similar to the one below:
219285
```
220286
Project: demo-terraform-automation-google
221-
└─ google_storage [path: ./google_storage]
222-
└─ google_function [path: ./google_function]
287+
├─ google_storage [path: ./google_storage]
288+
│ └─ google_function [path: ./google_function]
289+
└─ google_static_website [path: ./www/.terrahub/google_static_website]
290+
└─ iam_member_object_viewer [path: ./www/.terrahub/iam_member_object_viewer]
223291
```
224292

225293

226294
## Run TerraHub Automation
227295

228296
Run the following command in terminal:
229297
```shell
230-
terrahub run -a -y -i google_storage
231-
terrahub build -i google_function
298+
terrahub run -a -y -i google_storage,google_static_website
299+
terrahub build -i google_function,google_static_website
232300
terrahub run -a -y
233301
```
234302

@@ -241,4 +309,5 @@ Your output should be similar to the one below:
241309
Run the following command in terminal:
242310
```
243311
curl https://us-central1-terrahub-123456.cloudfunctions.net/demofunctionxxxxxxxx
312+
curl https://${STORAGE_BUCKET}_website.storage.googleapis.com/index.html
244313
```

0 commit comments

Comments
 (0)