1
1
# Terraform Demo using Google provider
2
2
3
3
## Login to Google Cloud
4
+
5
+ Run the following command in terminal:
4
6
``` shell
5
7
gcloud auth login
6
8
```
7
9
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:
9
16
``` shell
10
17
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
11
28
gcloud beta billing accounts list
12
29
```
13
30
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):
15
40
``` shell
16
41
export GOOGLE_CLOUD_PROJECT=" " # # e.g. terrahub-123456
17
42
export GOOGLE_APPLICATION_CREDENTIALS=" " # # e.g. ${HOME}/.config/gcloud/terraform.json
@@ -22,7 +47,18 @@ export IAM_NAME="" ## e.g. terraform
22
47
export IAM_DESC=" " # # e.g. terraform service account
23
48
```
24
49
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
+
25
59
## Create Google Cloud Project & Billing
60
+
61
+ Run the following command in terminal:
26
62
``` shell
27
63
gcloud projects create ${GOOGLE_CLOUD_PROJECT} \
28
64
--name=" ${PROJECT_NAME} " \
@@ -40,7 +76,13 @@ gcloud beta billing projects link ${GOOGLE_CLOUD_PROJECT} \
40
76
--billing-account=" ${BILLING_ID} "
41
77
```
42
78
79
+ Your output should be similar to the one below:
80
+ ```
81
+ ```
82
+
43
83
## Create Google Cloud IAM Service Account & Key
84
+
85
+ Run the following command in terminal:
44
86
``` shell
45
87
gcloud iam service-accounts create ${IAM_NAME} \
46
88
--display-name=" ${IAM_DESC} "
@@ -49,14 +91,26 @@ gcloud iam service-accounts keys create ${GOOGLE_APPLICATION_CREDENTIALS} \
49
91
--iam-account=" ${IAM_NAME} @${GOOGLE_CLOUD_PROJECT} .iam.gserviceaccount.com"
50
92
```
51
93
94
+ Your output should be similar to the one below:
95
+ ```
96
+ ```
97
+
52
98
## Add IAM Policy Binding to Google Cloud Project
99
+
100
+ Run the following command in terminal:
53
101
``` shell
54
102
gcloud projects add-iam-policy-binding ${GOOGLE_CLOUD_PROJECT} \
55
103
--member=" serviceAccount:${IAM_NAME} @${GOOGLE_CLOUD_PROJECT} .iam.gserviceaccount.com" \
56
104
--role=" roles/editor"
57
105
```
58
106
107
+ Your output should be similar to the one below:
108
+ ```
109
+ ```
110
+
59
111
## Add IAM Policy Binding to Google Cloud Organization
112
+
113
+ Run the following command in terminal:
60
114
``` shell
61
115
gcloud organizations add-iam-policy-binding ${ORG_ID} \
62
116
--member=" serviceAccount:${IAM_NAME} @${GOOGLE_CLOUD_PROJECT} .iam.gserviceaccount.com" \
@@ -67,14 +121,42 @@ gcloud organizations add-iam-policy-binding ${ORG_ID} \
67
121
--role=" roles/billing.user"
68
122
```
69
123
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:
71
146
``` shell
72
147
mkdir demo-terraform-google
73
148
cd demo-terraform-google
74
149
terrahub project -n demo-terraform-google
75
150
```
76
151
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:
78
160
``` shell
79
161
terrahub component -t google_project -n project
80
162
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
84
166
terrahub component -t google_project_iam_binding -n project_iam_policy_binding_compute_admin -o ../project_iam_member
85
167
```
86
168
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:
88
195
``` shell
89
196
terrahub configure -c terraform.var.google_org_id=" ${ORG_ID} "
90
197
terrahub configure -c terraform.var.google_billing_account=" ${BILLING_ID} "
91
198
terrahub configure -c terraform.var.google_project_id=" ${GOOGLE_CLOUD_PROJECT} "
92
199
```
93
200
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:
95
209
``` shell
96
210
terrahub run -a -y
97
211
```
212
+
213
+ Your output should be similar to the one below:
214
+ ```
215
+ ```
0 commit comments