Skip to content

Commit 42fe316

Browse files
committed
minor improvement
1 parent 4799574 commit 42fe316

File tree

2 files changed

+91
-19
lines changed

2 files changed

+91
-19
lines changed

README.md

Lines changed: 90 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Terraform Automation using Google Provider
1+
# Terraform Automation Demo using Google Cloud Provider
22

33
## Login to Google Cloud
44

@@ -12,7 +12,7 @@ gcloud auth login
1212

1313
## Setup Environment Variables (Will Be Used Later)
1414

15-
Manual Setup (set values in double quotes and run the following command in terminal):
15+
Manual Setup (set values in double quotes and run the following commands in terminal):
1616
```shell
1717
export GOOGLE_CLOUD_PROJECT="" ## e.g. terrahub-123456
1818
export GOOGLE_APPLICATION_CREDENTIALS="" ## e.g. ${HOME}/.config/gcloud/terraform.json
@@ -39,10 +39,30 @@ Run the following command in terminal:
3939
gcloud projects create ${GOOGLE_CLOUD_PROJECT} \
4040
--name="${PROJECT_NAME}" \
4141
--set-as-default
42+
```
43+
44+
Your output should be similar to the one below:
45+
```
46+
Create in progress for [https://cloudresourcemanager.googleapis.com/v1/projects/***].
47+
Waiting for [operations/***] to finish ... done.
48+
```
4249

50+
Next, run the following command in terminal:
51+
```shell
4352
gcloud beta billing projects link ${GOOGLE_CLOUD_PROJECT} \
4453
--billing-account="${BILLING_ID}"
54+
```
55+
56+
Your output should be similar to the one below:
57+
```
58+
billingAccountName: billingAccounts/***
59+
billingEnabled: true
60+
name: projects/***
61+
projectId: ***
62+
```
4563

64+
Finally, run the following command in terminal:
65+
```shell
4666
gcloud services enable cloudresourcemanager.googleapis.com
4767
gcloud services enable cloudbilling.googleapis.com
4868
gcloud services enable iam.googleapis.com
@@ -52,6 +72,7 @@ gcloud services enable storage-component.googleapis.com
5272

5373
Your output should be similar to the one below:
5474
```
75+
Operation "operations/***" finished successfully.
5576
```
5677

5778
## Create Google Cloud IAM Service Account & Key
@@ -60,13 +81,22 @@ Run the following command in terminal:
6081
```shell
6182
gcloud iam service-accounts create ${IAM_NAME} \
6283
--display-name="${IAM_DESC}"
84+
```
85+
86+
Your output should be similar to the one below:
87+
```
88+
Created service account [***].
89+
```
6390

91+
After that, run the following command in terminal:
92+
```shell
6493
gcloud iam service-accounts keys create ${GOOGLE_APPLICATION_CREDENTIALS} \
6594
--iam-account="${IAM_NAME}@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com"
6695
```
6796

6897
Your output should be similar to the one below:
6998
```
99+
Created key [***] of type [json] as [***] for [***@***.iam.gserviceaccount.com]
70100
```
71101

72102
## Add IAM Policy Binding to Google Cloud Project
@@ -80,6 +110,10 @@ gcloud projects add-iam-policy-binding ${GOOGLE_CLOUD_PROJECT} \
80110

81111
Your output should be similar to the one below:
82112
```
113+
Updated IAM policy for project [***].
114+
bindings:
115+
...
116+
version: 1
83117
```
84118

85119
## Create Terraform Configurations Using TerraHub
@@ -99,23 +133,35 @@ terrahub@0.0.1 (built: 2018-04-07T19:15:39.787Z)
99133
> NOTE: If you don't have TerraHub CLI, check out this
100134
[installation guide](https://www.npmjs.com/package/terrahub)
101135

102-
Run the following command in terminal:
136+
Run the following commands in terminal:
103137
```shell
104-
mkdir demo-terraform-automation-google
105-
cd demo-terraform-automation-google
106-
terrahub project -n demo-terraform-automation-google
138+
mkdir demo-terraform-automation-gcp
139+
cd demo-terraform-automation-gcp
140+
terrahub project -n demo-terraform-automation-gcp
107141
```
108142

109143
Your output should be similar to the one below:
110144
```
111145
✅ Project successfully initialized
112146
```
113147

114-
> NOTE: For this demo we have added "index.js" file which you have to copy in "demo-terraform-automation-google" dir
148+
## Copy Source Code for Google Function and Static Website
149+
150+
The source code of Google Function is stored in `index.js`:
151+
152+
```shell
153+
cat 'exports.helloGET = (req, res) => { res.send("Hello World!\n"); };' > index.js
154+
```
155+
156+
The source code of Static Website is cloned from another public repository:
115157

116-
> NOTE: For this demo we have run the following command in terminal
158+
```shell
117159
git clone https://github.com/TerraHubCorp/www.git \
118-
&& rm -rf ./www/.terrahub*
160+
&& rm -rf ./www/.terrahub*
161+
```
162+
163+
> NOTE: We are removing `.terrahub` folder (as shown above) because
164+
already included terraform configuration is not relevant for this demo
119165

120166
## Create TerraHub Components from Templates
121167

@@ -134,7 +180,7 @@ Your output should be similar to the one below:
134180

135181
## Update Project Config
136182

137-
Run the following command in terminal:
183+
Run the following commands in terminal:
138184
```shell
139185
terrahub configure -c terraform.version=0.11.11
140186
terrahub configure -c template.provider.google={}
@@ -149,7 +195,7 @@ Your output should be similar to the one below:
149195

150196
## Customize TerraHub Component for Storage Bucket
151197

152-
Run the following command in terminal:
198+
Run the following commands in terminal:
153199
```shell
154200
terrahub configure -i google_storage -c component.template.terraform.backend.local.path='/tmp/.terrahub/local_backend/google_storage/terraform.tfstate'
155201
terrahub configure -i google_storage -c component.template.resource.google_storage_bucket.google_storage.name="${STORAGE_BUCKET}"
@@ -166,7 +212,7 @@ Your output should be similar to the one below:
166212

167213
## Customize TerraHub Component for Google Cloud Function
168214

169-
Run the following command in terminal:
215+
Run the following commands in terminal:
170216
```shell
171217
terrahub configure -i google_function -c component.template.terraform.backend.local.path='/tmp/.terrahub/local_backend/google_function/terraform.tfstate'
172218
terrahub configure -i google_function -c component.template.data.terraform_remote_state.storage.backend='local'
@@ -219,7 +265,7 @@ Your output should be similar to the one below:
219265

220266
## Customize TerraHub Component for Google Cloud Static WebSite
221267

222-
Run the following command in terminal:
268+
Run the following commands in terminal:
223269
```shell
224270
terrahub configure -i google_static_website -c component.template.terraform.backend.local.path='/tmp/.terrahub/local_backend/google_static_website/terraform.tfstate'
225271
terrahub configure -i google_static_website -c component.template.resource.google_storage_bucket.google_static_website.name="${STORAGE_BUCKET}_website"
@@ -258,7 +304,7 @@ Your output should be similar to the one below:
258304

259305
## Customize TerraHub Component for IAM Member Object Viewer
260306

261-
Run the following command in terminal:
307+
Run the following commands in terminal:
262308
```shell
263309
terrahub configure -i iam_member_object_viewer -c component.template.terraform.backend.local.path='/tmp/.terrahub/local_backend/iam_member_object_viewer/terraform.tfstate'
264310
terrahub configure -i iam_member_object_viewer -c component.template.data.terraform_remote_state.storage.backend='local'
@@ -283,31 +329,57 @@ terrahub graph
283329

284330
Your output should be similar to the one below:
285331
```
286-
Project: demo-terraform-automation-google
332+
Project: demo-terraform-automation-gcp
287333
├─ google_storage [path: ./google_storage]
288334
│ └─ google_function [path: ./google_function]
289335
└─ google_static_website [path: ./www/.terrahub/google_static_website]
290336
└─ iam_member_object_viewer [path: ./www/.terrahub/iam_member_object_viewer]
291337
```
292338

293-
294339
## Run TerraHub Automation
295340

341+
### Prepare Storage Resources
342+
296343
Run the following command in terminal:
297344
```shell
298345
terrahub run -a -y -i google_storage,google_static_website
346+
```
347+
348+
Your output should be similar to the one below:
349+
```
350+
```
351+
352+
### Prepare Source Code for Deployment
353+
354+
Run the following command in terminal:
355+
356+
```shell
299357
terrahub build -i google_function,google_static_website
300-
terrahub run -a -y
301358
```
302359

303360
Your output should be similar to the one below:
304361
```
305362
```
306363

307-
## Run Test Command
364+
### Run TerraHub Automation
308365

309366
Run the following command in terminal:
367+
```shell
368+
terrahub run -a -y
369+
```
370+
371+
Your output should be similar to the one below:
372+
```
373+
```
374+
375+
## Testing Deployed Cloud Resources
376+
377+
Check if backend was deployed successfully. Run the following command in terminal:
310378
```
311379
curl https://us-central1-terrahub-123456.cloudfunctions.net/demofunctionxxxxxxxx
380+
```
381+
382+
Check if frontend was deployed successfully. Run the following command in terminal:
383+
```
312384
curl https://${STORAGE_BUCKET}_website.storage.googleapis.com/index.html
313385
```

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
exports.helloGET = (req, res) => {
2-
res.send("Hello World!\n");
2+
res.send("Hello World!\n");
33
};

0 commit comments

Comments
 (0)