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

terraform import on azurerm_app_service_plan missing many settings #2991

Closed
andrew-sumner opened this issue Mar 4, 2019 · 4 comments
Closed

Comments

@andrew-sumner
Copy link

andrew-sumner commented Mar 4, 2019

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 v0.11.11

  • provider.azurerm v1.22.1

Description

When running

terraform import azurerm_app_service_plan.test /subscriptions/<GUID>/resourceGroups/RG-DevSupport/providers/Microsoft.Web/serverFarms/HostingPlan-Andrew

I expect to import all the settings however many are missing.

Affected Resource(s)

  • azurerm_app_service_plan

Terraform Configuration Files

terraform {
  backend "local" {
    path = "../state/devtest/terraform.tfstate"
  }
}

# https://www.terraform.io/docs/providers/azurerm/
provider "azurerm" {
    version         = "=1.22.1"
    subscription_id = "${var.azure_subscription_id}"
    tenant_id       = "${var.azure_tenant_id}"
}

resource "azurerm_app_service_plan" "test" {
  name                = "HostingPlan-Andrew"
  resource_group_name = "RG-DevSupporttt"
  location            = "${var.location}"
  kind                = "Windows"

  sku {
    tier = "Basic"
    size = "B1"
  }
}

Debug Output

After running terraform plan on a newly imported app service plan I get this output:

Terraform will perform the following actions:

-/+ azurerm_app_service_plan.test (new resource required)
      id:                         "/subscriptions/a724b29b-ab3b-42dc-ab11-5c252397a687/resourceGroups/RG-DevSupporttt/providers/Microsoft.Web/serverFarms/HostingPlan-Andrew" => <computed> (forces new resource)
      app_service_environment_id: "" => <computed>
      kind:                       "" => "Windows" (forces new resource)
      location:                   "" => "australiasoutheast" (forces new resource)
      maximum_number_of_workers:  "" => <computed>
      name:                       "" => "HostingPlan-Andrew" (forces new resource)
      per_site_scaling:           "" => <computed>
      properties.#:               "" => <computed>
      reserved:                   "" => <computed>
      resource_group_name:        "RG-DevSupporttt" => "RG-DevSupporttt"
      sku.#:                      "0" => "1"
      sku.0.capacity:             "" => <computed>
      sku.0.size:                 "" => "B1"
      sku.0.tier:                 "" => "Basic"
      tags.%:                     "0" => <computed>

Note that it even wants to rename it.

Panic Output

Expected Behavior

After running terraform import on an app service plan the state file should contain:

"azurerm_app_service_plan.test2": {
                    "type": "azurerm_app_service_plan",
                    "depends_on": [],
                    "primary": {
                        "id": "/subscriptions/<GUID>/resourceGroups/RG-DevSupporttt/providers/Microsoft.Web/serverfarms/HostingPlan-Andrew",
                        "attributes": {
                            "id": "/subscriptions/<GUID>/resourceGroups/RG-DevSupporttt/providers/Microsoft.Web/serverfarms/HostingPlan-Andrew",
                            "kind": "Windows",
                            "location": "australiasoutheast",
                            "maximum_number_of_workers": "3",
                            "name": "HostingPlan-Andrew2",
                            "per_site_scaling": "false",
                            "properties.#": "1",
                            "properties.0.app_service_environment_id": "",
                            "properties.0.per_site_scaling": "false",
                            "properties.0.reserved": "false",
                            "reserved": "false",
                            "resource_group_name": "RG-DevSupporttt",
                            "sku.#": "1",
                            "sku.0.capacity": "1",
                            "sku.0.size": "B1",
                            "sku.0.tier": "Basic",
                            "tags.%": "0"
                        },
                        "meta": {},
                        "tainted": false
                    },
                    "deposed": [],
                    "provider": "provider.azurerm"
                }

Note: This state is from a newly created app service plan, created using terraform.

Actual Behavior

After running terraform import on an app service plan the state file actually contains:

 "azurerm_app_service_plan.test": {
                    "type": "azurerm_app_service_plan",
                    "depends_on": [],
                    "primary": {
                        "id": "/subscriptions/<GUID>/resourceGroups/RG-DevSupport/providers/Microsoft.Web/serverFarms/HostingPlan-Andrew",
                        "attributes": {
                            "id": "/subscriptions/<GUID>/resourceGroups/RG-DevSupport/providers/Microsoft.Web/serverFarms/HostingPlan-Andrew",
                            "kind": "",
                            "name": "",
                            "resource_group_name": "RG-DevSupporttt",
                            "sku.#": "0",
                            "tags.%": "0"
                        },
                        "meta": {},
                        "tainted": false
                    },
                    "deposed": [],
                    "provider": "provider.azurerm"
                },

Note that it's even missing the resource name

Steps to Reproduce

  1. Manually create an Azure App Service Plan
  2. Run terraform import ADDR ID
  3. Inspect state file, will be missing properties for the app service plan
  4. Add resource "azurerm_app_service_plan" to terraform file using same settings used to create in step 1
  5. Run terraform plan, should see no changes, will see that resource will be dropped and recreated because of the changes terraform thinks it needs to make

Important Factoids

References

@tombuildsstuff
Copy link
Contributor

hi @andrew-sumner

Thanks for opening this issue :)

Taking a look into this it appears the casing on the ID at Import time is incorrect:

$ terraform import azurerm_app_service_plan.test /subscriptions/<GUID>/resourceGroups/RG-DevSupport/providers/Microsoft.Web/serverFarms/HostingPlan-Andrew

From the Import section in the documentation this needs to be:

$ terraform import azurerm_app_service_plan.instance1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Web/serverfarms/instance1

(note the difference in serverFarms vs serverfarms)

Would you be able to take a look and see if Importing this using serverfarms instead of serverFarms works for you?

Since this is a question about Terraform Configuration rather than a bug in Terraform, I'm going to close this issue for the moment - but please let us know if that doesn't work for you and we'll take another look :)

Thanks!

@andrew-sumner
Copy link
Author

andrew-sumner commented Mar 5, 2019

Yes, the lowercase serverfarms worked thanks.

I had copied the resource id directly from Azure Portal like every other resource I have imported so I believe there is still a bug here. Do you think this issue should be reopened and either:

  1. Fail the import saying the resource was not found rather than importing an empty state entry, or
  2. Support serverFarms case as this is what Azure Portal uses

@tombuildsstuff
Copy link
Contributor

@andrew-sumner glad to hear this is now working for you

I had copied the resource id directly from Azure Portal like every other resource I have imported so I believe there is still a bug here. Do you think this issue should be reopened and either:

  1. Fail the import saying the resource was not found rather than importing an empty state entry, or
  2. Support serverFarms case as this is what Azure Portal uses

Unfortunately the Azure Portal differs from the API here (which is the source of truth and documents that the casing should be serverfarms) - as such I believe that to be a bug in the Azure Portal.

Whilst we plan to add additional validation to the import of (all) resources during terraform import in a future release (e.g. to ensure the segments match as we expect) - it's possible that this could form a part of the 2.0 work tracked in #2807 - but unfortunately I don't otherwise have a timeline for this.

Thanks!

@ghost
Copy link

ghost commented Apr 3, 2019

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!

@ghost ghost locked and limited conversation to collaborators Apr 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants