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

broken data azurerm_subnet route_table_id: not functioning #1337

Closed
bernadinm opened this issue Jun 2, 2018 · 4 comments
Closed

broken data azurerm_subnet route_table_id: not functioning #1337

bernadinm opened this issue Jun 2, 2018 · 4 comments

Comments

@bernadinm
Copy link

bernadinm commented Jun 2, 2018

Terraform Version

$ terraform -v
Terraform v0.11.7
+ provider.azurerm v1.5.0

Affected Resource(s)

data "azurerm_subnet" "public" {
  name                 = "cisco-csr-subnet-public"
  virtual_network_name = "${data.azurerm_virtual_network.current.name}"
  resource_group_name  = "${data.azurerm_resource_group.rg.name}"
  route_table_id       = "${azurerm_route_table.RTPublic.id}" # Not functioning 
}

Debug Output

Error: data.azurerm_subnet.public: "route_table_id": this field cannot be set

Panic Output

Expected Behavior

I expected that an existing subnet will be associated with an existing routing table.

Actual Behavior

Terraform failed.

Steps to Reproduce

  1. terraform apply

Important Factoids

There does not see to be any other way to do this in terraform. The data resource is the most appropriate resource to achieve linking an existing subnet to a routing table. Currently it is possible within the Azure Portal UI to associate the subnet to the routing table, but not with terraform at the moment.

@bernadinm bernadinm changed the title data azurerm_subnet route_table_id not functioning broken data azurerm_subnet route_table_id not functioning Jun 5, 2018
@bernadinm bernadinm changed the title broken data azurerm_subnet route_table_id not functioning broken data azurerm_subnet route_table_id: not functioning Jun 5, 2018
@tombuildsstuff
Copy link
Contributor

hi @bernadinm

Thanks for opening this issue, apologies for the delayed response here!

Data Sources in Terraform are for referencing information about existing resources (e.g. getting the ID of a Storage Account) - rather than for modifying information about them.

It's possible to import an existing resource into Terraform using theterraform import command - which can then be managed via the azurerm_route_table Resource. for instance here's how to import a Route Table into the State:

terraform import azurerm_route_table.test /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/routeTables/mytable1

Once the existing Resource has been imported into Terraform, it's then possible to change the value of this property via the azurerm_route_table resource. Would you be able to take a look and see if this resolves your issue?

Since this is a question about Terraform rather than a bug in Terraform - I'm going to close this issue for the moment (but we'll continue to take a look/respond 😄)

Thanks!

@bernadinm
Copy link
Author

Thank you @tombuildsstuff, if this is the case then what we're missing is this resource here route_table_association in the same way we have it for AWS.

https://www.terraform.io/docs/providers/aws/r/route_table_association.html

Do you recommend me making a separate feature request to ask for this resource in terraform-provider-azurerm provider?

data "azurerm_subnet" "public" {
  name                 = "mysubnet"
  virtual_network_name = "some-resource-group"
}

data "azurerm_route_table" "test" {
  name                = "myroutetable"
  resource_group_name = "some-resource-group"
}

resource "azurerm_route_table_association" "a" {
  subnet_id      = "${data.azurerm_subnet.public.id}"
  route_table_id = "${data.azurerm_route_table.test.id}"
}

@tombuildsstuff
Copy link
Contributor

hi @bernadinm

Unfortunately the Azure API isn't designed in such a way that this is possible (in general the API generally prefers creating monolithic resources rather than composable resources) - whilst it technically is possible to implement this resource by hacking around the azurerm_subnet resource, it'd lead to us having conflicts with that resource; as such the only way we could implement this safely would be to deprecate the field route_table_id from the subnet resource in favour of this new resource.

That said - I think this could make sense as a change but needs some more thought; would you mind opening a new issue specifically about this?

Thanks!

@ghost
Copy link

ghost commented Mar 30, 2020

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 👉 [email protected]. Thanks!

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

2 participants