Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving a module with "terraform state mv" loses "data." prefix for data.aws_redshift_service_account resource #16051

Closed
Chili-Man opened this issue Sep 8, 2017 · 12 comments
Assignees

Comments

@Chili-Man
Copy link
Contributor

Terraform Version

aws_redshift_service_account

Terraform Configuration Files

# ./module/redshiftdata.tf
provider "aws" {
  region = "us-west-2"
}

variable "regions" {
  type = "map"

  default = {
    "0" = "us-west-1"
    "1" = "us-west-2"
    "2" = "us-east-1"
    "3" = "us-east-2"
  }
}

data "aws_redshift_service_account" "main" {
  count  = "${length(var.regions)}"
  region = "${var.regions[count.index]}"
}
#./main.tf
module "rs_data" {
  source = "./module/redshiftdata"
}

Expected Behavior

With the above module layout, after running terraform apply you should be able to rename a module:

terraform apply
terraform state mv module.rs_data module.rs_data_renamed
terraform plan

Actual Behavior

Error refreshing state: 4 error(s) occurred:

* module.opengov_shared.module.redshift_shared_resources.aws_redshift_service_account.main[1]: aws_redshift_service_account.main.1: unknown resource type: aws_redshift_service_account
* module.opengov_shared.module.redshift_shared_resources.aws_redshift_service_account.main[2]: aws_redshift_service_account.main.2: unknown resource type: aws_redshift_service_account
* module.opengov_shared.module.redshift_shared_resources.aws_redshift_service_account.main[3]: aws_redshift_service_account.main.3: unknown resource type: aws_redshift_service_account
* module.opengov_shared.module.redshift_shared_resources.aws_redshift_service_account.main[0]: aws_redshift_service_account.main.0: unknown resource type: aws_redshift_service_account

References

As a work around, you can manually add the data prefix to the state and that fixes the above issue.
This issue is very similar to #9996

@apparentlymart
Copy link
Contributor

Hi @Chili-Man! Sorry for this broken behavior.

Indeed this does look a lot like #9996. The fix that was added for that does still seem to be in place, so looks like the problem is elsewhere this time. We'll take a look.

@jbardin jbardin self-assigned this Sep 8, 2017
@jbardin
Copy link
Member

jbardin commented Sep 11, 2017

Hi @Chili-Man,

What version of Terraform was this run with?

I'm not able to reproduce the error you have here. It is expected that renaming the module but not updating the config will "lose" the existing resources, but the data prefix seems to be correct.

This exercise does lead to another bug where orphaned module resources aren't destroyed however. I'll have to see if there's another duplicate of that somewhere.

@seongkkim
Copy link

seongkkim commented Sep 27, 2017

@apparentlymart , @jbardin +1 on this.
I have the same issue moving the states for data.template_file.* as well as data.docker_registry_image.*
Is this something that is resource specific or something that needs to be fixed up from core?
@Chili-Man, not sure this might help you for now, but the work around is to call

  • terraform state mv module.rs_data module.data.rs_data_renamed.

Put explicit .data. in between.

@jbardin
Copy link
Member

jbardin commented Sep 28, 2017

@seongkki:

Do you happen to have an example that reproduces this issue for you? Testing the above with recent versions of Terraform works as expected.

@santi698
Copy link

santi698 commented Oct 2, 2017

Hi, I'm facing a similar issue with aws_vpc_endpoint_service in version v0.10.6, should I create a new issue?

@jbardin
Copy link
Member

jbardin commented Oct 3, 2017

Hi @santi698,

Yes, if you have the details to reproduce the issue, please open a new one and I can continue form there.

Thanks!

@seongkkim
Copy link

@jbardin , sorry for late update. Here is how to reproduce the problem.
Use this state for testing.

# source.tfstate

{
    "version": 3,
    "terraform_version": "0.10.6",
    "serial": 4,
    "lineage": "c6688121-8a05-412b-bf15-31f7c46bdaf5",
    "modules": [
        {
            "path": [
                "root"
            ],
            "resources": {
                "data.docker_registry_image.consul": {
                    "type": "docker_registry_image",
                    "depends_on": [],
                    "primary": {
                        "id": "sha256:7b17ec4c51b1aadfee313038687a22dd3477b967cd716e8a6f524d23d2eb8c00",
                        "attributes": {
                            "id": "sha256:7b17ec4c51b1aadfee313038687a22dd3477b967cd716e8a6f524d23d2eb8c00",
                            "name": "registry.int.ciscoccservice.com:5000/ccbu/consul:v482",
                            "sha256_digest": "sha256:7b17ec4c51b1aadfee313038687a22dd3477b967cd716e8a6f524d23d2eb8c00"
                        },
                        "meta": {},
                        "tainted": false
                    },
                    "deposed": [],
                    "provider": ""
                }
            },
            "depends_on": []
        }
    ]
}

When I run terraform state list -state=source.tfstate, this spits out

docker_registry_image.consul`

With this state, I performed
terraform state mv -state=source.tfstate -state-out=dest.tfstate docker_registry_image.consul docker_registry_image.consul

and dest.tfstate look as follow:

# dest.tfstate
{
    "version": 3,
    "serial": 1,
    "lineage": "52e464d3-cc2f-4923-bf5b-ae51c878e794",
    "modules": [
        {
            "path": [
                "root"
            ],
            "outputs": {},
            "resources": {
                "docker_registry_image.consul": {
                    "type": "docker_registry_image",
                    "depends_on": [],
                    "primary": {
                        "id": "sha256:7b17ec4c51b1aadfee313038687a22dd3477b967cd716e8a6f524d23d2eb8c00",
                        "attributes": {
                            "id": "sha256:7b17ec4c51b1aadfee313038687a22dd3477b967cd716e8a6f524d23d2eb8c00",
                            "name": "registry.int.ciscoccservice.com:5000/ccbu/consul:v482",
                            "sha256_digest": "sha256:7b17ec4c51b1aadfee313038687a22dd3477b967cd716e8a6f524d23d2eb8c00"
                        },
                        "meta": {},
                        "tainted": false
                    },
                    "deposed": [],
                    "provider": ""
                }
            },
            "depends_on": []
        }
    ]
}

You can see

                "docker_registry_image.consul": {
                    "type": "docker_registry_image",......

data. prefix is missing from docker_registry_image.consul.

This is with terraform 0.10.6.

Thank you and let me know if this is uncertain.

@jbardin
Copy link
Member

jbardin commented Oct 3, 2017

Thanks @seongkki, that gives me exactly what I needed.
It seems that data sources are being selected without the data prefix.

@seongkkim
Copy link

@jbardin Great, would this be in the queue for a fix? Thanks alot

@jbardin jbardin removed the modules label Oct 4, 2017
@apparentlymart apparentlymart added cli and removed core labels Nov 7, 2018
@joshk0
Copy link

joshk0 commented Aug 15, 2019

still hitting this on 0.11.14

@hashibot
Copy link
Contributor

Hello! 🤖

This issue relates to an older version of Terraform that is no longer in active development, and because the area of Terraform it relates to has changed significantly since the issue was opened we suspect that the issue is either fixed or that the circumstances around it have changed enough that we'd need an updated issue report in order to reproduce and address it.

If you're still seeing this or a similar issue in the latest version of Terraform, please do feel free to open a new bug report! Please be sure to include all of the information requested in the template, even if it might seem redundant with the information already shared in this issue, because the internal details relating to this problem are likely to be different in the current version of Terraform.

Thanks!

@ghost
Copy link

ghost commented Sep 27, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Sep 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants