When should you write Terraform configuration files for existing infrastructure that you want to start managing with Terraform?
When should you write Terraform configuration files for existing infrastructure that you want to start managing with Terraform?
To import existing infrastructure into Terraform, you must first write the corresponding Terraform resource block in your configuration files. This block establishes how the resource will be known and managed in Terraform. Once the configuration is written, you can then use the terraform import command to associate the existing resource with this configuration. Terraform does not automatically generate configuration files for existing resources, hence it is essential to create these files beforehand.
A is the correct answer !
D: You can use the import command to migrate existing resources into your Terraform state file. The import command does not currently generate the configuration for the imported resource, so you must write the corresponding configuration block to map the imported resource to it. Importing infrastructure involves five steps: 1 Identify the existing infrastructure you will import. 2 Import infrastructure into your Terraform state file. 3 Write Terraform configuration that matches that infrastructure. 4 Review the Terraform plan to ensure the configuration matches the expected state and infrastructure. 5 Apply the configuration to update your Terraform state. Source: https://developer.hashicorp.com/terraform/tutorials/state/state-import
Answer is A. Source: https://developer.hashicorp.com/terraform/tutorials/state/state-import. Has been updated with new steps for Terraform v1.5 Using configuration to import resources involves the following steps: Identify the existing infrastructure you will import. Define an import block for the resources. Run terraform plan to review the import plan and optionally generate configuration for the resources. Prune generated configuration to only the required arguments. Apply the configuration to bring the resource into your Terraform state file.
But that is your "Import config", It is not the "existing infra config"
A: You need to have the corresponding resources defined in your Terraform configuration files before you can import them.
D. After you run terraform import
as per terraform 1.0 which is the latest version for exam its B. You can import infrastructure without corresponding Terraform code
You cannot import the resource unless the resource's basic block is not coded in the .tf file. Hence this is the 1st step. Once a basic block is written, you import the resources and enhance the code using the state details. <b> Before you run terraform import </b>
Please refer to this link https://developer.hashicorp.com/terraform/cli/import/usage It is said: "To import a resource, first write a resource block for it in your configuration, establishing the name by which it will be known to Terraform ... Now terraform import can be run to attach an existing instance to this resource configuration"
"To import a resource, first write a resource block for it in your configuration, establishing the name by which it will be known to Terraform" Answer is A. https://developer.hashicorp.com/terraform/cli/import/usage
1. Run terraform import to bring the existing resources under Terraform management. This command allows you to import the existing resources into the Terraform state without the corresponding Terraform configuration files. 2.After importing the resources, you should write the Terraform configuration files to define and manage the imported resources. These configuration files specify the desired state of the infrastructure and allow you to make changes to it in a controlled manner.
https://spacelift.io/blog/importing-exisiting-infrastructure-into-terraform
Answer is D
If D is right then B is necesarry right, and since its not multiple choice, it can only be A Right answer : A
A is correct
When should you write Terraform configuration files for existing infrastructure that you want to start managing with Terraform? A. Before you run terraform import.
Tested
Condidering and existing infrastructurre on a cloud provider, in order to manage these resources on terraform you need: 1. foreach resource, add at least the resources definition using resource_type.resource_name {} 2. foreach resource, use terraform import resource_type.resource_name <id>
which one right A or D?