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 does not wait for resource groups to be created #532

Closed
janboll opened this issue Nov 7, 2017 · 5 comments
Closed

Terraform does not wait for resource groups to be created #532

janboll opened this issue Nov 7, 2017 · 5 comments

Comments

@janboll
Copy link

janboll commented Nov 7, 2017

Hi there,

Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.

Terraform Version

Terraform v0.10.8

Affected Resource(s)

azurerm_resource_group

Terraform Configuration Files

Terraform file definition:

module "resoruce_group" {
  source = "../tf-modules/resource_group"
  rg_name_list = ["${var.rg_name_nsg}", "${var.rg_name_vnet}"]
  location = "${var.location}"
}

Module source:

resource "azurerm_resource_group" "resource_group_by_list" {
  count = "${length(var.rg_name_list)}"
  name = "${var.rg_name_list[count.index]}"
  location = "${var.location}"
}

Debug Output

* module.vnet.azurerm_virtual_network.vnet: 1 error(s) occurred:

* azurerm_virtual_network.vnet: network.VirtualNetworksClient#CreateOrUpdate: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceGroupNotFound" Message="Resource group 'XXX' could not be found."
* module.nsg.azurerm_network_security_group.NSG_by_count[0]: 1 error(s) occurred:

Expected Behavior

The resource group is created, follow up modules should execute and use the resource group without issue.

Actual Behavior

Resource group was created as expected, but Terraform crashes with 404 error. Repeated run of terraform then executes without any issues.

Steps to Reproduce

  1. terraform apply
    --> Resource group created, and error will show up
  2. terraform apply
    --> Resource group is used, no errors

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

@tombuildsstuff
Copy link
Contributor

Hey @janboll

Thanks for opening this issue :)

The issue you're seeing is an issue within Terraform Core where references between modules aren't ordered correctly in the graph - however if you were to create the Resource Group within the same file/folder structure as the Virtual Network the relationship should be inferred correctly.

There's an issue tracking this on Terraform Core here - however in the meantime I believe you should be able to create the Resource Group before calling the module to avoid this, like so:

resource "azurerm_resource_group" "test" {
   name = "foo"
  location = "West Europe"
}

module "network" {
  source = "./modules/network"
  resource_group_name = "${azurerm_resource_group.test.name}"
}

Would you be able to take a look and see if that solves your issue here?

Thanks!

@janboll
Copy link
Author

janboll commented Nov 8, 2017

Hi,

Thank you for the quick reply. I can confirm that this workaround is working.

Do you have dependencies for modules on the roadmap?

Thanks,
Jan

@tombuildsstuff
Copy link
Contributor

Hey @janboll

Thank you for the quick reply. I can confirm that this workaround is working.

That's great to hear :)

Do you have dependencies for modules on the roadmap?

It's being tracked in a couple of issues on Terraform Core (including this one) - but it's something we're aware of. As @jbardin has been doing a lot of work in this area, he's probably the best person to respond to that question.

Given there's nothing pending in this issue that's not being tracked elsewhere - I'm going to close this issue for the moment; however please feel free to re-open this issue if you're still having issues.

Thanks!

@rifaterdemsahin
Copy link

still having an issue on this one. Even i placed them into the same file

azurerm_app_service.catalogservices: azurerm_app_service.catalogservices: Error making Read request on AzureRM App Service Configuration "trnstgcatalogservices": web.AppsClient#GetConfiguration: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceGroupNotFound" Message="Resou

@tombuildsstuff
Copy link
Contributor

@rifaterdemsahin please open a new issue for this with the Terraform Configuration that you're using and we can take a look, in general this error generally is returned when there's no dependency ordering between the Resource Group and the App Service (or other resources used).

Thanks!

@hashicorp hashicorp locked as resolved and limited conversation to collaborators Aug 6, 2018
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