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

terraform "hijacks" resources that already exist #3562

Closed
AndyMoore opened this issue May 31, 2019 · 3 comments
Closed

terraform "hijacks" resources that already exist #3562

AndyMoore opened this issue May 31, 2019 · 3 comments

Comments

@AndyMoore
Copy link
Contributor

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

Terraform v0.11.13

  • provider.azurerm v1.29.0

Affected Resource(s)

noticed that if you try to create a resource that already exists within azure, terraform will automatically import it into its state, and take ownership of it

example: I've manually created a resource group and keyvault, both called "andytest"

I then add the resources to terraform config:

data "azurerm_client_config" "current" {}

resource "azurerm_resource_group" "andytest" {
  name     = "andytest"
  location = "${var.region}"
}

resource "azurerm_key_vault" "keyvault" {
  name                            = "andytest"
  location                        = "${azurerm_resource_group.andytest.location}"
  resource_group_name             = "${azurerm_resource_group.andytest.name}"
  tenant_id                       = "${data.azurerm_client_config.current.tenant_id}"

  enabled_for_disk_encryption     = true
  enabled_for_deployment          = true
  enabled_for_template_deployment = true

  sku {
    name = "standard"
  }
}

and run terraform apply

terraform not only applies successfully, but adds these to its state - this could inadvertently allow you to delete existing resources

Expected Behavior

In other providers (aws) terraform will notice a resource already exists, and refuse to apply over the top, or add to state without explicitly telling it to via a data source

Actual Behavior

in my case i applied a resource, noticed it clashed with something that already existed, renamed in terraform and ran apply again, and it deleted the existing resource

  • #0000
@tombuildsstuff
Copy link
Contributor

hi @AndyMoore

Thanks for opening this issue :)

This is planned to be fixed 2.0 (which is outlined here - the fix is already merged into the codebase (and is feature-flagged) - more information is available here.

Since this is planned to be fixed in 2.0 (and there's a workaround) I'm going to close this issue for the moment - but please subscribe to #2807 for updates.

Thanks!

@ghost
Copy link

ghost commented Jul 1, 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Jul 1, 2019
@ghost ghost unlocked this conversation Feb 24, 2020
@ghost
Copy link

ghost commented Feb 24, 2020

This has been released in version 2.0.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.0.0"
}
# ... other configuration ...

@ghost ghost locked and limited conversation to collaborators Feb 24, 2020
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

3 participants