Terraform: Terraform 0.9.x "forgot" about OpsWorks resources

Created on 18 Mar 2017  ·  22Comments  ·  Source: hashicorp/terraform

Hi there,

I'd like to report an issue with the upgrade to Terraform 0.9.0. It seems to be ignoring the existing OpsWorks resources I have in my state files, and it is attempting to re-create them.

Terraform Version

Terraform v0.9.0

Affected Resource(s)

  • aws_opsworks_stack
  • aws_opsworks_nodejs_app_layer
  • aws_opsworks_instance
  • aws_opsworks_application

Terraform Configuration Files

resource "aws_opsworks_stack" "admin" {
  name                          = "admin"
  region                        = "${var.region}"
  service_role_arn              = "${var.iam_role}"
  default_instance_profile_arn  = "${var.iam_profile}"
  vpc_id                        = "${var.vpc}"
  default_subnet_id             = "${var.subnet_a}"
  default_os                    = "Ubuntu 14.04 LTS"
  configuration_manager_version = "11.10"
  default_ssh_key_name          = "${var.key_name}"
  hostname_theme                = "Wild_Cats"
}

Expected Behavior

After running terraform init to migrate the remote state from 0.8.x to 0.9.x, it correctly imported all the resources, including the ones above. A subsequent terraform plan should have yielded no plan changes, as terraform state list shows the existing resources.

Actual Behavior

A terraform plan offered to re-create all OpsWorks resources. Furthermore, terraform import did not work, stating imported resources would collide with existing ones.

Steps to Reproduce

  1. terraform init
  2. terraform plan

Important Factoids

Replicated across three different AWS accounts, using three different environments (with shared modules).

bug provideaws

All 22 comments

$ terraform import module.admin.aws_opsworks_stack.admin long-id-goes-here
module.admin.aws_opsworks_stack.admin: Importing from ID "long-id-goes-here"...
module.admin.aws_opsworks_stack.admin: Import complete!
  Imported aws_opsworks_stack (ID: long-id-goes-here)
Error importing: 1 error(s) occurred:

* module.admin.aws_opsworks_stack.admin (import id: long-id-goes-here): Can't import module.admin.aws_opsworks_stack.admin, would collide with an existing resource.

Please remove or rename this resource before continuing.

Issue verified to exist in 0.9.1 too.

Hey @rafaelmagu – sorry you're having this issue. I'm investigating this and I have a suspicion, can you let me know what region(s) you're using? Or less specific, are you using us-east-1?

Hi @catsby, all my resources are in us-west-2.

Thanks @rafaelmagu – I believe I know the issue, and I'm working on a solution. Thank you for your patience

Hey @rafaelmagu another question – you say all your resources are in us-west-2, is that what the value of ${var.region} is above? Can you log into the AWS console and still see the ops works stack you're expecting, and confirm the region for me?

Yup. All resources appear intact in Oregon, and I can also see them when I do a terraform state list. ${var.region} is set to us-west-2.

Hey @rafaelmagu – I'm working on a patch for this, I hope to open the PR today. Sorry for the trouble here

Update: I've made progress but still don't have the patch quite ready. I had to add some things to opsworks and the testing framework to test this. Hopeful for tomorrow

Thank you for the work you've put in so far @catsby! Greatly appreciated.

Hey @rafaelmagu – I've opened https://github.com/hashicorp/terraform/pull/13024 which should address this. Included is a short description of what happened as well. Please let me know if you have any questions!

And thanks again for the patience 😄

@rafaelmagu So I believe we have fixed this in #13024 - this was released in Terraform 0.9.2

Let me know if this isn't the case :)

@stack72 I got 0.9.2 and ran terraform plan, and the resources are still marked for creation. Should a simple terraform import ... do the trick?

For the record, import didn't work either.

I have the same problem, not fixed with 0.9.2.

I think it might work for the stack but not the layers or instances.
Can this issue be re-opened? Or would you rather have a new issue?

I have the same problem too and I found a workaround for this. You can have another AWS provider which points to us-east-1 (The region where original OpsWorks endpoint lives) and set it in your opsworks resources. See https://www.terraform.io/docs/configuration/providers.html fore more detail about multiple providers.

Hope it helps.

@nabeken Thanks for sharing your workaround! It works and it is quite clean 😄

EDIT: It worked for one of our environment but Terraform still can't detect the opsworks resources in another environment.. it's really weird. Will update if I figure out the solution.

Hey all thanks for the updates –

Can each of you clarify which resources are not being found? opsworks_stack _should_ be patched here in the _v0.9.2_. I need to know both if it's not, or if this affects other resources (and which ones).

Thanks! Sorry for the trouble here.

@catsby opsworks_stack isn't patched on my plans.

I've opened a new issue. The further discussions should go to https://github.com/hashicorp/terraform/issues/13483.

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.

Was this page helpful?
0 / 5 - 0 ratings