Skip to content

Latest commit

 

History

History
171 lines (114 loc) · 5.22 KB

File metadata and controls

171 lines (114 loc) · 5.22 KB

Lab: S3

Help for the VSCode editor.

  1. Information only.

  2. Let's first inspect the configuration files in the directory called MCU.
    What is the AWS region configured for use in the provider block? (Assuming we do not pass in additional variables during command execution)
    1. Navigate to the directory terraform-projects/S3-Buckets/MCU/ in the Explorer pane

    2. We are asked about the provider and variables, so inspect all of providers.tf, variables.tf and terraform.tfvars. Assuming no TF_VAR_ environment variable is set, and terraform is run without either of -var or -var-file, then you should be able to determine the region.

    3. Reveal

      us-east-1

  3. There is a resource block configured in the main.tf file in this configuration directory. What is the resource name that will be provisioned when we run terraform apply?

    Remember that the resource name is a property of the resource statement, not an argument within the block (i.e. not what lies between { and })

    Reveal

    marvel-cinematic-universe

  4. What is the current state of this configuration directory?

    We can solve this with the following flow:

    1. Is there a terraform.tfstate file?
      • Yes - an apply has been run at least once, so it is certainly initialized.
        • Does the state file contain resources?
          • Yes - Resources Provisioned
          • No - Resources not provisioned
      • No - Move on
    2. Is there a .terraform directory, and does it contain plugin directories
      • Yes - Directory Initialized
      • No - Directory not initialized
  5. What is the name of the s3 bucket that has been created by this configuration?

    Examine main.tf and look at the resource arguments.

  6. What is the DNS domain name that is created for this bucket?

    Run terraform show inside this configuration directory and inspect the attribute called bucket_domain_name.

    cd /root/terraform-projects/S3-Buckets/MCU
    terraform show
  7. Information only

  8. The main.tf file is empty. Use it to create a new S3 bucket...

    Specifications

    • resource name: dc_bucket
    • bucket name: dc_is_better_than_marvel
    1. Navigate to the DC folder in the Explorer pane and open main.tf

    2. Create the resource block. Refer to the documentation if needed.

      Reveal
      resource "aws_s3_bucket" "dc_bucket" {
          bucket = "dc_is_better_than_marvel"
      }
      
    3. Try to create the bucket

      cd /root/terraform-projects/S3-Buckets/DC
      terraform init
      terraform plan
      terraform apply

    It's OK of you get an error - move on to the next question.

  9. Why did the terraform apply command fail?

    Refer to the error message from the previous terraform apply

  10. Information only

  11. Let's fix that now and change the bucket name so that it uses dashes (-) instead of underscore(_).
    1. Replace all _ with - in the bucket name so it now reads dc-is-better-than-marvel

    2. Deploy

      cd /root/terraform-projects/S3-Buckets/DC
      terraform init
      terraform plan
      terraform apply
  12. Navigate to the pixar directory in Explorer pane.

  13. Information only

  14. Upload woody.jpg to the existing bucket pixar-studios-2020

    Specifications

    • Bucket: pixar-studios-2020
    • Key: woody.jpg
    • Source: /root/woody.jpg

    For this we need to use the aws_s3_object resource which represents the state of a file in an S3 bucket. Note that the solution tab on the lab page suggests to use the aws_s3_bucket_object resource, however this is deprecated in favour of aws_s3_object.

    1. Navigate to the Pixar folder in Explorer pane

    2. Create the resource per the specfication. We haven't been given a ame for the resource in the question, so let's just call it upload

      Reveal
      resource "aws_s3_object" "upload" {
          bucket = "pixar-studios-2020"
          key = "woody.jpg"
          source = "/root/woody.jpg"
      }
      
    3. Deploy

      cd /root/terraform-projects/S3-Buckets/Pixar
      terraform init
      terraform plan
      terraform apply