Free Terraform Associate Exam Braindumps (page: 37)

Page 36 of 113

You want to use terraform import to start managing infrastructure that was not originally provis ioned through infrastructure as code. Before you can import the resource's current state, what must you do in order to prepare to manage these resources using Terraform?

  1. Run terraform refresh to ensure that the state file has the latest information for existing resources.
  2. Update the configuration file to include the new resources.
  3. Shut down or stop using the resources being imported so no changes are inadvertently missed.
  4. Modify the Terraform state file to add the new resources.

Answer(s): B

Explanation:

The current implementation of Terraform import can only import resources into the state. It does not generate configuration. A future version of Terraform will also generate configuration.
Because of this, prior to running terraform import it is necessary to write manually a resource configuration block for the resource, to which the imported object will be mapped.
The terraform import command is used to import existing infrastructure.
To import a resource, first write a resource block for it in our configuration, establishing the name by which it will be known to Terraform.
Example:
resource "aws_instance" "import_example" { # ...instance configuration...
}
Now terraform import can be run to attach an existing instance to this resource configuration.
$ terraform import aws_instance.import_example i-03efafa258104165f aws_instance.import_example: Importing from ID "i-03efafa258104165f"... aws_instance.import_example: Import complete!
Imported aws_instance (ID: i-03efafa258104165f) aws_instance.import_example: Refreshing state... (ID: i-03efafa258104165f) Import successful!
The resources that were imported are shown above. These resources are now in your Terraform state and will henceforth be managed by Terraform.
This command locates the AWS instance with ID i-03efafa258104165f (which has been created outside Terraform) and attaches its existing settings, as described by the EC2 API, to the name aws_instance.import_example in the Terraform state.



Which of the below terraform commands do not run terraform refresh implicitly before taking actual action of the command?

  1. terraform apply
  2. terraform destroy
  3. terraform init
  4. terraform import
  5. terraform plan

Answer(s): C,D


Reference:

https://www.terraform.io/docs/commands/refresh.html



You want to use different AMI images for different regions and for the purpose you have defined following code block.

1. variable "images" 2. {
3. type = "map" 4.
5. default = {
6. us-east-1 = "image-1234"
7. us-west-2 = "image-4567"
8. us-west-1 = "image-4589" 9. }
10. }

What of the following approaches needs to be followed in order to select image-4589?

  1. var.images["us-west-1"]
  2. var.images[3]
  3. var.images[2]
  4. lookup(var.images["us-west-1"]

Answer(s): A



By default, a defined provisioner is a creation-time provisioner.

  1. True
  2. False

Answer(s): A


Reference:

https://www.terraform.io/docs/provisioners/index.html






Post your Comments and Discuss HashiCorp Terraform Associate exam with other Community members:

Terraform Associate Discussions & Posts