From b0c01def1940610175b94f0efa492ed7b0cee745 Mon Sep 17 00:00:00 2001 From: ned1313 Date: Mon, 14 Aug 2023 07:29:51 -0400 Subject: [PATCH] minor fixes and streamlining --- terraform_fundmentals/14-data_source.md | 10 ++++---- terraform_fundmentals/15-reading_state.md | 24 ++++++++++---------- terraform_fundmentals/17-store-state.md | 8 +++---- terraform_fundmentals/18-secure_variables.md | 4 ++-- terraform_fundmentals/19-lifecycles.md | 2 +- terraform_fundmentals/20-templatefile.md | 14 ++++++++---- 6 files changed, 34 insertions(+), 28 deletions(-) diff --git a/terraform_fundmentals/14-data_source.md b/terraform_fundmentals/14-data_source.md index b7838f8..e8faff8 100644 --- a/terraform_fundmentals/14-data_source.md +++ b/terraform_fundmentals/14-data_source.md @@ -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 { @@ -37,7 +37,7 @@ provider "azurerm" { } ``` -`main.tf` +`virtual_network/main.tf` ```terraform resource "azurerm_resource_group" "data_source" { @@ -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 { @@ -92,7 +92,7 @@ provider "azurerm" { } ``` -Populate the `data.tf` file: +Populate the `azure_vm/data.tf` file: ```terraform data "azurerm_subnet" "web_subnet" { @@ -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" { diff --git a/terraform_fundmentals/15-reading_state.md b/terraform_fundmentals/15-reading_state.md index 684c8d7..e2aa9ce 100644 --- a/terraform_fundmentals/15-reading_state.md +++ b/terraform_fundmentals/15-reading_state.md @@ -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" @@ -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 ``` @@ -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" { @@ -79,7 +79,7 @@ data "terraform_remote_state" "primary" { Initialize the secondary project with `init`. -```shell +```bash terraform init ``` @@ -89,7 +89,7 @@ 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 } @@ -97,11 +97,11 @@ output "primary_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: diff --git a/terraform_fundmentals/17-store-state.md b/terraform_fundmentals/17-store-state.md index ee3c308..c108b64 100644 --- a/terraform_fundmentals/17-store-state.md +++ b/terraform_fundmentals/17-store-state.md @@ -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. @@ -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 diff --git a/terraform_fundmentals/18-secure_variables.md b/terraform_fundmentals/18-secure_variables.md index 0ab4fcf..f257ef9 100644 --- a/terraform_fundmentals/18-secure_variables.md +++ b/terraform_fundmentals/18-secure_variables.md @@ -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 ``` @@ -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: diff --git a/terraform_fundmentals/19-lifecycles.md b/terraform_fundmentals/19-lifecycles.md index 8adc233..6d92c44 100644 --- a/terraform_fundmentals/19-lifecycles.md +++ b/terraform_fundmentals/19-lifecycles.md @@ -180,7 +180,7 @@ resource "azurerm_virtual_machine" "main" { # ... storage_os_disk { - name = "${var.prefix}myvm-osdisk" + name = "${var.prefix}myvm-osdisk-new" ... lifecycle { diff --git a/terraform_fundmentals/20-templatefile.md b/terraform_fundmentals/20-templatefile.md index 7b31bb3..8e3d9f2 100644 --- a/terraform_fundmentals/20-templatefile.md +++ b/terraform_fundmentals/20-templatefile.md @@ -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" { @@ -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 @@ -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