Skip to content

Commit

Permalink
fixed vcdl-864
Browse files Browse the repository at this point in the history
  • Loading branch information
syedQuadri7 committed Jun 13, 2024
1 parent 294ea78 commit 7d9b1a6
Show file tree
Hide file tree
Showing 293 changed files with 3,159 additions and 3,074 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
slug: setup-our-environment
id: ebj23ohhehzw
type: challenge
title: "\U0001F3E1 Moving in - Explore Your Workspace"
teaser: |
Explore the Terraform code for the hashicat application.
notes:
- type: text
contents: |
Setting up your environment...
Keep an eye on the bottom right corner to know when you can get started.
- type: text
contents: The Terraform command line tool is available for MacOS, FreeBSD, OpenBSD,
Windows, Solaris and Linux.
- type: text
contents: The Terraform language is designed to be both human and machine-readable.
- type: text
contents: Most modern code editors support Terraform syntax highlighting.
tabs:
- title: Shell
type: terminal
hostname: workstation
- title: Code Editor
type: code
hostname: workstation
path: /root/hashicat-aws
difficulty: basic
timelimit: 10000
---
Open the "Code Editor" tab on the left. You'll see some terraform configuration files for the hashicat application. Open the file called "main.tf". Note that the file type at the bottom of the screen was automatically set to "hcl" to give optimized syntax highlighting and colors.

When you edit any of these files, you will see a blue dot and a disk icon on the tab above it. **Be sure to click the disk icon to save your changes!** There is no "auto-saving" in the Instruqt editor!

Throughout this track, please execute all commands on the "Shell" tab.

Congratulations, you are ready to start working with Terraform on AWS. We'll use the hashicat-aws example app in the rest of the challenges as you learn new Terraform skills.

Click the **Check** button to continue.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
slug: hello-terraform
id: e0tq7efazoo2
type: challenge
title: "\U0001F44B Getting to Know Terraform"
teaser: |
Learn Terraform basics and command line syntax.
notes:
- type: text
contents: |-
Terraform Community Edition is a command line application that you can download and run from your laptop or virtual workstation.
It is written in Go and runs on macOS, Linux or Windows. You can always download the latest version of Terraform from https://www.terraform.io/downloads.html
- type: text
contents: |-
Installing Terraform on your laptop or workstation is easy. You simply download the zip file, unpack it, and place it somewhere in your PATH.
Check out this tutorial for step-by-step instructions:
https://learn.hashicorp.com/terraform/getting-started/install.html
We've pre-installed Terraform in your Instruqt lab environment for you.
tabs:
- title: Shell
type: terminal
hostname: workstation
- title: Code Editor
type: code
hostname: workstation
path: /root/hashicat-aws
difficulty: basic
timelimit: 10000
---
Let's start with some basic Terraform commands.
Run the following commands on the "Shell" tab.

Check the version of Terraform running on your machine:

```
terraform version
```

You can always get help if you're curious about command syntax:

```
terraform --help
```

Terraform runs on Windows, OSX, or Linux. You can install it on your laptop or on a cloud based workstation.

Today we'll be using the preconfigured Terraform workstation in the "Code Editor" and "Shell" tabs on the left for all our lab exercises.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
slug: aws-credentials
id: qtjyikiuvx9z
type: challenge
title: "\U0001F510 Connecting Terraform to AWS"
teaser: |
Connecting to AWS with Access Keys and Secret Keys.
notes:
- type: text
contents: Did you know HCL stands for "HashiCorp Configuration Language"?
tabs:
- title: Shell
type: terminal
hostname: workstation
- title: Code Editor
type: code
hostname: workstation
path: /root/hashicat-aws
difficulty: basic
timelimit: 10000
---
In order to authenticate to AWS and build resources, Terraform requires you to provide a set of credentials, backed by an appropriate IAM policy.

For this training environment, we have prepared some temporary AWS credentials and stored them as environment variables. Terraform will automatically read and use the environment variables that are configured in your shell environment.

Run the following commands on the "Shell" tab:

```
echo $AWS_ACCESS_KEY_ID
echo $AWS_SECRET_ACCESS_KEY
```
You should see valid AWS keys. If not, return to the track home page by clicking the **Close** button, stop the track, and then restart it.

*Do not ever store your credentials in source code files*, as they can be accidentally exposed or copied to a public repository.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
slug: terraform-code
id: ozizhb0unuov
type: challenge
title: "\U0001F468\U0001F4BB What does Terraform code look like?"
teaser: |
The Terraform DSL (Domain Specific Language) is a declarative language that lets you build almost any type of infrastructure.
notes:
- type: text
contents: |-
Terraform will read anything in the current directory that ends in `*.tf` or `*.tfvars`.
By convention most Terraform workspaces will contain `main.tf`, `variables.tf`, and `outputs.tf` files.
You can also group your Terraform code into files by purpose. For example, you might place all your load balancer configuration code into a file called `load_balancer.tf`.
tabs:
- title: Shell
type: terminal
hostname: workstation
- title: Code Editor
type: code
hostname: workstation
path: /root/hashicat-aws
difficulty: basic
timelimit: 10000
---
We've downloaded some Terraform code onto your workstation. Run the following command to see the Terraform code files:
```
ls *.tf
```
The same files are visible in the file explorer pane on the left. Terraform files are marked with the purple T icon.

Terraform code always ends with a `.tf` extension. You can have as many Terraform files as you want, but these three are commonly created first:

**main.tf** - Where most of your Terraform code is stored. This is the part that does the building of resources.<br>
**variables.tf** - Use this file to define which variables will be available to your users.<br>
**outputs.tf** - This file contains outputs that will be shown at the end of a successful Terraform run.

Files that end in anything other than `*.tf` or `*.tfvars` are ignored by Terraform.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
slug: terraform-init-provider
id: rxw0ladzg8zc
type: challenge
title: "\U0001F3E1 Terraform Init - Install the Providers"
teaser: |
Terraform needs a provider to talk to cloud APIs. The provider is the bridge that connects Terraform core to your infrastructure providers.
notes:
- type: text
contents: |-
The Terraform core program isn't very useful by itself. Terraform needs the help of a *provider* to be able to talk to cloud APIs. Terraform has hundreds of different providers. You can browse the provider list here:
https://registry.terraform.io/browse/providers
Today we'll be using a few different providers, but the main one is the *aws* provider.
tabs:
- title: Shell
type: terminal
hostname: workstation
- title: Code Editor
type: code
hostname: workstation
path: /root/hashicat-aws
difficulty: basic
timelimit: 10000
---
We have downloaded some Terraform code for the HashiCat application. We'll be using this source code for the rest of the track.

Before we can do anything with Terraform we need to initialize our workspace. Run the following command in your "Shell" tab:
```
terraform init
```

The `terraform init` command scans your Terraform code, identifies any providers that are needed, and downloads them.

Run the following command to verify that the aws provider was installed under the ".terraform" directory:

```
ls .terraform/providers/registry.terraform.io/hashicorp
```

This hidden directory is where all modules and plugins are stored.
22 changes: 22 additions & 0 deletions instruqt-tracks/terraform-intro-aws/06-provider-quiz/assignment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
slug: provider-quiz
id: qtjoepabjrlx
type: quiz
title: "\U0001F4DD Quiz 1 - Providers and Modules"
teaser: |
A quiz about Terraform init
notes:
- type: text
contents: |
It's quiz time!
answers:
- In the /tmp directory
- In the user's home directory
- In the .terraform directory
- None of the above
solution:
- 2
difficulty: basic
timelimit: 10000
---
Where does Terraform store its modules and providers?
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
slug: terraform-validate
id: 0ge7cn9kcnom
type: challenge
title: "\U0001F469‍⚖️ Terraform Validate - Test Your Code"
teaser: |
Terraform has a built in validation tester. This is useful to see whether your Terraform code is valid and parses correctly.
notes:
- type: text
contents: Terraform has a built-in syntax checker. You can run it with the `terraform
validate` command.
tabs:
- title: Shell
type: terminal
hostname: workstation
- title: Code Editor
type: code
hostname: workstation
path: /root/hashicat-aws
difficulty: basic
timelimit: 10000
---
Terraform comes with a built-in subcommand called *validate*. This is useful when you want to do a quick syntax check of your code to make sure it parses correctly.

Edit the main.tf file and remove the double quotes between `aws_vpc` and `hashicat` on line 14 of the file, keeping the space that was between them. Save the file.

Validate your code:

```
terraform validate
```

Now put the double quotes back in line 14, save the file, and run the validate command again. This time you should pass the validation test.

`terraform validate` is most often used in automated CI/CD test pipelines. It allows you to quickly catch errors in your code before any other steps are taken.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
slug: terraform-plan
id: wrnxxdklcxbq
type: challenge
title: "\U0001F914 Terraform Plan - Dry Run Mode"
teaser: |
Terraform has a dry run mode where you can preview what will be built without actually creating any resources. In this challenge we'll run `terraform plan` and view the output.
notes:
- type: text
contents: |-
`terraform plan` allows you to preview any changes to your environment in a safe way.
This can help you identify any unexpected changes before you deploy them, not after they are already built.
tabs:
- title: Shell
type: terminal
hostname: workstation
- title: Code Editor
type: code
hostname: workstation
path: /root/hashicat-aws
difficulty: basic
timelimit: 10000
---
Run the `terraform plan` command:

```
terraform plan
```

When you run this command Terraform will prompt you to enter the `prefix` variable.

Enter a short string of lower-case letters and/or numbers. We recommend that you use your first and last name.

The prefix will become part of the name for our VPC, subnet, EC2 instance and other resources.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
slug: terraform-variables
id: d9uqeneyhruz
type: challenge
title: "\U0001F39B️ Working with Terraform Variables"
teaser: |
Terraform variables allow you to customize your infrastructure without editing any code. You can use the same Terraform code to deploy dev, staging and production but with different variables.
notes:
- type: text
contents: The `terraform.tfvars` file is a convenient place for users to configure
their variables.
tabs:
- title: Shell
type: terminal
hostname: workstation
- title: Code Editor
type: code
hostname: workstation
path: /root/hashicat-aws
difficulty: basic
timelimit: 10000
---
In Terraform all variables must be declared (with or without an optional default value) before you can use them. Variables are usually declared in the "variables.tf" file although they can also be declared in other "*.tf" files. Their values can be set in the "terraform.tfvars" file and in other ways which we'll explore later.

Open the "terraform.tfvars" file and set your `prefix` variable by deleting the `# ` at the beginning of the line and replacing "yourname" with your own name (first and last with or without a hyphen between them and all lower case).

**Be sure to click the disk icon above the file to save your change!**

Now run `terraform plan` again. This time you won't have to enter your prefix manually.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
slug: terraform-add-a-variable
id: zdbscmg1vqjl
type: challenge
title: "\U0001F5FC Change Your Location"
teaser: |
Terraform is flexible enough to deploy infrastructure anywhere in the world. You can easily provision your applications in different geographical regions by simply changing a single variable.
notes:
- type: text
contents: |-
You can override any variable defined in the "variables.tf" file by setting it in your personal `terraform.tfvars` file.
In this challenge, you will pick the location where your AWS resources should be deployed.
tabs:
- title: Shell
type: terminal
hostname: workstation
- title: Code Editor
type: code
hostname: workstation
path: /root/hashicat-aws
difficulty: basic
timelimit: 10000
---
In the previous challenge we set our `prefix` variable in the "terraform.tfvars" file. Let's set another variable that will determine the location where your AWS infrastructure will be deployed.

First run another plan so you'll be able to compare what happens after you change the location.

```
terraform plan
```

Choose an AWS region near you but different from the default one which is "us-east-1". Add a `region` variable to your "terraform.tfvars" file, setting it to your desired region such as `us-west-1`, `eu-west-2`, or `ap-southeast-1`.

See this [page](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-available-regions) for a list of valid AWS regions.

Choosing a region close to you can help improve speed and performance.

**Be sure to click the disk icon above the file to save your change!**

Once you've set your `region` variable, try running `terraform plan` again. What's different this time?

Remember that you can set values for any variable declared in your "variables.tf" file in the "terraform.tfvars" file.
Loading

0 comments on commit 7d9b1a6

Please sign in to comment.