Skip to content

Commit e1871ef

Browse files
committed
improve documentation
1 parent e51259f commit e1871ef

File tree

1 file changed

+124
-6
lines changed

1 file changed

+124
-6
lines changed

README.md

Lines changed: 124 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
11
# Terraform Demo using Google provider
22

33
## Login to Google Cloud
4+
5+
Run the following command in terminal:
46
```shell
57
gcloud auth login
68
```
79

8-
## Get Google Cloud values for ORG_ID and BILLING_ID
10+
> NOTE: If you don't have Google Cloud CLI, check out
11+
[installation guide](https://cloud.google.com/sdk/install)
12+
13+
## Get Values from Your Google Cloud Account
14+
15+
Run the following command in terminal:
916
```shell
1017
gcloud organizations list
18+
```
19+
20+
Your output should be similar to the one below:
21+
```
22+
DISPLAY_NAME ID DIRECTORY_CUSTOMER_ID
23+
mydomain.com 123456789012 a1b2c3d4e
24+
```
25+
26+
Run the following command in terminal:
27+
```shell
1128
gcloud beta billing accounts list
1229
```
1330

14-
## Setup Google Cloud ENV Variables
31+
Your output should be similar to the one below:
32+
```
33+
ACCOUNT_ID NAME OPEN MASTER_ACCOUNT_ID
34+
123456-ABCDEF-ZYXWVU My Billing Account True
35+
```
36+
37+
## Setup Environment Variables (Will Be Used Later)
38+
39+
Manual Setup (set values in double quotes and run the following command in terminal):
1540
```shell
1641
export GOOGLE_CLOUD_PROJECT="" ## e.g. terrahub-123456
1742
export GOOGLE_APPLICATION_CREDENTIALS="" ## e.g. ${HOME}/.config/gcloud/terraform.json
@@ -22,7 +47,18 @@ export IAM_NAME="" ## e.g. terraform
2247
export IAM_DESC="" ## e.g. terraform service account
2348
```
2449

50+
Automated Setup (run the following command in terminal):
51+
```shell
52+
export ORG_ID="$(gcloud organizations list --format=json | jq '.[0].name[14:]')"
53+
export BILLING_ID="$(gcloud beta billing accounts list --format=json | jq '.[0].name[16:]')"
54+
```
55+
56+
> NOTE: If you don't have JQ CLI, check out
57+
[installation guide](https://stedolan.github.io/jq/download/)
58+
2559
## Create Google Cloud Project & Billing
60+
61+
Run the following command in terminal:
2662
```shell
2763
gcloud projects create ${GOOGLE_CLOUD_PROJECT} \
2864
--name="${PROJECT_NAME}" \
@@ -40,7 +76,13 @@ gcloud beta billing projects link ${GOOGLE_CLOUD_PROJECT} \
4076
--billing-account="${BILLING_ID}"
4177
```
4278

79+
Your output should be similar to the one below:
80+
```
81+
```
82+
4383
## Create Google Cloud IAM Service Account & Key
84+
85+
Run the following command in terminal:
4486
```shell
4587
gcloud iam service-accounts create ${IAM_NAME} \
4688
--display-name="${IAM_DESC}"
@@ -49,14 +91,26 @@ gcloud iam service-accounts keys create ${GOOGLE_APPLICATION_CREDENTIALS} \
4991
--iam-account="${IAM_NAME}@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com"
5092
```
5193

94+
Your output should be similar to the one below:
95+
```
96+
```
97+
5298
## Add IAM Policy Binding to Google Cloud Project
99+
100+
Run the following command in terminal:
53101
```shell
54102
gcloud projects add-iam-policy-binding ${GOOGLE_CLOUD_PROJECT} \
55103
--member="serviceAccount:${IAM_NAME}@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com" \
56104
--role="roles/editor"
57105
```
58106

107+
Your output should be similar to the one below:
108+
```
109+
```
110+
59111
## Add IAM Policy Binding to Google Cloud Organization
112+
113+
Run the following command in terminal:
60114
```shell
61115
gcloud organizations add-iam-policy-binding ${ORG_ID} \
62116
--member="serviceAccount:${IAM_NAME}@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com" \
@@ -67,14 +121,42 @@ gcloud organizations add-iam-policy-binding ${ORG_ID} \
67121
--role="roles/billing.user"
68122
```
69123

70-
## Create TerraHub Project
124+
Your output should be similar to the one below:
125+
```
126+
```
127+
128+
## Create Terraform Configurations Using TerraHub
129+
130+
Run the following commands in terminal:
131+
```shell
132+
terrahub --help | head -3
133+
```
134+
135+
Your output should be similar to the one below:
136+
```
137+
Usage: terrahub [command] [options]
138+
139+
terrahub@0.0.28 (built: 2018-10-11T12:33:57.775Z)
140+
```
141+
142+
> NOTE: If you don't have TerraHub CLI, check out
143+
[installation guide](https://www.npmjs.com/package/terrahub)
144+
145+
Run the following command in terminal:
71146
```shell
72147
mkdir demo-terraform-google
73148
cd demo-terraform-google
74149
terrahub project -n demo-terraform-google
75150
```
76151

77-
## Create TerraHub Component
152+
Your output should be similar to the one below:
153+
```
154+
✅ Project successfully initialized
155+
```
156+
157+
## Create TerraHub Components
158+
159+
Run the following command in terminal:
78160
```shell
79161
terrahub component -t google_project -n project
80162
terrahub component -t google_service_account -n service_account -o ../project
@@ -84,14 +166,50 @@ terrahub component -t google_project_iam_binding -n project_iam_policy_binding_s
84166
terrahub component -t google_project_iam_binding -n project_iam_policy_binding_compute_admin -o ../project_iam_member
85167
```
86168

87-
## Update TerraHub Component Config
169+
Your output should be similar to the one below:
170+
```
171+
✅ Done
172+
```
173+
174+
## Visualize TerraHub Components
175+
176+
Run the following command in terminal:
177+
```shell
178+
terrahub graph
179+
```
180+
181+
Your output should be similar to the one below:
182+
```
183+
Project: demo-terraform-google
184+
└─ project [path: ./project]
185+
├─ project_iam_member [path: ./project_iam_member]
186+
│ ├─ project_iam_binding_compute_admin [path: ./project_iam_binding_compute_admin]
187+
│ └─ project_iam_binding_storage_admin [path: ./project_iam_binding_storage_admin]
188+
└─ service_account [path: ./service_account]
189+
└─ service_account_key [path: ./service_account_key]
190+
```
191+
192+
## Update Project Config
193+
194+
Run the following command in terminal:
88195
```shell
89196
terrahub configure -c terraform.var.google_org_id="${ORG_ID}"
90197
terrahub configure -c terraform.var.google_billing_account="${BILLING_ID}"
91198
terrahub configure -c terraform.var.google_project_id="${GOOGLE_CLOUD_PROJECT}"
92199
```
93200

94-
## Execute TerraHub Component
201+
Your output should be similar to the one below:
202+
```
203+
✅ Done
204+
```
205+
206+
## Run TerraHub Automation
207+
208+
Run the following command in terminal:
95209
```shell
96210
terrahub run -a -y
97211
```
212+
213+
Your output should be similar to the one below:
214+
```
215+
```

0 commit comments

Comments
 (0)