How should we use terraform imports by using modules?

315    Asked by Unnatigautam in Salesforce , Asked on Sep 12, 2023

We have a big AWS setup built with Terraform. Since different regions are applied but in separate ways, we have most of the things in modules that are imported, like the below-mentioned code:

We also have S3 buckets, which were manually created. We have also tried to import it. But the terraform import command does not find any configuration file and error. It looks like this: 

Error: resource address "aws_s3_bucket.machine-learning" does not exist in the configuration.

Create the configuration in the root module before importing the resource like this: 

But the problem is the terraform plan or application finds the configuration and wants to form it. But I need something else.

Answered by Chris EVANS

The terraform import command uses the resource address syntax in the terraform import module. It is a way to talk about objects in a configuration that exists outside of that configuration. So, if you want to refer to resources declared in the child module, you should consider adding a module path at the beginning of the address:




You can also terraform plans if you need clarification on choosing the correct address for a particular resource instance. It helps to see the lesson that Terraform can create and use with Terraform import.

You can also use quoting or escaping to ensure the shell does not interpret those as its metacharacters. But pass them literally to Terraform.

You can also run the Terraform plan using the names in the output. You can use the main. tf

And modules/ aws-assets.tf

If you want to install the aws_s3_bucket module, you can run the command mentioned below:


Your Answer

Interviews

Parent Categories