Help for the VSCode editor.
-
Information only.
-
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)-
Navigate to the directory
terraform-projects/S3-Buckets/MCU/
in the Explorer pane -
We are asked about the provider and variables, so inspect all of
providers.tf
,variables.tf
andterraform.tfvars
. Assuming noTF_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. -
Reveal
us-east-1
-
-
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
-
What is the current state of this configuration directory?
We can solve this with the following flow:
- 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
- Yes -
- Does the state file contain resources?
- No - Move on
- Yes - an
- Is there a
.terraform
directory, and does it contain plugin directories- Yes -
Directory Initialized
- No -
Directory not initialized
- Yes -
- Is there a
-
What is the name of the s3 bucket that has been created by this configuration?
Examine
main.tf
and look at the resource arguments. -
What is the DNS domain name that is created for this bucket?
Run
terraform show
inside this configuration directory and inspect the attribute calledbucket_domain_name
.cd /root/terraform-projects/S3-Buckets/MCU terraform show
-
Information only
-
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
-
Navigate to the
DC
folder in the Explorer pane and openmain.tf
-
Create the resource block. Refer to the documentation if needed.
Reveal
resource "aws_s3_bucket" "dc_bucket" { bucket = "dc_is_better_than_marvel" }
-
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.
- resource name:
-
Why did the terraform apply command fail?
Refer to the error message from the previous
terraform apply
-
Information only
-
Let's fix that now and change the bucket name so that it uses dashes (-) instead of underscore(_).
-
Replace all
_
with-
in the bucket name so it now readsdc-is-better-than-marvel
-
Deploy
cd /root/terraform-projects/S3-Buckets/DC terraform init terraform plan terraform apply
-
-
Navigate to the
pixar
directory in Explorer pane. -
Information only
-
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 ofaws_s3_object
.-
Navigate to the
Pixar
folder in Explorer pane -
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" }
-
Deploy
cd /root/terraform-projects/S3-Buckets/Pixar terraform init terraform plan terraform apply
- Bucket: