Reputation: 215
I want to run terragrunt import on an external module. (This resource exists in the real world and I want to pull it into my state).
# terragrunt.hcl
terraform {
source = "../../../../..//modules/environment"
}
inputs = {
env_list = [
{
name = "dev"
}
]
}
# modules/environments/main.tf
resource "confluentcloud_environment" "environment" {
provider = confluentcloudofficial
count = length(var.env_list)
display_name = var.env_list[count.index].name
}
terragrunt import 'confluentcloud_environment.enviroment[0]' env-299n2
is the command I'd use I think (I get this resource name from a terragrunt plan) but I'm left with this error:
Error: resource address "confluentcloud_environment.enviroment[0]" does not exist in the configuration.
Before importing this resource, please create its configuration in the root module. For example:
resource "confluentcloud_environment" "enviroment" { # (resource arguments) }
Is it possible to import existing state into Terraform (via Terragrunt) without first declaring it in a root main.tf?
Upvotes: 1
Views: 1307
Reputation: 1978
I got this error while moving stuff from Terraform to Terragrunt.
I used terraform state list
+ terraform state show <someresource
in the older project to later run terragrunt import
.
There was stuff shown in terraform state list
that weren't in sync with newer code. Long story short, I really didn't have the resource declared in newer Terragrunt module code. Double check that.
EXTRA: Also don't forget --terragrunt-source
attribute when pointing to modules on your local machine.
Upvotes: 0
Reputation: 215
Turns out all I needed to do was delete the contents in the .terragrunt-cache folder and try again. 3 days of my life...
Upvotes: 0