You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+238-1Lines changed: 238 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ touch variables.tf
22
22
cd
23
23
```
24
24
25
-
Add the following to the each _variables.tf_ file, and fill in the GCP Project ID:
25
+
Add the following to the each _variables.tf_ file, and fill in the _GCP Project ID_:
26
26
```
27
27
variable "region" {
28
28
default = "us-central1"
@@ -109,3 +109,240 @@ EOT
109
109
allow_stopping_for_update = true
110
110
}
111
111
```
112
+
To import the first instance, use the following command, using the Instance ID for _tf-instance-1_ you copied down earlier.
113
+
```
114
+
terraform import module.instances.google_compute_instance.tf-instance-1 <Instance ID - 1>
115
+
```
116
+
To import the second instance, use the following command, using the Instance ID for _tf-instance-2_ you copied down earlier.
117
+
```
118
+
terraform import module.instances.google_compute_instance.tf-instance-2 <Instance ID - 2>
119
+
```
120
+
The two instances have now been imported into your terraform configuration. You can now run the commands to update the state of Terraform. Type _yes_ at the dialogue after you run the apply command to accept the state changes.
121
+
```
122
+
terraform plan
123
+
terraform apply
124
+
```
125
+
**TASK 2: Configure a remote backend** <br/>
126
+
Add the following code to the _modules/storage/storage.tf_ file, and fill in the _Bucket Name_:
Run the following commands to initialize the module and create the storage bucket resource. Type _yes_ at the dialogue after you run the apply command to accept the state changes.
142
+
```
143
+
terraform init
144
+
terraform apply
145
+
```
146
+
Next, update the _main.tf_ file so that the terraform block looks like the following. Fill in your _GCP Project ID_ for the bucket argument definition.
147
+
```
148
+
terraform {
149
+
backend "gcs" {
150
+
bucket = "<FILL IN PROJECT ID>"
151
+
prefix = "terraform/state"
152
+
}
153
+
required_providers {
154
+
google = {
155
+
source = "hashicorp/google"
156
+
version = "3.55.0"
157
+
}
158
+
}
159
+
}
160
+
```
161
+
Run the following to initialize the remote backend. Type _yes_ at the prompt.
162
+
```
163
+
terraform init
164
+
```
165
+
**TASK 3: Modify and update infrastructure** <br/>
166
+
Navigate to _modules/instances/instance.tf_. Replace the entire contents of the file with the following, and fill in your _Instance 3 ID_:
resource "google_compute_instance" "<FILL IN INSTANCE 3 NAME>" {
203
+
name = "<FILL IN INSTANCE 3 NAME>"
204
+
machine_type = "n1-standard-2"
205
+
zone = "us-central1-a"
206
+
allow_stopping_for_update = true
207
+
208
+
boot_disk {
209
+
initialize_params {
210
+
image = "debian-cloud/debian-10"
211
+
}
212
+
}
213
+
214
+
network_interface {
215
+
network = "default"
216
+
}
217
+
}
218
+
```
219
+
Run the following commands to initialize the module and create/update the instance resources. Type _yes_ at the dialogue after you run the apply command to accept the state changes.
220
+
```
221
+
terraform init
222
+
terraform apply
223
+
```
224
+
**TASK 4: Taint and destroy resources** <br/>
225
+
Taint the _tf-instance-3_ resource by running the following command, and fill in your _Instance 3 ID_:
226
+
```
227
+
terraform taint module.instances.google_compute_instance.<FILL IN INSTANCE 3 NAME>
228
+
```
229
+
Run the following commands to apply the changes:
230
+
```
231
+
terraform init
232
+
terraform apply
233
+
```
234
+
Remove the _tf-instance-3_ resource from the _instances.tf_ file. Delete the following code chunk from the file.
235
+
```
236
+
resource "google_compute_instance" "<FILL IN INSTANCE 3 NAME>" {
237
+
name = "<FILL IN INSTANCE 3 NAME>"
238
+
machine_type = "n1-standard-2"
239
+
zone = "us-central1-a"
240
+
allow_stopping_for_update = true
241
+
242
+
boot_disk {
243
+
initialize_params {
244
+
image = "debian-cloud/debian-10"
245
+
}
246
+
}
247
+
248
+
network_interface {
249
+
network = "default"
250
+
}
251
+
}
252
+
```
253
+
Run the following commands to apply the changes. Type _yes_ at the prompt.
254
+
```
255
+
terraform apply
256
+
```
257
+
**TASK 5: Use a module from the Registry** <br/>
258
+
Copy and paste the following to the end of _main.tf_ file, fill in _Version Number_ and _Network Name_ instructed in the challenge:
0 commit comments