You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a public IP, and a load balancer that uses it (and hence depends on it).
Simultaneously delete the public IP and remove it from the load balancer.
Since the load balancer depends on the public IP, I'd expect the load balancer to be modified before the public IP is deleted. However, Terraform doesn't recognize that dependency and instead tries to delete the public IP at the same time it's modifying the load balancer - resulting in Azure (correctly) complaining.
# terraform apply
azurerm_resource_group.rg: Refreshing state... [id=/subscriptions/xxxx/resourceGroups/nmiron-dependency-test-rg]
azurerm_public_ip.pip: Refreshing state... [id=/subscriptions/xxxx/resourceGroups/nmiron-dependency-test-rg/providers/Microsoft.Network/publicIPAddresses/pip]
azurerm_lb.lb: Refreshing state... [id=/subscriptions/xxxx/resourceGroups/nmiron-dependency-test-rg/providers/Microsoft.Network/loadBalancers/lb]
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
~ update in-place
- destroy
Terraform will perform the following actions:
# azurerm_lb.lb will be updated in-place
~ resource "azurerm_lb" "lb" {
id = "/subscriptions/xxxx/resourceGroups/nmiron-dependency-test-rg/providers/Microsoft.Network/loadBalancers/lb"
location = "westus"
name = "lb"
private_ip_addresses = []
resource_group_name = "nmiron-dependency-test-rg"
sku = "Basic"
tags = {}
- frontend_ip_configuration {
- inbound_nat_rules = [] -> null
- load_balancer_rules = [] -> null
- name = "PublicIPAddress" -> null
- outbound_rules = [] -> null
- private_ip_address_allocation = "Dynamic" -> null
- public_ip_address_id = "/subscriptions/xxxx/resourceGroups/nmiron-dependency-test-rg/providers/Microsoft.Network/publicIPAddresses/pip" -> null
- zones = [] -> null
}
}
# azurerm_public_ip.pip will be destroyed
- resource "azurerm_public_ip" "pip" {
- allocation_method = "Static" -> null
- id = "/subscriptions/xxxx/resourceGroups/nmiron-dependency-test-rg/providers/Microsoft.Network/publicIPAddresses/pip" -> null
- idle_timeout_in_minutes = 4 -> null
- ip_address = "40.78.94.7" -> null
- ip_version = "IPv4" -> null
- location = "westus" -> null
- name = "pip" -> null
- public_ip_address_allocation = "Static" -> null
- resource_group_name = "nmiron-dependency-test-rg" -> null
- sku = "Basic" -> null
- tags = {} -> null
- zones = [] -> null
}
Plan: 0 to add, 1 to change, 1 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
azurerm_public_ip.pip: Destroying... [id=/subscriptions/xxxx/resourceGroups/nmiron-dependency-test-rg/providers/Microsoft.Network/publicIPAddresses/pip]
azurerm_lb.lb: Modifying... [id=/subscriptions/xxxx/resourceGroups/nmiron-dependency-test-rg/providers/Microsoft.Network/loadBalancers/lb]
azurerm_lb.lb: Still modifying... [id=/subscriptions/xxxx...ers/Microsoft.Network/loadBalancers/lb, 10s elapsed]
azurerm_lb.lb: Modifications complete after 11s [id=/subscriptions/xxxx/resourceGroups/nmiron-dependency-test-rg/providers/Microsoft.Network/loadBalancers/lb]
Error: Error deleting Public IP "pip" (Resource Group "nmiron-dependency-test-rg"): network.PublicIPAddressesClient#Delete: Failure sending request: StatusCode=400 -- Original Error: Code="PublicIPAddressCannotBeDeleted" Message="Public IP address /subscriptions/xxxx/resourceGroups/nmiron-dependency-test-rg/providers/Microsoft.Network/publicIPAddresses/pip can not be deleted since it is still allocated to resource /subscriptions/xxxx/resourceGroups/nmiron-dependency-test-rg/providers/Microsoft.Network/loadBalancers/lb/frontendIPConfigurations/PublicIPAddress. In order to delete the public IP, disassociate/detach the Public IP address from the resource. To learn how to do this, see aka.ms/deletepublicip." Details=[]
Expected Behavior
Terraform updates the load balancer to not reference the public IP.
Terraform then deletes the public IP.
Actual Behavior
Terraform attempts to perform the two steps simultaneously, resulting in an error.
Note that this still happens even if you manually add depends_on = ["azurerm_public_ip.pip"] to the load balancer - since you of course need to delete this line when you delete the public IP.
Steps to Reproduce
Create the .tf file above
set TF_LOG=DEBUG
terraform init, terraform apply
Inspect terraform.tfstate: notice that the load balancer correctly depends on the public IP. Inspect the logs, and note the following line: ReferenceTransformer: "azurerm_lb.lb" references: [azurerm_resource_group.rg azurerm_public_ip.pip]`
Modify the .tf file above: remove the public IP, and remove the frontend_ip_configuration block from the load balancer (or just use lb-dependency-test.tf-2 from the Gist above).
terraform apply
Inspect the debug logs from step 5, and note the following line: ReferenceTransformer: "azurerm_lb.lb" references: [azurerm_resource_group.rg]. No dependency on the public IP even though it was in the state file!
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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
ghost
locked and limited conversation to collaborators
Mar 27, 2020
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
bugcorev0.12Issues (primarily bugs) reported against v0.12 releases
Summary
I'm doing the following:
Since the load balancer depends on the public IP, I'd expect the load balancer to be modified before the public IP is deleted. However, Terraform doesn't recognize that dependency and instead tries to delete the public IP at the same time it's modifying the load balancer - resulting in Azure (correctly) complaining.
Terraform Version
Terraform Configuration Files
Debug Output
Full output: https://gist.github.com/nitzanm/f228bace457dd657b7a5f4c671faa09c
Summary output:
Expected Behavior
Actual Behavior
Terraform attempts to perform the two steps simultaneously, resulting in an error.
Note that this still happens even if you manually add
depends_on = ["azurerm_public_ip.pip"]
to the load balancer - since you of course need to delete this line when you delete the public IP.Steps to Reproduce
terraform init
,terraform apply
lb-dependency-test.tf-2
from the Gist above).terraform apply
ReferenceTransformer: "azurerm_lb.lb" references: [azurerm_resource_group.rg]
. No dependency on the public IP even though it was in the state file!Additional Context
References
The text was updated successfully, but these errors were encountered: