-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3cc22b0
Showing
27 changed files
with
4,023 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Terraform for Beginners Course | ||
|
||
In this repo, we have the lab solutions for this course. | ||
|
||
Please also see [Tips for the VSCode Editor](https://github.com/kodekloudhub/community-faq/blob/main/docs/vscode-tips.md). | ||
|
||
Note that in many of these labs, pressing `Check` button may take 10-15 seconds to come back, since the validation has to run terraform in the background to test your configurations. | ||
|
||
* 01 - Getting Started with Terraform | ||
* [01 - Lab: HCL Basics](./docs/01-getting-started-with-terraform/01-hcl-basics.md) | ||
* 02 - Terraform Basics | ||
* [01 - Lab: Terraform Providers](./docs/02-terraform-basics/01-terraform-providers.md) | ||
* [02 - Lab: Multiple Providers](./docs/02-terraform-basics/02-multiple-providers.md) | ||
* [03 - Lab: Variables](./docs/02-terraform-basics/03-variables.md) | ||
* [04 - Lab: Using Variables in Terraform](./docs/02-terraform-basics/04-using-variables-in-terraform.md) | ||
* [05 - Lab: Resource Attributes](./docs/02-terraform-basics/05-resource-attributes.md) | ||
* [06 - Lab: Resource Dependencies](./docs/02-terraform-basics/06-resource-dependencies.md) | ||
* [07 - Lab: Output Variables](./docs/02-terraform-basics/07-output-variables.md) | ||
* 03 - Terraform State | ||
* [01 - Lab: Terraform State](./docs/03-terraform-state/01-terraform-state.md) | ||
* 04 - Working with Terraform | ||
* [01 - Lab: Terraform Commands](./docs/04-working-with-terraform/01-terraform-commands.md) | ||
* [02 - Lab: Lifecycle Rules](./docs/04-working-with-terraform/02-lifecycle-rules.md) | ||
* [03 - Lab: Data Sources](./docs/04-working-with-terraform/03-datasources.md) | ||
* [04 - Lab: count and for_each](./docs/04-working-with-terraform/04-count-and-for-each.md) | ||
* [05 - Lab: Version Constraints](./docs/04-working-with-terraform/05-version-contraints.md) | ||
* 05 - Terraform with AWS | ||
* [01 - Lab: AWS CLI and IAM](./docs/05-terraform-with-aws/01-aws-cli-and-iam.md) | ||
* [02 - Lab: IAM with Terraform](./docs/05-terraform-with-aws/02-iam-with-terraform.md) | ||
* [03 - Lab: S3](./docs/05-terraform-with-aws/03-s3.md) | ||
* [04 - Lab: DynamoDB](./docs/05-terraform-with-aws/04-dynamodb.md) | ||
* 06 - Remote State | ||
* [01 - Lab: Remote State](./docs/06-remote-state/01-remote-state.md) | ||
* [02 - Lab: Terraform State Commands]() | ||
* 07 - Terraform Provisioners | ||
* [01 - Lab: AWS EC2 and Provisioners](./docs/07-terraform-provisioners/01-aws-ec2-and-provisioners.md) | ||
* 08 - Terraform Import, Tainting Resources and Debugging | ||
* [01 - Lab: Taint and Debugging](./docs/08-terraform-import-tainting-debugging/01-taint-and-debugging.md) | ||
* [02 - Lab: Terraform Import](./docs/08-terraform-import-tainting-debugging/02-terraform-import.md) | ||
* 09 - Terraform Modules | ||
* [01 - Lab: Terraform Modules](./docs/09-terraform-modules/01-terraform-modules.md) | ||
* 10 - Terraform Functions and Conditional Expressions | ||
* [01 - Lab: Functions and Conditional Expressions](./docs/10-terraform-functions-and-conditional-expressions/01-functions-and-conditional-expressions.md) | ||
* [02 - Lab: Terraform Workspaces](./docs/10-terraform-functions-and-conditional-expressions/02-terraform-workspaces.md) |
185 changes: 185 additions & 0 deletions
185
docs/01-getting-started-with-terraform/01-hcl-basics.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
# Lab: HCL Basics | ||
|
||
Help for the [VSCode editor](https://github.com/kodekloudhub/community-faq/blob/main/docs/vscode-tips.md). | ||
|
||
1. Information only | ||
|
||
1. <details> | ||
<summary>Navigate to the directory /root/terraform-projects/HCL. There is a file present in this location. What is the file extension used by this file?</summary> | ||
|
||
1. Open the VSCode terminal. | ||
1. In the terminal, do | ||
|
||
``` | ||
cd /root/terraform-projects/HCL | ||
ls | ||
``` | ||
We see `main.tf`. The file name is `main` and the file extension is `.tf` | ||
</details> | ||
1. Information only | ||
1. <details> | ||
<summary>What is the resource type specified in this file?</summary> | ||
Inspect with VSCode: | ||
1. Click on `terraform-projects` in the explorer pane | ||
1. Click on the revealed `main.tf` to open the file | ||
1. Examine the `resource` line. The first argument is the `type` and the second argument is the `name`, therefore the answer is | ||
> `local_file` | ||
</details> | ||
1. <details> | ||
<summary>What is the resource name used for the local_file resource in this configuration file?</summary> | ||
Following on from the above, the answer is | ||
> `games` | ||
</details> | ||
1. <details> | ||
<summary>What is the name of the provider for which we are creating this resource?</summary> | ||
Know that the format of a resource type when decalring a resource is generally `provider_type`, therefore given `local_file` we have | ||
* `local` - name of the provider. | ||
* `file` - resource provided by the provider. | ||
So the answer is | ||
> `local` | ||
</details> | ||
1. <details> | ||
<summary>Which one of the below is not an example of an argument used within the resource block?</summary> | ||
Know that arguments are what appears between `{` and `}` in a resource block and are of the form `argument = value` | ||
This resource has two arguments: `filename` and `content` therefore the answer is the one that is not one of these two arguments | ||
> `resource_type = "local_file"` | ||
1. <details> | ||
<summary>If you run a terraform plan now? Would it work?</summary> | ||
> `No` | ||
Go ahead and try it in the terminal and note the errors. | ||
Why? We cannot plan or apply resources without first doing `terraform init`. For a new configuration, we must init the configuration to ensure all the correct providers are installed. | ||
</details> | ||
1. <details> | ||
<summary>Run a terraform init inside the configuration directory: /root/terraform-projects/HCL</summary> | ||
1. If the terminal is closed, reopen it | ||
1. Run the following commands | ||
```bash | ||
cd /root/terraform-projects/HCL | ||
terraform init | ||
``` | ||
</details> | ||
1. <details> | ||
<summary>What was the version of the local provider plugin that was downloaded?</summary> | ||
Inspect the output from `terraform init`. It lists the names and versions of all providers that were initialized. | ||
</details> | ||
1. <details> | ||
<summary>Now, try to run a terraform plan.</summary> | ||
In the terminal run | ||
``` | ||
terraform plan | ||
``` | ||
This will either print an execution plan, or it will print a list of errors. | ||
</details> | ||
1. <details> | ||
<summary>Why did the command fail?</summary> | ||
Inspect the error produced when the command was run. If unsure, refer to the [documentation](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file). | ||
We can see that it is complaining about arguments. | ||
</details> | ||
1. <details> | ||
<summary>Which of the following is not a valid argument for the local_file resource?</summary> | ||
Check the `Unsupported argument` error in the plan output. The argument that is "not expected here" is the invalid argument. | ||
</details> | ||
1. <details> | ||
<summary>Fix the argument in the configuration file and then run a terraform plan followed by terraform apply to create the local_file resource called games.</summary> | ||
Check the `Missing required argument` error in the plan output. This gives you the correct name for the invalid argument. | ||
1. Edit `file` to be `filename` | ||
1. Run | ||
``` | ||
terraform plan | ||
terraform apply | ||
``` | ||
</details> | ||
1. <details> | ||
<summary>What is the new argument that we have added?</summary> | ||
There are now three arguments to the resource. Two of them were there before (although the values were different), and one of them is new. | ||
> `sensitive_content` | ||
The values of sensitive fields do not show up in normal execution plans. | ||
</details> | ||
1. <details> | ||
<summary>If we run terraform plan or terraform apply now we see an error!<br/>Identify and fix the issue.</summary> | ||
You may ignore the deprecation warning. | ||
The error here is "Invalid attribute combination". This means we have specified more than one argument in a mutually exclusive argument group. The list of mutually exclusive arguments is provided in the message:<br/> | ||
`[content,sensitive_content,content_base64]` | ||
You are asked to ensure the file content does not show up in the execution plan, so you must remove the argument that is not sensitive, i.e. `content` | ||
Remove this, then run | ||
``` | ||
terraform plan | ||
terraform apply | ||
``` | ||
Unfortunately the sensitive content still shows up in the deprecation warning. Hashicorp should really fix that! It does not however show up in the execution plan itself. | ||
</details> | ||
1. Information only | ||
1. <details> | ||
<summary>Finally, destroy this resource using terraform destroy.</summary> | ||
Run | ||
``` | ||
terraform destroy | ||
``` | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# Lab: Terraform Providers | ||
|
||
Help for the [VSCode editor](https://github.com/kodekloudhub/community-faq/blob/main/docs/vscode-tips.md). | ||
|
||
1. <details> | ||
<summary>We have a new configuration directory located at the path /root/terraform-projects/things-to-do. Inspect this directory and find out the number of providers initialized within this directory.</summary> | ||
|
||
Konw that when a configuration is initialized with `terraform init`, a subdirectory `.terraform` is created by the init process. | ||
|
||
Inspect `/root/terraform-projects/things-to-do` directory as directed and look for `.terraform` there. If it doesn't exist, then no providers are initialized. | ||
|
||
</details> | ||
|
||
1. <details> | ||
<summary>How about now? How many provider plugins are installed in this configuration directory?</summary> | ||
|
||
The `.terraform` directory now exists. Expand this in the Explorer pane of the VSCode editor, and see that there is an entry<br/>`registry.terraform.io/hashicorp/local/2.3.0/linux_amd64/`<br/>This represents a single provider plugin. | ||
|
||
</details> | ||
|
||
1. <details> | ||
<summary>How many configuration files exist in the directory: /root/terraform-projects/things-to-do ?</summary> | ||
|
||
Configuration files are genrally files with a `.tf` file extension. Count them. | ||
|
||
</details> | ||
|
||
1. <details> | ||
<summary>How many resources are configured in this configuration directory?</summary> | ||
|
||
Count all the resource blocks used. | ||
|
||
We can see two resources: `things-to-do` and `more-things-to-do` | ||
|
||
</details> | ||
|
||
1. <details> | ||
<summary>What is the version of the plugin for the local provider that has been downloaded for this configuration?</summary> | ||
|
||
Referring back to what we did io Q2, we can see the version as part of the path<br/>`registry.terraform.io/hashicorp/local/2.3.0/linux_amd64/` | ||
|
||
</details> | ||
|
||
1. <details> | ||
<summary>Now, go ahead and create these resources using terraform!</summary> | ||
|
||
Run the following | ||
|
||
```bash | ||
cd /root/terraform-projects/things-to-do | ||
terraform plan | ||
terraform apply | ||
``` | ||
|
||
Note that we didn't do `terraform init` here. That was done for you by the setup phase of Q2. | ||
</details> | ||
1. Information only | ||
1. <details> | ||
<summary>How many resources are configured within this configuration directory?</summary> | ||
1. Navigate to `christmas-wishlist` in the Eplorer pane. | ||
1. Open each of the `.tf` files in turn | ||
1. Count the resource blocks in each file. | ||
1. Sum the results | ||
</details> | ||
1. <details> | ||
<summary>What is the filename that will be created by the resource called cyberpunk?</summary> | ||
Check the value for `filename` argument in `cyberpunk.tf` | ||
</details> | ||
1. <details> | ||
<summary>Create a new configuration file within the same directory called xbox.tf. This file should make use of the same local_file resource type with the below requirements:</summary> | ||
* Resource name: `xbox` | ||
* filename: `root/xbox.txt` | ||
* content: `Wouldn't mind an XBox either!` | ||
<details> | ||
<summary>Reveal code</summary> | ||
```hcl | ||
resource "local_file" "xbox" { | ||
filename = "/root/xbox.txt" | ||
content = "Wouldn't mind an XBox either!" | ||
} | ||
``` | ||
</details> | ||
|
||
Now run the following in the terminal | ||
|
||
```bash | ||
cd /root/terraform-projects/christmas-wishlist | ||
terraform init | ||
terraform plan | ||
terraform apply | ||
``` | ||
|
||
</details> | ||
|
||
1. <details> | ||
<summary>Now, navigate to the directory /root/terraform-projects/provider-a. We have downloaded a plugin in this directory. Identify the name and type of provider.</summary> | ||
|
||
1. You can look in the `.terraform` directory beneath `provider-a` in the Explorer pane. Here we see `linode` | ||
1. Go to https://registry.terraform.io and search for `linode`, then click on the result. | ||
1. Now we see that the provder is "by: linode" and that linode is a partner. This means it is "verified". Official providers are "by: Hashicorp". | ||
|
||
</details> | ||
|
||
1. <details> | ||
<summary>Now, navigate to the directory /root/terraform-projects/provider-b. We have downloaded a plugin in this directory. Identify the name and type of provider.</summary> | ||
|
||
Just as for the previous question, find the provider on terraform registry. Since it is neither by Hashicorp, nor by Ansible themselves and marked as Partner, it is therefore a community provider. | ||
|
||
Anyone with golang programming skills can create a community provider and publish it to the registry. | ||
|
||
</details> | ||
|
Oops, something went wrong.