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

`Microsoft.RedHatOpenShift/openShiftClusters@2023-07-01-preview` - switching api-version gets error 400

Open davidkarlsen opened this issue 10 months ago • 1 comments

I have this resource, which I bumped the api from one version to another (https://learn.microsoft.com/en-us/azure/templates/microsoft.redhatopenshift/openshiftclusters?pivots=deployment-language-terraform) - but now I provide an explicit value for a property which was not there before (it was an opt-in feature before, that I had to enable at provider level).

 # module.aro.azapi_resource.aro will be updated in-place
  ~ resource "azapi_resource" "aro" {
        id                        = "/subscriptions/XXX/resourceGroups/ftm-aro-dev-nore-rg/providers/Microsoft.RedHatOpenShift/openShiftClusters/ftm-aro-dev-nore-aro"
        name                      = "ftm-aro-dev-nore-aro"
        tags                      = {
            "contactemail"   = "XXXX"
            "costallocation" = "XXXX"
            "environment"    = "dev"
        }
      ~ type                      = "Microsoft.RedHatOpenShift/openShiftClusters@2022-09-04" -> "Microsoft.RedHatOpenShift/openShiftClusters@2023-07-01-preview"
        # (9 unchanged attributes hidden)
    }

now it fails with:

Error: creating/updating "Resource: (ResourceId \"/subscriptions/XXXX/resourceGroups/ftm-aro-dev-nore-rg/providers/Microsoft.RedHatOpenShift/openShiftClusters/ftm-aro-dev-nore-aro\" / Api Version \"2023-07-01-preview\")": PUT https://management.azure.com/subscriptions/XXXX/resourceGroups/ftm-aro-dev-nore-rg/providers/Microsoft.RedHatOpenShift/openShiftClusters/ftm-aro-dev-nore-aro
│ --------------------------------------------------------------------------------
│ RESPONSE 400: 400 Bad Request
│ ERROR CODE: PropertyChangeNotAllowed
│ --------------------------------------------------------------------------------
│ {
│   "error": {
│     "code": "PropertyChangeNotAllowed",
│     "message": "Changing property 'properties.networkProfile.outboundType' is not allowed.",
│     "target": "properties.networkProfile.outboundType"
│   }
│ }

which is a bit strange - because I set the same value as which is returned with az aro list (the value is UserDefinedRouting).

how can I get out of this?

davidkarlsen avatar Oct 01 '23 18:10 davidkarlsen

Hi @davidkarlsen ,

Thank you for taking time to report this issue and apologize for the late response.

It seems to be an issue on the API side. There's a workaround for this, hope it could help you.

  1. Copy azapi_resource.aro block, and name it "import" for example, then change its type to Microsoft.RedHatOpenShift/openShiftClusters@2023-07-01-preview
  2. Run terraform import azapi_resource.import /subscriptions/****/resourceGroups/****/providers/Microsoft.RedHatOpenShift/openShiftClusters/****?api-version=2023-07-01-preview to import the resource into terraform state
  3. Run terraform plan to check the diff. When import a new resource, azapi provider will add every configurable fields in the state, so you'll see there're lots of fields are not defined in the config, you can add the necessary fields to the config then run terraform apply to update the terraform state.
  4. Run terraform state rm azapi_resource.aro command to remove the old resource from terraform state. And remove the azapi_resource.aro block from config.

ms-henglu avatar Oct 11 '23 05:10 ms-henglu