Azure / terraform-provider-azapi

Terraform provider for Azure Resource Manager Rest API
https://registry.terraform.io/providers/Azure/azapi/latest
Mozilla Public License 2.0
175 stars 47 forks source link

Getting 404 with using azapi_update for Virtual Endpoints on Postgres Flexible Servers #620

Open will-iam-gm opened 1 day ago

will-iam-gm commented 1 day ago

Hello yesterday we experienced several of our workflows failing on running azapi_update_resource

We are using this resource to create a virtual endpoint for Postgres Flexible Servers, we started using this several months back since at the time Azurerm did not support virtual endpoints.

resource "azapi_update_resource" "virtual_endpoint" {
  for_each  = local.secondary_deployment ? local.postgres_flexible_servers : {}
  type      = "Microsoft.DBforPostgreSQL/flexibleServers/virtualendpoints@2023-06-01-preview"
  name      = module.postgres_flexible_server_virtual_endpoint_tagging[each.key].postgres_flexible_server_virtual_endpoint_id
  parent_id = module.postgres_flexible_server[each.key].azurerm_postgresql_flexible_server_id
  body = jsonencode({
    properties = {
      endpointType = "ReadWrite"
      members = [
        module.postgres_flexible_server_replica[each.key].azurerm_postgresql_flexible_server.name
      ]
    }
  })
}

Here is the error

╷
│ Error: checking for presence of existing Resource: (ResourceId "/subscriptions/3f7d848d-ffd6-4908-9dc7-0cd745e5e282/resourceGroups/a232328-t01-musea2-rg-willb/providers/Microsoft.DBforPostgreSQL/flexibleServers/a232328-t01-musea2-psql-willb/virtualendpoints/a232328-t01-psql-willb" / Api Version "2023-06-01-preview"): GET https://management.azure.com/subscriptions/3f7d848d-ffd6-4908-9dc7-0cd745e5e282/resourceGroups/a232328-t01-musea2-rg-willb/providers/Microsoft.DBforPostgreSQL/flexibleServers/a232328-t01-musea2-psql-willb/virtualendpoints/a232328-t01-psql-willb
│ --------------------------------------------------------------------------------
│ RESPONSE 404: 404 Not Found
│ ERROR CODE: ResourceNotFound
│ --------------------------------------------------------------------------------
│ {
│   "error": {
│     "code": "ResourceNotFound",
│     "message": "The specified resource 'https://orcasbreadth.eastus2.control.database.windows.net:8343/modules/ArmPostgreSQL/subscriptions/3f7d848d-ffd6-4908-9dc7-0cd745e5e282/resourceGroups/a232328-t01-musea2-rg-willb/providers/Microsoft.DBforPostgreSQL/flexibleServers/a232328-t01-musea2-psql-willb/virtualendpoints/a232328-t01-psql-willb?api-version=2023-06-01-preview' was not found."
│   }
│ }
│ --------------------------------------------------------------------------------
│ 
│ 
│   with azapi_update_resource.virtual_endpoint["willb"],
│   on postgres.tf line 108, in resource "azapi_update_resource" "virtual_endpoint":
│  108: resource "azapi_update_resource" "virtual_endpoint" {
│ 
╵

Debug turned on

2024-09-18T13:41:14.871Z [DEBUG] provider.terraform-provider-azapi_v1.12.1: Sep 18 13:41:14.871535 Request: ==> OUTGOING REQUEST (Try=1)
2024-09-18T13:41:16.9156183Z    GET https://management.azure.com/subscriptions/3f7d848d-ffd6-4908-9dc7-0cd745e5e282/resourceGroups/a232328-t01-musea2-rg-willb/providers/Microsoft.DBforPostgreSQL/flexibleServers/a232328-t01-musea2-psql-willb/virtualendpoints/a232328-t01-psql-willb?api-version=2023-06-01-preview
2024-09-18T13:41:16.9157902Z    Accept: application/json
2024-09-18T13:41:16.9158336Z    Authorization: REDACTED
2024-09-18T13:41:16.9159529Z    User-Agent: HashiCorp Terraform/1.6.6 (+https://www.terraform.io) Terraform Plugin SDK/2.8.0 terraform-provider-azapi/vv1.12.1 pid-222c6c49-1b0a-5959-a213-6608f9eb8820
2024-09-18T13:41:16.9160802Z    X-Ms-Correlation-Request-Id: 020b1db2-520a-101c-99c8-19373e1e30df
2024-09-18T13:41:16.9161673Z    Request contained no body: timestamp=2024-09-18T13:41:14.871Z
2024-09-18T13:41:16.9163203Z 2024-09-18T13:41:15.118Z [DEBUG] provider.terraform-provider-azapi_v1.12.1: Sep 18 13:41:15.117947 Response: ==> REQUEST/RESPONSE (Try=1/246.361782ms, OpTime=246.383293ms) -- RESPONSE RECEIVED
2024-09-18T13:41:16.9165781Z    GET https://management.azure.com/subscriptions/3f7d848d-ffd6-4908-9dc7-0cd745e5e282/resourceGroups/a232328-t01-musea2-rg-willb/providers/Microsoft.DBforPostgreSQL/flexibleServers/a232328-t01-musea2-psql-willb/virtualendpoints/a232328-t01-psql-willb?api-version=2023-06-01-preview
2024-09-18T13:41:16.9167496Z    Accept: application/json
2024-09-18T13:41:16.9167956Z    Authorization: REDACTED
2024-09-18T13:41:16.9169124Z    User-Agent: HashiCorp Terraform/1.6.6 (+https://www.terraform.io) Terraform Plugin SDK/2.8.0 terraform-provider-azapi/vv1.12.1 pid-222c6c49-1b0a-5959-a213-6608f9eb8820
2024-09-18T13:41:16.9170392Z    X-Ms-Correlation-Request-Id: 020b1db2-520a-101c-99c8-19373e1e30df
2024-09-18T13:41:16.9171204Z    --------------------------------------------------------------------------------
2024-09-18T13:41:16.9171810Z    RESPONSE Status: 404 Not Found
2024-09-18T13:41:16.9172379Z    Cache-Control: no-cache
2024-09-18T13:41:16.9172822Z    Content-Length: 421
2024-09-18T13:41:16.9173314Z    Content-Type: application/json; charset=utf-8
2024-09-18T13:41:16.9173837Z    Date: Wed, 18 Sep 2024 13:41:14 GMT
2024-09-18T13:41:16.9174304Z    Expires: -1
2024-09-18T13:41:16.9174692Z    Pragma: no-cache
2024-09-18T13:41:16.9175256Z    Strict-Transport-Security: max-age=31536000; includeSubDomains
2024-09-18T13:41:16.9175870Z    X-Cache: REDACTED
2024-09-18T13:41:16.9176303Z    X-Content-Type-Options: nosniff
2024-09-18T13:41:16.9176964Z    X-Ms-Correlation-Request-Id: 020b1db2-520a-101c-99c8-19373e1e30df
2024-09-18T13:41:16.9177765Z    X-Ms-Ratelimit-Remaining-Subscription-Global-Reads: REDACTED
2024-09-18T13:41:16.9178508Z    X-Ms-Ratelimit-Remaining-Subscription-Reads: 498
2024-09-18T13:41:16.9179182Z    X-Ms-Request-Id: fea291b0-be57-4d12-b615-87f561e9d062
2024-09-18T13:41:16.9180028Z    X-Ms-Routing-Request-Id: EASTUS:20240918T134115Z:7850f93e-74a8-459e-b8fb-2d2ec929aeeb
2024-09-18T13:41:16.9180755Z    X-Msedge-Ref: REDACTED
2024-09-18T13:41:16.9181327Z    --------------------------------------------------------------------------------
2024-09-18T13:41:16.9184192Z {"error":{"code":"ResourceNotFound","message":"The specified resource 'https://orcasbreadth.eastus2.control.database.windows.net:8343/modules/ArmPostgreSQL/subscriptions/3f7d848d-ffd6-4908-9dc7-0cd745e5e282/resourceGroups/a232328-t01-musea2-rg-willb/providers/Microsoft.DBforPostgreSQL/flexibleServers/a232328-t01-musea2-psql-willb/virtualendpoints/a232328-t01-psql-willb?api-version=2023-06-01-preview' was not found."}}

We are using Terraform 1.6.6 and AzAPI provider 1.12.1

Also we are using Api Version "2023-06-01-preview", I tried swapping this for Api Version "2023-12-01-preview" and no difference.

Reference : https://learn.microsoft.com/en-us/azure/templates/microsoft.dbforpostgresql/flexibleservers/virtualendpoints?pivots=deployment-language-terraform

ms-henglu commented 17 hours ago

Hi @will-iam-gm ,

Thank you for taking time to report this issue.

The azapi_update_resource is used to update an existing resource, from the logs, it seems the target resource doesn't exist.

will-iam-gm commented 8 hours ago

@ms-henglu that is interesting so your saying we have been using this resource incorrectly? We definitely been using this to add virtualendpoints to Postgres Flexible servers for several months..

I think we assumed the resource getting updated was the Postgres server itself, which does exist