google-cloud-platformterraformterraform-provider-gcpgoogle-deployment-manager

error: instance type null does not match any allowed primitive type


I am trying to create compute instance in gcp using following yaml file (terraform)

resources :
- type : compute.v1.instance
  name: quickstart-deployment-vm
  properties:
       zone: us-central1-f
       machineType: f1-micro
       disks:
                 - deviceName: boot
                   type: PERSISTENT
                   boot: true
                   autoDelete: true
                   initializeParams:
                             sourceImage: debian-cloud/debian-9
       networkInterfaces:
                 - network:
                   accessConfigs:
                     - name: ExternalNAT
                       type: ONE_TO_ONE_NAT

but receiving following error

ERROR: (gcloud.deployment-manager.deployments.create) Error in Operation [operation-1673778262629-5f24adec6dda7-44a3a3ab-e5cbf301]: errors:
- code: CONDITION_NOT_MET
  location: /deployments/my-deployment/resources/quickstart-deployment-vm->$.properties
  message: |
    error: instance type (null) does not match any allowed primitive type (allowed: ["string"])
        level: "error"
        schema: {"loadingURI":"#","pointer":"/schemas/NetworkInterface/properties/network"}
        instance: {"pointer":"/networkInterfaces/0/network"}
        domain: "validation"
        keyword: "type"
        found: "null"
        expected: ["string"]

So help me to resolve this error


Solution

  • The error is stating that the network key needs a string type value, but instead there is a null value. This is accurate as there is no value for that key. We can fix this with the following:

    networkInterfaces:
    - network: default
      accessConfigs:
      - name: ExternalNAT
        type: ONE_TO_ONE_NAT