Home > OS >  Error while restoring RDS DB Instance using terraform
Error while restoring RDS DB Instance using terraform

Time:09-02

Can someone please tell me what I'm doing wrong here. I am trying to import a newly-restored RDS instance into terraform state

I have application module that calls a core-module from company's repository

\applications\rds\main.tf

module "rds" {
  source                  = "git::https://mysource-control/public/core-modules//aws/rds/rds?ref=v3.5.0" 

}

then I have root environment specific module that calls application module

\env\us-west-2\qa\rds\main.tf

module "rds" {
  source                     = "../../../../applications/rds"
}

On import I am getting error

C:\....\env\us-west-2\qa\rds>terraform import module.rds.module.rds qa-db-instane

Error: Invalid address │ │ on line 1: │ 1: module.rds.module.rds │ │ A resource instance address is required here. The module path must be followed by a resource instance specification. ╵

For information on valid syntax, see: https://www.terraform.io/docs/cli/state/resource-addressing.html

CodePudding user response:

In the official documentation there is an example for importing RDS instances https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_instance#import

You'll notice they mention aws_db_instance.default which is the Terraform resource name, followed by whatever you've named it.

In your case if the underlying resource in your nested module (for example sake, say it's called my_db) you'll be able to go

terraform import module.rds.module.rds.aws_db_instance.my_db qa-db-instance
  • Related