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

json: cannot unmarshal object into Go struct field ServiceEndpointPolicyPropertiesFormat.contextualServiceEndpointPolicies of type string #519

Open
zeusbaba opened this issue Apr 24, 2024 · 9 comments

Comments

@zeusbaba
Copy link

getting this error on some resources.
Could you please help/advise on how to resolve this?

current versions:

aztfexport version v0.14.1(f492475)  
Terraform v1.8.2

Pasting below log snippet

2024-04-24T15:03:40.912+0200 [ERROR] aztfexport: Importing azurerm_subnet_service_endpoint_storage_policy.res-67: exit status 1

Error: retrieving Subnet Service Endpoint Storage Policy "_e41f87a2_mi_REDACTED" (Resource Group "rg-redacted-qa"): network.ServiceEndpointPoliciesClient#Get: Failure responding to request: StatusCode=200 -- Original Error: Error occurred unmarshalling JSON - Error = 'json: cannot unmarshal object into Go struct field ServiceEndpointPolicyPropertiesFormat.contextualServiceEndpointPolicies of type string' JSON = '{
  "name": "_e41f87a2_mi_REDACTED",
  "id": "/subscriptions/REDACTED/resourceGroups/rg-redacted-qa/providers/Microsoft.Network/serviceEndpointPolicies/_e41f87a2_mi_REDACTED",
  "etag": "W/\"83bfed89-30f4-redacted\"",
  "type": "Microsoft.Network/serviceEndpointPolicies",
  "location": "norwayeast",
  "properties": {
    "provisioningState": "Succeeded",
    "resourceGuid": "4f9befbd-REDACTED",
    "serviceAlias": "/services/Azure/ManagedInstance",
    "serviceEndpointPolicyDefinitions": [],
    "contextualServiceEndpointPolicies": [
      {
        "id": "/subscriptions/REDACTED/resourceGroups/rg-redacted-qa/providers/Microsoft.Network/virtualNetworks/vnet-redactedqa/subnets/managedinstance/contextualServiceEndpointPolicies/ManagedInstanceContextualPolicy"
      }
    ]
  },
  "kind": "Internal"
}' 
@magodo
Copy link
Collaborator

magodo commented Apr 25, 2024

@zeusbaba This seems to be an upstream provider issue, you can verify this by directly import it via terraform import azurerm_subnet_service_endpoint_storage_policy.name <id>.

@zeusbaba
Copy link
Author

@zeusbaba This seems to be an upstream provider issue, you can verify this by directly import it via terraform import azurerm_subnet_service_endpoint_storage_policy.name <id>.

thnx for response.
I'll try this and get back to you soon

@zeusbaba
Copy link
Author

@zeusbaba This seems to be an upstream provider issue, you can verify this by directly import it via terraform import azurerm_subnet_service_endpoint_storage_policy.name <id>.

terraform import azurerm_subnet_service_endpoint_storage_policy.name id

fails, because

Error: resource address "azurerm_subnet_service_endpoint_storage_policy.name" does not exist in the configuration.

i assume that aztfexport failed to parse it in the first run. I don't see it in the generated main.tf either

@magodo
Copy link
Collaborator

magodo commented Apr 25, 2024

@zeusbaba You'll need to first write a main.tf to which contains the following content:

resource azurerm_subnet_service_endpoint_storage_policy name {
}

@zeusbaba
Copy link
Author

@magodo as you suggested, I manually added this section to the generated main.tf, and then re-run
terraform import azurerm_subnet_service_endpoint_storage_policy.name id
getting this error

Error: Error ensuring Resource Providers are registered.  
...  
 Original Error: Cannot register providers: Microsoft.AppConfiguration, Microsoft.DataFactory, Microsoft.SignalRService. Errors were: Cannot register provider Microsoft.AppConfiguration with Azure Resource Manager: unexpected status 403 (403 Forbidden) with error: AuthorizationFailed: The client '152af153-redacted' with object id '152f153-redacted' does not have authorization to perform action 'Microsoft.AppConfiguration/register/action' over scope '/subscriptions/a498c7e3-redacted' or the scope is invalid.
...

btw. as i see in the logs, this import is supposed to be done by aztfexport , right?

@magodo
Copy link
Collaborator

magodo commented Apr 26, 2024

@zeusbaba Yes, the error you see here is because the AzureRM provider by default register all the resource providers that potentially be used. You can suppress it by specifying skip_provider_registration.

@zeusbaba
Copy link
Author

following your suggestion, I did set ARM_SKIP_PROVIDER_REGISTRATION=true
then re-run aztfexport on the failing resource group.

but the same error still in the logs.

2024-04-26T07:23:42.666+0200 [ERROR] aztfexport: Importing azurerm_subnet_service_endpoint_storage_policy.res-69: exit status 1

Error: retrieving Subnet Service Endpoint Storage Policy "_e41f87a2_REDACTED" (Resource Group "rg-redacted-qa"): network.ServiceEndpointPoliciesClient#Get: Failure responding to request: StatusCode=200 -- Original Error: Error occurred unmarshalling JSON - Error = 'json: cannot unmarshal object into Go struct field ServiceEndpointPolicyPropertiesFormat.contextualServiceEndpointPolicies of type string' JSON = '{
  "name": "_e41f87a2_REDACTED",
  "id": "/subscriptions/a498c7e3-REDACTED/resourceGroups/rg-redacted-qa/providers/Microsoft.Network/serviceEndpointPolicies/_e41f87a2_REDACTED",
  "etag": "W/\"96ddffdc-REDACTED\"",
  "type": "Microsoft.Network/serviceEndpointPolicies",
  "location": "norwayeast",
  "properties": {
    "provisioningState": "Succeeded",
    "resourceGuid": "88e6ea86-REDACTED",
    "serviceAlias": "/services/Azure/ManagedInstance",
    "serviceEndpointPolicyDefinitions": [],
    "contextualServiceEndpointPolicies": [
      {
        "id": "/subscriptions/a498c7e3-REDACTED/resourceGroups/rg-redacted-qa/providers/Microsoft.Network/virtualNetworks/vnet-saassb1qa/subnets/managedinstance/contextualServiceEndpointPolicies/ManagedInstanceContextualPolicy"
      }
    ]
  },
  "kind": "Internal"
}'
2024-04-26T07:23:42.809+0200 [ERROR] aztfexport: Importing azurerm_subnet_service_endpoint_storage_policy.res-67: exit status 1

Error: retrieving Subnet Service Endpoint Storage Policy "_e41f87a2_REDACTED" (Resource Group "rg-redacted-qa"): network.ServiceEndpointPoliciesClient#Get: Failure responding to request: StatusCode=200 -- Original Error: Error occurred unmarshalling JSON - Error = 'json: cannot unmarshal object into Go struct field ServiceEndpointPolicyPropertiesFormat.contextualServiceEndpointPolicies of type string' JSON = '{
  "name": "_e41f87a2_REDACTED",
  "id": "/subscriptions/a498c7e3-REDACTED/resourceGroups/rg-redacted-qa/providers/Microsoft.Network/serviceEndpointPolicies/_e41f87a2_REDACTED",
  "etag": "W/\"83bfed89-REDACTED\"",
  "type": "Microsoft.Network/serviceEndpointPolicies",
  "location": "norwayeast",
  "properties": {
    "provisioningState": "Succeeded",
    "resourceGuid": "4f9befbd-REDACTED",
    "serviceAlias": "/services/Azure/ManagedInstance",
    "serviceEndpointPolicyDefinitions": [],
    "contextualServiceEndpointPolicies": [
      {
        "id": "/subscriptions/a498c7e3-REDACTED/resourceGroups/rg-redacted-qa/providers/Microsoft.Network/virtualNetworks/vnet-saassb1qa/subnets/managedinstance/contextualServiceEndpointPolicies/ManagedInstanceContextualPolicy"
      }
    ]
  },
  "kind": "Internal"
}'

@magodo
Copy link
Collaborator

magodo commented Apr 28, 2024

Sorry, I mean this error is raised from the upstream azurerm provider, which needs to be fixed there. Could you please again try reproduce this error by terraform import command, then submit an issue there?

@zeusbaba
Copy link
Author

Sorry, I mean this error is raised from the upstream azurerm provider, which needs to be fixed there. Could you please again try reproduce this error by terraform import command, then submit an issue there?

fyi. as you suggested, I've created this issue >>
we can progress based on response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants