Skip to content

Latest commit

 

History

History
157 lines (94 loc) · 3.97 KB

01-terraform-modules.md

File metadata and controls

157 lines (94 loc) · 3.97 KB

Lab: HCL Basics

Help for the VSCode editor.

  1. Navigate to indicated directory in Explorer pane

  2. Which configuration block is defined in the main.tf file at the moment?

    module

  3. What is the source of the module used in this configuration?

    Public terraform registry

    You can verify by searhcing for it at https://registry.terraform.io

  4. What is the version of the module used?

    Inspect the version argument to the module block.

  5. How many required arguments does this module expect?

    Refer to the documentation and scroll down to the inputs section.

    Reveal

    1

  6. Which argument is to be specified, just to create an IAM User with this module?

    From where you retrieved the previous answer in the documentatin, get the name of this required variable

    Reveal

    name

  7. Now, update this module block that will allow it to create an IAM User called max.
    1. Replace the comment in main.tf with the appropriate argument

      Reveal
      name = "max"
      
      </details>
      
      
    2. Init and plan

      cd /root/terraform-projects/project-sapphire
      terraform init
      terraform plan
  8. How many resources are set to be created in the execution plan ?

    Examine the output of the terraform plan you just ran.

    Reveal

    3

  9. Which resources are set to be created?

    Given we know how many resources will be created from the answer of the previous question, only one of the given options cann possibly be correct! Plus they're all present in the plan output.

    Reveal

    aws_iam_access_key, aws_iam_user and aws_iam_user_login_profile

  10. Why is the module creating additional resources, when only the name for creating an IAM User was defined in the main.tf file?

    Refer to the [documentation]https://registry.terraform.io/modules/terraform-aws-modules/iam/aws/latest/submodules/iam-user) and scroll down to the inputs section. Inspect the default values for arguments we did not provide.

    Reveal

    The three resources will be created by default as per the modiule configuration.

  11. We only want to create the IAM User. Update the module block to only allow create_user. Disable create_iam_access_key and create_iam_user_login_profile.

    You should haqve esablished that there are some default tru boolean values for some arguments. These need to be explicitly set false to disable the subresource creation.

    1. Update the mdule resource accordingly

      Reveal
      module "iam_iam-user" {
          source  = "terraform-aws-modules/iam/aws//modules/iam-user"
          version = "3.4.0"
          name                          = "max"
          create_iam_user_login_profile = false
          create_iam_access_key         = false
      }
      
    2. Deploy

      cd /root/terraform-projects/project-sapphire
      terraform plan
      terraform apply