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-provider-azurerm fails to identify dependencies #2629

Closed
juanjojulian opened this issue Jan 9, 2019 · 3 comments
Closed

terraform-provider-azurerm fails to identify dependencies #2629

juanjojulian opened this issue Jan 9, 2019 · 3 comments

Comments

@juanjojulian
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.11

  • provider.azurerm v1.20.0

Affected Resource(s)

*azurerm_public_ip
*azurerm_resource_group

Terraform Configuration Files

resource "azurerm_resource_group" "main" {
  name     = "${var.sub-name}-${var.region}-${var.aplication}-rg"
  location = "${var.region}"
}

resource "azurerm_public_ip" "main" {
  count                = "${var.public_ip == "true" ? 1 : 0}"
  name                 = "${var.sub-name}-${var.region}-${var.hostname}-PublicIP${count.index}"
  location             = "${var.region}"
  resource_group_name  = "${var.sub-name}-${var.region}-${var.aplication}-rg"
  public_ip_address_allocation = "${var.public_ip_alloc}"
}

Expected Behavior

Terraform should understand that the resource group should be created prior to attempting the public ip creation.

Actual Behavior

Error: Error applying plan:

1 error(s) occurred:

* module.XXX.azurerm_public_ip.main: 1 error(s) occurred:

* azurerm_public_ip.main: Error Creating/Updating Public IP "XXX-PublicIP0" (Resource Group "XXX-rg"): network.PublicIPAddressesClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code="ResourceGroupNotFound" Message="Resource group 'XXX-rg' could not be found."

###NOTE
This problem is solved using depends_on = ["azurerm_resource_group.main"] but as per Terraform documentation this should not be necessary as Terraform should solve all dependencies.

@tombuildsstuff
Copy link
Member

hey @juanjojulian

Thanks for opening this issue :)

Terraform infers the dependencies between resources in one of two ways - ether using an Implicit Dependency or using an Explicit Dependency.

We'd recommend using an Implicit Dependency where possible - which is where you use the Interpolation Syntax to reference between resources, for example:

resource "azurerm_resource_group" "main" {
  name     = "example-resource-group"
  location = "West Europe"
}
resource "azurerm_public_ip" "main" {
  name                 = "my-example-public-ip"
  location             = "${azurerm_resource_group.main.location}"
  resource_group_name  = "${azurerm_resource_group.main.name}"
  public_ip_address_allocation = "Dynamic"
}

The other approach would be to use an Explicit Dependency which can be achieved using the depends_on parameter - but we'd recommend using an Implicit Dependency where possible (since it means you don't need to keep this extra parameter up to date). Without the dependency information (either an Implicit or Explicit Dependency) Terraform doesn't know these resources rely on one another - which means it believes it can create them in parallel (which is why you're seeing this error about the Resource Group not existing).

Would you be able to take a look and see if using an Implicit Dependency works for you? Since this is a question about Terraform Configuration rather than a bug in Terraform, I'm going to close this issue for the moment (but we'll continue responding 😄)

Thanks!

@juanjojulian
Copy link
Contributor Author

Thanks Tom, I will try using interpolation syntax :-)

@ghost
Copy link

ghost commented Mar 5, 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!

@hashicorp hashicorp locked and limited conversation to collaborators Mar 5, 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

3 participants