Skip to content

Commit

Permalink
minor fixes and streamlining
Browse files Browse the repository at this point in the history
  • Loading branch information
ned1313 committed Aug 14, 2023
1 parent d044b6e commit b0c01de
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 28 deletions.
10 changes: 5 additions & 5 deletions terraform_fundmentals/14-data_source.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ touch datasource/virtual_network/{main,terraform}.tf

Populate the files for the virtual network:

`terraform.tf`
`virtual_network/terraform.tf`

```terraform
terraform {
Expand All @@ -37,7 +37,7 @@ provider "azurerm" {
}
```

`main.tf`
`virtual_network/main.tf`

```terraform
resource "azurerm_resource_group" "data_source" {
Expand Down Expand Up @@ -75,7 +75,7 @@ cd ../azure_vm
touch {main,terraform,data}.tf
```

Populate the `terraform.tf` file:
Populate the `azure_vm/terraform.tf` file:

```terraform
terraform {
Expand All @@ -92,7 +92,7 @@ provider "azurerm" {
}
```

Populate the `data.tf` file:
Populate the `azure_vm/data.tf` file:

```terraform
data "azurerm_subnet" "web_subnet" {
Expand All @@ -115,7 +115,7 @@ terraform apply

## Task 3: Use the data source for an Azure VM

Populate the `main.tf` file:
Populate the `azure_vm/main.tf` file:

```terraform
resource "azurerm_network_interface" "web" {
Expand Down
24 changes: 12 additions & 12 deletions terraform_fundmentals/15-reading_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ In this step, you'll create a Terraform project on disk that does nothing but em

The project should consist of a single file which can be named something like `primary/main.tf`.

```shell
```bash
mkdir -p ~/workstation/terraform/azure/read_state_lab/primary && cd $_
```

```shell
```bash
touch main.tf
```

The contents of `main.tf` are a single output for `public_ip`. This is the entire contents of the file.

```bash
```hcl
# primary/main.tf
output "public_ip" {
value = "8.8.8.8"
Expand All @@ -40,11 +40,11 @@ Generate a state file for the project. Within that project, run `terraform init`

Run the standard `terraform` commands within the `primary` project.

```shell
```bash
terraform init
```

```shell
```bash
terraform apply
```

Expand All @@ -56,17 +56,17 @@ Create a new Terraform configuration that uses a data source to read the configu

Create a second directory named `secondary`.

```shell
```bash
mkdir ~/workstation/terraform/azure/read_state_lab/secondary && cd $_
```

```shell
```bash
touch main.tf
```

Define a `terraform_remote_state` data source that uses a `local` backend which points to the primary project.

```bash
```hcl
# secondary/main.tf
# Read state from another Terraform config’s state
data "terraform_remote_state" "primary" {
Expand All @@ -79,7 +79,7 @@ data "terraform_remote_state" "primary" {

Initialize the secondary project with `init`.

```shell
```bash
terraform init
```

Expand All @@ -89,19 +89,19 @@ Declare the `public_ip` as an `output`.

Within `/workstation/terraform/azure/read_state_lab/secondary/main.tf`, define an output whose value is the `public_ip` from the data source you just defined.

```bash
```hcl
output "primary_public_ip" {
value = data.terraform_remote_state.primary.outputs.public_ip
}
```

Finally, run `apply`. You should see the IP address you defined in the `primary` configuration.

```shell
```bash
terraform apply
```

```
```bash
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:
Expand Down
8 changes: 4 additions & 4 deletions terraform_fundmentals/17-store-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ You'll setup a new project using Terraform Cloud as your backed and use a second

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.

1. Perform a `terraform login` from your workstation
1. Perform a `terraform login` from your lab environment.

```bash
Terraform will request an API token for app.terraform.io using your browser.
Expand Down Expand Up @@ -142,9 +142,9 @@ Congratulations! You're now storing state remotely. With Terraform Cloud you are

Back in the Terraform Cloud UI you'll be able to:

* View all your organization's workspaces
* Lock a workspace, making it easy to avoid conflicting changes and state corruption
* View state history
- View all your organization's workspaces
- Lock a workspace, making it easy to avoid conflicting changes and state corruption
- View state history

## Task 3: Create another Terraform config that reads from the state on Terraform Cloud

Expand Down
4 changes: 2 additions & 2 deletions terraform_fundmentals/18-secure_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You can store your variable values in a Terraform Cloud workspace. In this lab w
Create the directory for the Terraform config:

```bash
mkdir tfc-secure-variables && cd tfc-secure-variables
mkdir -p ~/workstation/terraform/azure/tfc-secure-variables && cd $_
touch {terraform,main}.tf
```

Expand Down Expand Up @@ -110,7 +110,7 @@ Kick off a run from the CLI:
terraform plan
```

Observe that this is a speculative plan.
Observe that this is a speculative plan. If you receive a variable or cloud authentication error, you may have mistyped the variable name or value, or you may have selected the wrong variable type.

Kick off an apply from the CLI:

Expand Down
2 changes: 1 addition & 1 deletion terraform_fundmentals/19-lifecycles.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ resource "azurerm_virtual_machine" "main" {
# ...
storage_os_disk {
name = "${var.prefix}myvm-osdisk"
name = "${var.prefix}myvm-osdisk-new"
...
lifecycle {
Expand Down
14 changes: 10 additions & 4 deletions terraform_fundmentals/20-templatefile.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ Build the dashboard using the Azure Virtual Machine Module

Create a new directory for this lab and create a `main.tf` with the following:

- make sure to update ### with your initials
```bash
mkdir -p ~/workstation/terraform/azure/templatefile/ && cd $_
touch main.tf
```

Add the below configuration to the `main.tf` file. Make sure to update ### with your initials

```hcl
provider "azurerm" {
Expand Down Expand Up @@ -165,14 +170,14 @@ output "dashboard_url" {
```
Then perform an `init`, `plan`, and `apply`.

## Task 2: Use `templatefile` to render the dasboard layout
## Task 2: Use `templatefile` to render the dashboard layout

### Step 2.1: Use `templatefile`

1. Create a `templates` directory in the same directory as your `main.tf`
2. Create a `dash.tpl` file inside the `templates` directory.

For example: `/terraform/azure/template_lab` which contains:
For example: `/terraform/azure/templatefile` which contains:

```bash
├ main.tf
Expand Down Expand Up @@ -312,7 +317,8 @@ Replace with the following
sub_id = data.azurerm_subscription.current.subscription_id
})
```
Initialize the configuration with a `terraform init` followed by a `plan` and `apply`.

Run a `terraform plan` and `terraform apply` to see the changes.

### Step 2.3: Destroy

Expand Down

0 comments on commit b0c01de

Please sign in to comment.