terraform-provider-azurerm icon indicating copy to clipboard operation
terraform-provider-azurerm copied to clipboard

Sub resources (Virtual application) again getting added after terraform import

Open premchavhan99 opened this issue 3 years ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Community Note

  • Please vote on this issue by adding a :thumbsup: 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.1.1

AzureRM Provider Version

3.12.0

Affected Resource(s)/Data Source(s)

azurerm_windows_web_app

Terraform Configuration Files

resource "azurerm_windows_web_app" "app_web" {
  name                = terraform.workspace == "prod" ? "app-web" :"app-web-${terraform.workspace}"
  resource_group_name = var.rg_name
  location            = azurerm_service_plan.plan_web.location
  service_plan_id     = azurerm_service_plan.plan_web.id

  client_affinity_enabled = true

  site_config {
    always_on               = var.app_web_always_on
    ftps_state              = "AllAllowed"
    scm_minimum_tls_version = "1.0"
    use_32_bit_worker       = "false"

    virtual_application {
      physical_path = "site\\wwwroot"
      preload       = var.app_web_site_config_preload
      virtual_path  = "/"
    }
  }

  sticky_settings {
    app_setting_names = var.app_web_app_settings_names
  }

  tags = var.app__web_tag
}

Debug Output/Panic Output

# module.app_service.azurerm_windows_web_app.app_web will be updated in-place
  ~ resource "azurerm_windows_web_app" "app_web" {
        id                                = "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/rg-dev/providers/Microsoft.Web/sites/app-web"
        name                              = "app-web"
        tags                              = {
            "displayName"
                                          = "web"
            "hidden-related:/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/rg-dev/providers/Microsoft.Web/serverfarms/plan-web" = "Resource"
        }
        # (18 unchanged attributes hidden)



      ~ site_config {
            # (22 unchanged attributes hidden)


          + virtual_application {
              + physical_path = "site\\wwwroot"
              + preload       = true
              + virtual_path  = "/"
            }
            # (1 unchanged block hidden)
        }


        # (11 unchanged blocks hidden)
    }

Expected Behaviour

I have Imported a azurerm_windows_web_app into terraform, It already have virtual application but Terraform is trying to add it again and showing update in place changes image

Actual Behaviour

No response

Steps to Reproduce

No response

Important Factoids

No response

References

No response

premchavhan99 avatar Sep 20 '22 10:09 premchavhan99

Thanks @premchavhan99 for raising this issue, can you let me know the value of the always_on, is it true or false?

Also, are you able to reproduce it? if you can, can you share the virtual application value before terraform import with me? you can get the value by calling the api: GET https://management.azure.com/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Web/sites/xxx/config/web?api-version=2022-03-01

xiaxyi avatar Sep 22 '22 00:09 xiaxyi

Hi @xiaxyi , attaching a screenshot below of site config and virtual application configuration image image and I have just imported the app service in terraform didnt applied the plan yet, so all the values are same as actual app service in azure portal, Thank you

premchavhan99 avatar Sep 22 '22 03:09 premchavhan99

@premchavhan99 , Thanks for the information. The value of virtualApplication is the default value and terraform won't set it back to state.

func flattenVirtualApplications(appVirtualApplications *[]web.VirtualApplication) []VirtualApplication {
	if appVirtualApplications == nil || onlyDefaultVirtualApplication(*appVirtualApplications) {
		return nil
	}

You don't need to set the block in the config file, it will be set by default. The preloadEnabled property is referring to the always_on property. The value is true if always_on is set to true (which is the default value)

You can test the behavior by below steps:

  1. Turn off the always_on
  2. import to terraform, the virtual application will be written to state
  3. plan -> there is no diff.

xiaxyi avatar Sep 28 '22 07:09 xiaxyi

@Amier3 Thanks for labeling this issue, this is not a bug but a by design behavior.

xiaxyi avatar Sep 28 '22 07:09 xiaxyi

Thanks @xiaxyi for the help, it is working as expected now

premchavhan99 avatar Oct 11 '22 12:10 premchavhan99

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.

github-actions[bot] avatar Nov 11 '22 02:11 github-actions[bot]