Import existing resources into Terraform to manage them with infrastructure as code
terraform.tfstate
. Every change to a .tf
file will be compared with the Terraform state to determine what changes need to be made.
Here is an example of a .tfstate
file:
terraform refresh
before terraform plan
.
terraform state
command
to edit it in a more controlled environment..tf
fileimport
block with two attributes
terraform plan
should render something like this:
terraform plan
again. If everything looks good, run terraform apply
to import the resource:
lsh
command in your terminal to access your infrastructure.
For example, to find the IDs of your tags, run lsh tags list
.
for_each
keyword to loop over the objects and get their key-value pair to build our resource. Running terraform apply
should import the servers successfully.
terraform plan
before applying your changes to verify the changes
that will be made.projectID:resourceID
. This is needed for nested resources. On the provider documentation, you can verify if a resource is a nested resource or not.
To automatically generate the resource blocks, run:
generated_resources.tf
file with the resource blocks of the remaining infrastructure. Generating configuration is still an experimental feature, and it’s highly encouraged for you to verify the generated resources.
You can edit and organize resources in different files. When you’ve finished verifying the generated resources, run terraform apply
to finish your configuration.
Now you know everything needed to import your existing Latitude.sh infrastructure to Terraform.
Happy coding!