Help for the VSCode editor.
-
Information only
-
Let's start off by creating an IAM User called mary but this time by making use of Terraform. In the configuration directory /root/terraform-projects/IAM, create a file called iam-user.tf
- Resource Type:
aws_iam_user
- Resource Name:
users
- Name:
mary
-
Refer to the [documentation]) for
aws_iam_user
. Check the Argument Refrence and note that there's only one required argument. Given the requirements we have, that should be all we need. -
Create the resource
Reveal
resource "aws_iam_user" "users" { name = "mary" }
-
Init the configuration
cd /root/terraform-projects/IAM terraform init
- Resource Type:
-
Run terraform plan within this configuration.
terraform plan
Note any error.
-
Why did the previous command fail?
From the error message we can see that it is
Region is not set.
-
Information only
-
Add a new file called provider.tf containing a provider block for aws.
Inside this block add a single argument called region with the value ca-central-1-
Add new file
provider.tf
-
Configure the provider block
Reveal
provider "aws" { region = "ca-central-1" }
-
-
Run a terraform plan now. Does it work?
terraform plan
Note any error.
-
Information only. Note that we have also updated
provider.tf
for you. -
Now, run a terraform plan and then a terraform apply
terraform plan terraform apply
-
Information only
-
What is the name of the variable that has been added to the variables.tf file?
Inspect
variables.tf
. There's only the one variable. -
What is the data type used for the variable called project-sapphire-users?
Inspect the
type
argument of this variable -
Now, update the iam-user.tf to make use of the count meta-argument to loop through the project-sapphire-users variable and create all the users in the list.
What needs to be done here is almost exactly the same as you did in Q6 in the count and for_each lab in course section 4.
-
Update the resource accordingly.
Reveal
resource "aws_iam_user" "users" { count = length(var.project-sapphire-users) name = var.project-sapphire-users[count.index] }
-