yuga05
yuga05

Reputation: 1

Creating terraform modules

I already have terraform code in different folders, each having its resources individually, the state file in remote S3.

Eg:- ec2-solr
ec2-setup\

Requirement is to create a main module calling this root configurations files, I have copied the backend.tf from the root module into main and setup the variables. The problem, is when I now run terraform plan from the main module tf is saying new resource to be created.

Is there a way, to import the state into the main module?

terraform v - "0.12.29" provider.aws: version = "~> 3.37"

Upvotes: 0

Views: 251

Answers (1)

John Skiles Skinner
John Skiles Skinner

Reputation: 2028

The command terraform state mv allows you to hook a remote object up to a new (or renamed or moved) resource instance.

This documentation gives the example of moving a resource into a module like this:

terraform state mv aws_instance.foo module.web

Upvotes: 2

Related Questions