Skip to content

Latest commit

 

History

History
138 lines (88 loc) · 3.27 KB

02-iam-with-terraform.md

File metadata and controls

138 lines (88 loc) · 3.27 KB

Lab: IAM with Terraform

Help for the VSCode editor.

  1. Information only

  2. 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
    1. 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.

    2. Create the resource

      Reveal
      resource "aws_iam_user" "users" {
          name = "mary"
      }
      
    3. Init the configuration

      cd /root/terraform-projects/IAM
      terraform init
  3. Run terraform plan within this configuration.
    terraform plan

    Note any error.

  4. Why did the previous command fail?

    From the error message we can see that it is

    Region is not set.

  5. Information only

  6. 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
    1. Add new file provider.tf

    2. Configure the provider block

      Reveal
      provider "aws" {
          region = "ca-central-1"
      }
      
  7. Run a terraform plan now. Does it work?
    terraform plan

    Note any error.

  8. Information only. Note that we have also updated provider.tf for you.

  9. Now, run a terraform plan and then a terraform apply
    terraform plan
    terraform apply
  10. Information only

  11. 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.

  12. What is the data type used for the variable called project-sapphire-users?

    Inspect the type argument of this variable

  13. 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.

    1. Update the resource accordingly.

      Reveal
      resource "aws_iam_user" "users" {
          count = length(var.project-sapphire-users)
          name = var.project-sapphire-users[count.index]
      }