Skip to content

Latest commit

 

History

History
95 lines (55 loc) · 3.42 KB

File metadata and controls

95 lines (55 loc) · 3.42 KB

Lab: Datasources

Help for the VSCode editor.

  1. A data source once created, can be used to create, update, and destroy infrastructure?

    FALSE

    A datasource can only read resource data and use that information within terraform.

  2. A data source can be created using the data block.

    'TRUE'

  3. A new configuration directory has been created at /root/terraform-projects/project-lexcorp. A data source block is defined in the main.tf file to read the contents of an existing file.
    There is also an output variable that uses reference expression to print the file content using this data source. However, there is something wrong!
    Troubleshoot and fix the issue.
    1. We can immediately see the first issue based on the onswer to the previous question. There is no such block as datasource. Correct this.

    2. Let's see if we fixed it

      cd /root/terraform-projects/project-lexcorp
      terraform init
      terraform plan
    3. There is another error at line 2

      A data resource "local_file" "content" has not been declared in the root module.

      The value reference at this line is incorrectly looking for

      data "local_file" "content" { ... }
      

      so there is a mistake in the reference expression. A reference expression for a data block is:

      data.type.name.attribute

      We know from previous labs that the local_file resource has an attribute content, therefore we are missing the resource name from the reference. Correct it:

      data.local_file.os.content

    4. Deploy

      terraform plan
      terraform apply
      
  4. Information only.

  5. We have now created a new configuration file called ebs.tf within the same configuration directory we have been working on.
    What is the resource type that we are working with here?

    The first property of the data block is the resource type, just as it is for resource

    aws_ebs_volume

  6. Once this data source is created, how do we fetch the Volume Id for the resource that is created in AWS?

    Refer to the documentation and look in the Attributes Reference section.

    Choose the correct attribute from those given. Attribute names are case sensistive.

  7. Another file called s3.tf has now been created. It too has a data source that will be used to read data of an existing s3 bucket.
    However, there is a mistake in the argument used. What is wrong here?

    This data source has an argument, which is the name of the bucket to get information on.

    Refer to the documentation and look in the Argument Reference section. You will see that there is only one argument, and it's not in agreement with what is in s3.tf, therefore the answer must be

    bucket_name is not a valid argument

  8. Information only.