» google_cloudiot_device

A Google Cloud IoT Core device.

To get more information about Device, see:

» Example Usage - Cloudiot Device Basic

resource "google_cloudiot_registry" "registry" {
  name     = "cloudiot-device-registry"
}

resource "google_cloudiot_device" "test-device" {
  name     = "cloudiot-device"
  registry = google_cloudiot_registry.registry.id
}

» Example Usage - Cloudiot Device Full

resource "google_cloudiot_registry" "registry" {
  name     = "cloudiot-device-registry"
}

resource "google_cloudiot_device" "test-device" {
  name     = "cloudiot-device"
  registry = google_cloudiot_registry.registry.id

  credentials {
    public_key {
        format = "RSA_PEM"
        key = file("test-fixtures/rsa_public.pem")
    }
  }

  blocked = false

  log_level = "INFO"

  metadata = {
    test_key_1 = "test_value_1"
  }

  gateway_config {
    gateway_type = "NON_GATEWAY"
  }
}

» Argument Reference

The following arguments are supported:

  • name - (Required) A unique name for the resource.

  • registry - (Required) The name of the device registry where this device should be created.


  • credentials - (Optional) The credentials used to authenticate this device. Structure is documented below.

  • blocked - (Optional) If a device is blocked, connections or requests from this device will fail.

  • log_level - (Optional) The logging verbosity for device activity. Possible values are NONE, ERROR, INFO, and DEBUG.

  • metadata - (Optional) The metadata key-value pairs assigned to the device.

  • gateway_config - (Optional) Gateway-related configuration and state. Structure is documented below.

The credentials block supports:

  • expiration_time - (Optional) The time at which this credential becomes invalid.

  • public_key - (Required) A public key used to verify the signature of JSON Web Tokens (JWTs). Structure is documented below.

The public_key block supports:

  • format - (Required) The format of the key. Possible values are RSA_PEM, RSA_X509_PEM, ES256_PEM, and ES256_X509_PEM.

  • key - (Required) The key data.

The gateway_config block supports:

  • gateway_type - (Optional) Indicates whether the device is a gateway. Default value is NON_GATEWAY. Possible values are GATEWAY and NON_GATEWAY.

  • gateway_auth_method - (Optional) Indicates whether the device is a gateway. Possible values are ASSOCIATION_ONLY, DEVICE_AUTH_TOKEN_ONLY, and ASSOCIATION_AND_DEVICE_AUTH_TOKEN.

  • last_accessed_gateway_id - The ID of the gateway the device accessed most recently.

  • last_accessed_gateway_time - The most recent time at which the device accessed the gateway specified in last_accessed_gateway.

» Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • id - an identifier for the resource with format {{registry}}/devices/{{name}}

  • num_id - A server-defined unique numeric ID for the device. This is a more compact way to identify devices, and it is globally unique.

  • last_heartbeat_time - The last time an MQTT PINGREQ was received.

  • last_event_time - The last time a telemetry event was received.

  • last_state_time - The last time a state event was received.

  • last_config_ack_time - The last time a cloud-to-device config version acknowledgment was received from the device.

  • last_config_send_time - The last time a cloud-to-device config version was sent to the device.

  • last_error_time - The time the most recent error occurred, such as a failure to publish to Cloud Pub/Sub.

  • last_error_status - The error message of the most recent error, such as a failure to publish to Cloud Pub/Sub. Structure is documented below.

  • config - The most recent device configuration, which is eventually sent from Cloud IoT Core to the device. Structure is documented below.

  • state - The state most recently received from the device. Structure is documented below.

The last_error_status block contains:

  • number - (Optional) The status code, which should be an enum value of google.rpc.Code.

  • message - (Optional) A developer-facing error message, which should be in English.

  • details - (Optional) A list of messages that carry the error details.

The config block contains:

  • version - The version of this update.

  • cloud_update_time - The time at which this configuration version was updated in Cloud IoT Core.

  • device_ack_time - The time at which Cloud IoT Core received the acknowledgment from the device, indicating that the device has received this configuration version.

  • binary_data - (Optional) The device configuration data.

The state block contains:

  • update_time - (Optional) The time at which this state version was updated in Cloud IoT Core.

  • binary_data - (Optional) The device state data.

» Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 4 minutes.
  • update - Default is 4 minutes.
  • delete - Default is 4 minutes.

» Import

Device can be imported using any of these accepted formats:

$ terraform import google_cloudiot_device.default {{registry}}/devices/{{name}}