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

[BUG] Not Possible Associate to Vnet Subnet created via terraform #8

Closed
fdmsantos opened this issue Sep 1, 2023 · 6 comments
Closed
Labels
bug Something isn't working

Comments

@fdmsantos
Copy link
Contributor

fdmsantos commented Sep 1, 2023

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 Version

1.5.6

AzureRM Provider Version

3.65.0

Affected Resource(s)/Data Source(s)

azurerm_app_service_virtual_network_swift_connection and azurerm_app_service_slot_virtual_network_swift_connection

Terraform Configuration Files

module "subnet" {
  source               = "claranet/subnet/azurerm"
  version              = "6.2.0"
  resource_group_name  = var.az_resource_group_name
  virtual_network_name = module.vnet[0].virtual_network_name
  custom_subnet_name   = "${var.name_prefix}-private-subnet"
  subnet_cidr_list     = ["10.0.0.16/28"]
  network_security_group_name = module.nsg[0].network_security_group_name
  subnet_delegation = {
    app-service = [
      {
        name    = "Microsoft.Web/serverFarms"
        actions = ["Microsoft.Network/virtualNetworks/subnets/action"]
      }
    ]
  }

  use_caf_naming = false
  location_short = ""
  client_name    = ""
  environment    = ""
  stack          = ""
}

And in function app module add:

app_service_vnet_integration_subnet_id = module.subnet.subnet_id 

Debug Output/Panic Output

╷
│ Error: Invalid count argument
│ 
│   on .terraform/modules/app-service/modules/container-web-app/r-appservice.tf line 673, in resource "azurerm_app_service_virtual_network_swift_connection" "app_service_vnet_integration":
│  673:   count          = var.app_service_vnet_integration_subnet_id == null ? 0 : 1
│ 
│ The "count" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around this, use the -target argument to first apply only
│ the resources that the count depends on.

│ Error: Invalid count argument
│ 
│   on .terraform/modules/app-service/modules/container-web-app/r-appservice.tf line 679, in resource "azurerm_app_service_slot_virtual_network_swift_connection" "app_service_slot_vnet_integration":
│  679:   count          = var.staging_slot_enabled && var.app_service_vnet_integration_subnet_id != null ? 1 : 0
│ 
│ The "count" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around this, use the -target argument to first apply only
│ the resources that the count depends on.

Expected Behaviour

It's not possible associate app service to Vnet Subnet if the Subnet is also created in terraform. Because the resources are depending from count keyword, where the count value cannot be determined until apply.

Expected Behaviour: Azure Web App deployed on subnet.

Actual Behaviour

Terraform error

Steps to Reproduce

No response

Important Factoids

No response

References

No response

@fdmsantos fdmsantos added the bug Something isn't working label Sep 1, 2023
@BzSpi
Copy link
Contributor

BzSpi commented Sep 4, 2023

Hello @fdmsantos

Thank you for opening this issue.
Unfortunately, this is a Terraform limitation. See here and here.
Even if we try to do our best building modules to avoid dealing with this issue, we sometimes encounter it.
I'm afraid that your only solution is to target the creation of your subnet and do a second full apply.

@fdmsantos
Copy link
Contributor Author

fdmsantos commented Sep 4, 2023 via email

@BzSpi
Copy link
Contributor

BzSpi commented Sep 4, 2023

You're right, we have it on some modules.

Also, we've removed the swift resource for function-app but not app-service and cannot remember why. Let me check.

@fdmsantos
Copy link
Contributor Author

hi @BzSpi ,

Any news?

Thanks

@BzSpi
Copy link
Contributor

BzSpi commented Sep 19, 2023

Hi @fdmsantos

Sorry for the delay. We have previously experienced issues with the VNet integration in the app service resource, it may have been fixed now.
We've added it in our internal backlog but feel free to suggest an implementation.

@Shr3ps
Copy link
Member

Shr3ps commented Oct 20, 2023

@Shr3ps Shr3ps closed this as completed Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants