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: terraform_fundmentals/11-meta-arguments.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ So far, we've already used arguments to configure your resources. These argument
12
12
13
13
We are going to reuse the configuration in the `azure` directory from the exercises `02-basic-configuration` and `03-virtual_machine`. If you don't have those configurations, they are in the appendix of this lab.
14
14
15
-
Add a count argument to the Azure Virtual Machine resource in `main.tf` with a value of 2. Also adjust the value of `name` to incrementally add a number to the end of each instances name:
15
+
Add a count argument to the Azure Virtual Machine resource in `main.tf` with a value of 2. Also adjust the value of `name` to incrementally add a number to the end of each instances name:
## Task 2: Modify the rest of the configuration to support multiple instances
64
64
65
-
### Step 8.2.1
65
+
### Step 2.1
66
66
67
67
If you run `terraform apply` now, you'll get an error. Since we added _count_ to the azure_virtual_machine.training resource, it now refers to multiple resources. Because of this, values like our public_dns output no longer refer to the "public dns" of a single resource. We need to tell terraform which resource we're referring to.
68
68
@@ -74,9 +74,9 @@ output "public_dns" {
74
74
}
75
75
```
76
76
77
-
The syntax `azurerm_public_ip.training[*]...` refers to all of the instances, so this will output a list of all dns entries.
77
+
The syntax `azurerm_public_ip.training[*]...` refers to all of the instances, so this will output a list of all dns entries.
78
78
79
-
### Step 8.2.2
79
+
### Step 2.2
80
80
81
81
Run `terraform apply` to add the new instance. You will notice that because we changed the name of the Azure Virtual Mahine, that there will be a forced replacement of our previous virutal machine.
82
82
@@ -92,7 +92,7 @@ Plan: 2 to add, 0 to change, 1 to destroy.
92
92
93
93
## Task 3: Add variable interpolation to the count argument
94
94
95
-
### Step 8.3.1
95
+
### Step 3.1
96
96
97
97
Update `variables.tf` to add a new variable definition, and use it:
98
98
@@ -130,7 +130,7 @@ Remember to also add the variable declaration to your `terraform.tfvars` accordi
130
130
num_vms = 2
131
131
```
132
132
133
-
### Step 8.3.2
133
+
### Step 3.2
134
134
135
135
Run `terraform apply` in the terraform directory. No changes should be detected as the _values_ have not changed:
In this lab, you will explore how Terraform is authenticating to Azure.
6
+
7
+
- Task 1: View the current environment variables
8
+
9
+
## Task 1: View the current environment variables
10
+
11
+
From the terminal of you lab environment, run the following command to view the current environment variables:
12
+
13
+
```bash
14
+
env | grep ARM
15
+
```
16
+
17
+
You should see environment variables for the Azure subscription ID, tenant ID, client ID, and client secret.
18
+
19
+
From the cloud credentials tab, you can confirm that the values line up to what was provisioned for you.
20
+
21
+
## Bonus Task: Override the environment variables
22
+
23
+
You can also set the Azure authentication values directly in the provider block. Although this isn't recommended, it can be useful for testing. Add the necessary arguments in the `azurerm` provider block and use input variables to set the values.
Copy file name to clipboardExpand all lines: terraform_fundmentals/15-reading_state.md
+5-9Lines changed: 5 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Lab 12: State
1
+
# Lab: State
2
2
3
3
Duration: 10 minutes
4
4
@@ -7,15 +7,11 @@ This lab demonstrates how to read state from another Terraform project. It uses
7
7
- Task 1: Create a Terraform configuration that defines an output
8
8
- Task 2: Read an output value from that project's state
9
9
10
-
## Prerequisites
11
-
12
-
This lab only requires a copy of [Terraform](https://www.terraform.io/downloads.html). It doesn't require any cloud provider credentials.
13
-
14
10
## Task 1: Create a Terraform configuration that defines an output
15
11
16
12
For this task, you'll create two Terraform configurations in two separate directories. One will read from the other (using state files).
17
13
18
-
### Step 1.1.1
14
+
### Step 1.1
19
15
20
16
In this step, you'll create a Terraform project on disk that does nothing but emit an output. It should emit `public_ip` which can be a hard-coded value (for simplicity).
21
17
@@ -38,7 +34,7 @@ output "public_ip" {
38
34
}
39
35
```
40
36
41
-
### Step 1.1.2
37
+
### Step 1.2
42
38
43
39
Generate a state file for the project. Within that project, run `terraform init` and `apply`. You should see a `terraform.tfstate` file after running these commands.
44
40
@@ -54,7 +50,7 @@ terraform apply
54
50
55
51
## Task 2: Read an output value from that project's state
56
52
57
-
### Step 1.2.1
53
+
### Step 2.1
58
54
59
55
Create a new Terraform configuration that uses a data source to read the configuration from the `primary` project.
60
56
@@ -87,7 +83,7 @@ Initialize the secondary project with `init`.
Copy file name to clipboardExpand all lines: terraform_fundmentals/17-store-state.md
+19-19Lines changed: 19 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ You'll setup a new project using Terraform Cloud as your backed and use a second
11
11
12
12
## Task 1: Sign up for Terraform Cloud
13
13
14
-
1. Navigate to [the sign up page](https://app.terraform.io/signup) and create an account for Terraform Cloud. If you already have a TFC account
14
+
1. Navigate to [the sign up page](https://app.terraform.io/signup) and create an account for Terraform Cloud and an organization called `###-tfc-demo-2023` where `###` is your initials. If you already have an account, just create the organization.
15
15
16
16
1. Perform a `terraform login` from your workstation
17
17
@@ -40,7 +40,7 @@ Open the following URL to access the tokens page for app.terraform.io:
Setup the configuration to utilize the `remote` backend, replacing `ORGANIZATION NAME` with the name of your organization and ```###``` with your initials.
94
94
95
95
```hcl
96
96
# write_state/main.tf
97
97
terraform {
98
-
backend "remote" {
98
+
cloud {
99
99
organization = "<ORGANIZATION NAME>"
100
100
101
101
workspaces {
@@ -105,7 +105,7 @@ terraform {
105
105
}
106
106
```
107
107
108
-
### Step 2.2.3
108
+
### Step 2.3
109
109
110
110
Next, add the ability to generate and emit a `random` output from your configuration:
111
111
@@ -124,7 +124,7 @@ output "random" {
124
124
}
125
125
```
126
126
127
-
### Step 2.2.4
127
+
### Step 2.4
128
128
129
129
Provision the resource and push the state to Terraform Cloud with:
You'll see Terraform confirm it is creating your state remotely as well as your `random` output.
137
137
If you navigate back to your organization, you will also see a new workspace name `###_write_state`.
138
138
139
-
### Step 2.2.5
139
+
### Step 2.5
140
+
141
+
Congratulations! You're now storing state remotely. With Terraform Cloud you are able to share your workspace with teammates.
140
142
141
-
Congratulations!
142
-
You're now storing state remotely.
143
-
With Terraform Cloud you are able to share your workspace with teammates.
144
143
Back in the Terraform Cloud UI you'll be able to:
145
144
146
145
* View all your organization's workspaces
@@ -151,7 +150,7 @@ Back in the Terraform Cloud UI you'll be able to:
151
150
152
151
Now that we have our state stored in Terraform Cloud in our `###_write_state` workspace, we will create another project, configuration, and workspace to read from it.
153
152
154
-
### Step 2.3.1
153
+
### Step 3.1
155
154
156
155
Start by creating a new directory and `main.tf` file:
157
156
@@ -160,15 +159,15 @@ mkdir -p ~/workstation/terraform/azure/cloud_state_demo/read_state && cd $_
160
159
touch main.tf
161
160
```
162
161
163
-
### Step 2.3.2
162
+
### Step 3.2
164
163
165
164
Just as we did in Step 2.2.2, we need to setup our configuration to use the `remote` backend, once again replacing `ORGANIZATION NAME`.
166
165
We will also create a new `random` resource to compare against:
In order to read from our `###_write_state` workspace, we will need to setup a `terraform_remote_state` data source.
192
191
Data sources are used to retrieve read-only data from sources outside of our project.
193
-
It supports several cloud providers, but we'll be using `remote` as the `backend`.
192
+
193
+
It supports several cloud providers, but we'll be using `remote` as the `backend`. That is the name of the Terraform Cloud backend.
194
194
195
195
```hcl
196
196
# read_state/main.tf
@@ -211,7 +211,7 @@ In addition to creating the `terraform_remote_state` data source in your configu
211
211
212
212
From the Terraform Cloud UI, go to the `###_write_state` workspace, and select *Settings->General*. Under the *Remote state sharing* section change the radio button to **Share with all workspaces in this organization**, then click on *Save settings* at the bottom of the page.
213
213
214
-
### Step 2.3.4
214
+
### Step 3.4
215
215
216
216
Now that we have access to our remote `###_write_state` workspace, we can retrieve the `random` output contained within it.
217
217
We'll also output `random` which we created in this configuration, confirming that they are distinct.
@@ -227,7 +227,7 @@ output "write_state_random" {
227
227
}
228
228
```
229
229
230
-
### Step 2.3.5
230
+
### Step 3.5
231
231
232
232
To verify that we have successfully retrieved the state from out `###_write_state` workspace, we can run our configuration and validate our outputs.
Copy file name to clipboardExpand all lines: terraform_fundmentals/19-lifecycles.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ This lab demonstrates how to use lifecycle directives to control the order in wh
7
7
- Task 1: Use `create_before_destroy` with an instance rename
8
8
- Task 2: Use `prevent_destroy` with an instance
9
9
10
-
###Create the base Terraform Configuration
10
+
## Create the base Terraform Configuration
11
11
12
12
Change directory into a folder specific to this challenge, and create a `main.tf` and `terraform.tfvars` files to hold our configuration.
13
13
@@ -23,7 +23,7 @@ We will start with a few of the basic resources needed.
23
23
24
24
When you rename a Azure Virtual Machine, terraform will reprovision the resource (delete and then create a new instance). We can leverage `create_before_destroy` to override that default behavior
25
25
26
-
### Step 6.1.1: Deploy your Azure Virtual Machine
26
+
### Step 1.1: Deploy your Azure Virtual Machine
27
27
28
28
Place the following configuration in your `main.tf` file to deploy your virtual machine.
29
29
@@ -136,7 +136,7 @@ vm_size = "Standard_A2_v2"
136
136
- Run a `terraform plan`
137
137
- Run a `terraform apply`
138
138
139
-
### Step 6.1.2: Rename your Azure Virtual Machine
139
+
### Step 1.2: Rename your Azure Virtual Machine
140
140
141
141
Edit your `main.tf` file and add the suffix _renamed_ to the value for `name` as shown below:
142
142
@@ -170,7 +170,7 @@ Terraform will perform the following actions:
170
170
171
171
Answer `yes` to proceed with the replacement of the instances.
172
172
173
-
### Step 6.1.3: Use `create_before_destroy` and rename the instances again
173
+
### Step 1.3: Use `create_before_destroy` and rename the instances again
174
174
175
175
Add a `lifecycle` configuration to the `azurerm_virtual_machine` resource. Specify that this resource should be created before the existing instance(s) are destroyed. Additionally, rename the instance(s) again, by removing the suffix _renamed_, and replacing it with `new`
0 commit comments