_This issue was originally opened by @swapnild2111 as hashicorp/terraform#26227. It was migrated here as a result of the provider split. The original body of the issue is below._
Terraform v0.13.2
+ provider registry.terraform.io/hashicorp/azurerm v2.20.0
resource "azurerm_public_ip" "ingress-ip-legacy" {
name = "test-ingress-ip-1"
resource_group_name = "rg-sandbox"
location = "West Europe"
allocation_method = "Static"
sku = "Standard"
}
terraform import azurerm_public_ip.ingress-ip-legacy /subscriptions/xxxxxxxx/resourceGroups/rg-sandbox/providers/Microsoft.Network/publicIPAddresses/test-ip
terraform plan
Terraform will perform the following actions:
# azurerm_public_ip.ingress-ip-legacy must be replaced
-/+ resource "azurerm_public_ip" "ingress-ip-legacy" {
allocation_method = "Static"
+ fqdn = (known after apply)
~ id = "/subscriptions/xxxxxxxxxx/resourceGroups/rg-sandbox/providers/Microsoft.Network/publicIPAddresses/test-ip" -> (known after apply)
idle_timeout_in_minutes = 4
~ ip_address = "20.54.xxx.xxx" -> (known after apply)
ip_version = "IPv4"
location = "westeurope"
~ name = "test-ip" -> "test-ingress-ip-1" # forces replacement
- public_ip_prefix_id = "/subscriptions/xxxxxxx/resourceGroups/rg-sandbox/providers/Microsoft.Network/publicIPPrefixes/test-prefix" -> null # forces replacement
resource_group_name = "rg-sandbox"
sku = "Standard"
- tags = {
- "Self Managed" = "Yes"
} -> null
- zones = [] -> null
- timeouts {}
}
As mentioned above -
terraform import xxx
terraform plan
I have masked few things to be compliant with organisation.
Also same scenario doesn't work for azurerm_public_ip_prefix
Maybe I'm missing something, but the name is different between the imported resource and the name as defined in your template. This would always cause the resource to be recreated.
Thanks for opening this issue. After tested, seems I cannot repro this issue with latest azurerm provider and below repro steps. Could you have a try below tfconfig to check whether the issue still exists?
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-pip-tester2"
location = "eastus2"
}
resource "azurerm_public_ip" "test" {
name = "test-ingress-ip-1"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
allocation_method = "Static"
sku = "Standard"
}
terraform import azurerm_public_ip.test /subscriptions/xx-xx-xx-xx/resourceGroups/acctestRG-pip-tester2/providers/Microsoft.Network/publicIPAddresses/test-ingress-ip-1
tf plan
Go to Azure portal, go to some resource group, create a public static ip address directly on the portal.
Create main.tf with following content:
provider "azurerm" {
features {}
}
resource "azurerm_public_ip" "test" {
name = "test-ip"
resource_group_name = "rg"
location = "West Europe"
allocation_method = "Static"
sku = "Standard"
}
terraform initInitializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/azurerm...
- Installing hashicorp/azurerm v2.27.0...
- Installed hashicorp/azurerm v2.27.0 (signed by HashiCorp)
The following providers do not have any version constraints in configuration,
so the latest version was installed.
To prevent automatic upgrades to new major versions that may contain breaking
changes, we recommend adding version constraints in a required_providers block
in your configuration, with the constraint strings suggested below.
* hashicorp/azurerm: version = "~> 2.27.0"
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
terraform import azurerm_public_ip.test /subscriptions/xxx-xxx-xxx-xxx-xxx/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/test-ipazurerm_public_ip.test: Importing from ID "/subscriptions/xxx-xxx-xxx-xxx-xxx/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/test-ip"...
azurerm_public_ip.test: Import prepared!
Prepared azurerm_public_ip for import
azurerm_public_ip.test: Refreshing state... [id=/subscriptions/xxx-xxx-xxx-xxx-xxx/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/test-ip]
Import successful!
The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
terraform planRefreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
azurerm_public_ip.test: Refreshing state... [id=/subscriptions/xxx-xxx-xxx-xxx-xxx/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/test-ip]
------------------------------------------------------------------------
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement
Terraform will perform the following actions:
# azurerm_public_ip.test must be replaced
-/+ resource "azurerm_public_ip" "test" {
allocation_method = "Static"
+ fqdn = (known after apply)
~ id = "/subscriptions/xxx-xxx-xxx-xxx-xxx/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/test-ip" -> (known after apply)
idle_timeout_in_minutes = 4
~ ip_address = "x.x.x.x" -> (known after apply)
ip_version = "IPv4"
location = "westeurope"
name = "test-ip"
- public_ip_prefix_id = "/subscriptions/xxx-xxx-xxx-xxx-xxx/resourceGroups/rg/providers/Microsoft.Network/publicIPPrefixes/test-prefix" -> null # forces replacement
resource_group_name = "rg"
sku = "Standard"
- tags = {
- "Self Managed" = "Yes"
} -> null
- zones = [] -> null
- timeouts {}
}
Plan: 1 to add, 0 to change, 1 to destroy.
------------------------------------------------------------------------
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
Now if you see, it's actually going to destroy the existing IP and recreate it. In my infrastructure I have couple of IP's which are tied up with resources & those should not be re-created.
@swapnild2111 you need to add the matching properties into the Terraform schema, which is why this plan is showing changes - changing the Public IP from being one based on a public_ip_prefix_id (as it is in Azure) to without one locally requires recreation due to the way Azure works - however adding/removing the tags is possible without a recreation.
Since this should be fixed by updating the Terraform Configuration here, I'm going to close this issue for the moment - however you should be able to resolve this by adding matching values to the Terraform Configuration, which should make terraform plan run clean here :)
Thanks!
Thank you all for help :)
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!