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

Importing azurerm_static_site_custom_domain resource fails to set validation_type, leading to resource replacement #15837

Closed
fvdnabee opened this issue Mar 15, 2022 · 2 comments · Fixed by #15849

Comments

@fvdnabee
Copy link
Contributor

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 (and AzureRM Provider) Version

  • Terraform v1.1.7 on linux_amd64
  • provider registry.terraform.io/hashicorp/azurerm v2.95.0

Affected Resource(s)

  • azurerm_static_site_custom_domain

Terraform Configuration Files

variable "resource_group_name" {}

data "azurerm_resource_group" "rg" {
  name = var.resource_group_name
}

resource "azurerm_static_site" "spa" {
  name                = "mySpa"
  resource_group_name = data.azurerm_resource_group.rg.name
  location            = data.azurerm_resource_group.rg.location
  sku_tier            = "Free"
}

resource "azurerm_static_site_custom_domain" "spa" {
  static_site_id  = azurerm_static_site.spa.id
  domain_name     = "example.com"
  validation_type = "cname-delegation"
}

Debug Output

❯ terraform import 'azurerm_static_site_custom_domain.spa[0]' /subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Web/staticSites/mySpa/customDomains/example.com                                  
azurerm_static_site_custom_domain.spa[0]: Importing from ID "/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Web/staticSites/mySpa/customDomains/example.com"...                                                        
azurerm_static_site_custom_domain.spa[0]: Import prepared!                                                                                        
  Prepared azurerm_static_site_custom_domain for import                                                                                                        
azurerm_static_site_custom_domain.spa[0]: Refreshing state... [id=/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Web/staticSites/mySpa/customDomains/example.com]                                                      
                                                                                                                                                               
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.                                                                                              

Panic Output

Expected Behaviour

The resource is imported in a complete state.

Actual Behaviour

The resource is imported partially, with validation_type not set. This the resource state after the import:

    {
      "mode": "managed",
      "type": "azurerm_static_site_custom_domain",
      "name": "spa",
      "provider": "provider[\"registry.terraform.io/hashicorp/azurerm\"]",
      "instances": [
        {
          "index_key": 0,
          "schema_version": 0,
          "attributes": {
            "domain_name": "example.com",
            "id": "/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Web/staticSites/mySpa/customDomains/example.com",
            "static_site_id": "/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Web/staticSites/mySpa",
            "timeouts": {
              "create": null,
              "delete": null,
              "read": null,
              "update": null
            },
            "validation_token": "",
            "validation_type": null
          },
          "sensitive_attributes": [],
          "private": "REDACTED"
        }
      ]
    },

Note that validation_type is set to null.

Whenever terraform creates a new plan after the import, it proposes to replace the imported resource:

Terraform will perform the following actions:

  # azurerm_static_site_custom_domain.spa[0] must be replaced
-/+ resource "azurerm_static_site_custom_domain" "spa" {
      ~ id               = "/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Web/staticSites/mySpa/customDomains/example.com" -> (known after apply)  
      + validation_token = (sensitive value)
      + validation_type  = "cname-delegation" # forces replacement
        # (2 unchanged attributes hidden)

      - timeouts {}                     
    }                                   

Plan: 1 to add, 0 to change, 1 to destroy.

Steps to Reproduce

  1. Provision just the SWA from terraform
  2. Provision custom domain from another tool (e.g. azure portal)
  3. Import custom domain resource into terraform (see above)
  4. Run terraform plan

Important Factoids

References

  • #0000
magodo added a commit that referenced this issue Mar 16, 2022
This is to allow the imported `azurerm_static_site_custom_domain` not suffering force replacement issue. Fixes #15837.
magodo added a commit that referenced this issue Mar 16, 2022
This is to allow the imported `azurerm_static_site_custom_domain` not suffering force replacement issue. Fixes #15837.
@github-actions github-actions bot added this to the v3.12.0 milestone Jun 29, 2022
@github-actions
Copy link

github-actions bot commented Jul 1, 2022

This functionality has been released in v3.12.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

github-actions bot commented Aug 1, 2022

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 github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants