Google Cloud IoT Core Device
This page shows how to write Terraform for Cloud IoT Core Device and write them securely.
google_cloudiot_device (Terraform)
The Device in Cloud IoT Core can be configured in Terraform with the resource name google_cloudiot_device. The following sections describe 5 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "google_cloudiot_device" "raspberrypi3" {
name = "raspberrypi3"
registry = google_cloudiot_registry.iot_poc_registry.id
credentials {
public_key {
resource "google_cloudiot_device" "foglamp-demo-device" {
name = "foglamp-demo-device"
registry = google_cloudiot_registry.foglamp-demo-registry.id
credentials {
public_key {
resource "google_cloudiot_device" "this" {
blocked = var.blocked
log_level = var.log_level
metadata = var.metadata
name = var.name
registry = var.registry
resource "google_cloudiot_device" "device_dev1" {
name = "device-dev1"
registry = google_cloudiot_registry.test_registry.id
credentials {
public_key {
resource "google_cloudiot_device" "instance-1" {
name = "instance-1"
registry = google_cloudiot_registry.test-registry.id
}
Parameters
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 areNONE,ERROR,INFO, andDEBUG.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 areRSA_PEM,RSA_X509_PEM,ES256_PEM, andES256_X509_PEM.key- (Required) The key data.
The gateway_config block supports:
gateway_type- (Optional) Indicates whether the device is a gateway. Default value isNON_GATEWAY. Possible values areGATEWAYandNON_GATEWAY.gateway_auth_method- (Optional) Indicates whether the device is a gateway. Possible values areASSOCIATION_ONLY,DEVICE_AUTH_TOKEN_ONLY, andASSOCIATION_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.
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.
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.
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.
update_time- (Optional) The time at which this state version was updated in Cloud IoT Core.binary_data- (Optional) The device state data.
Explanation in Terraform Registry
A Google Cloud IoT Core device. To get more information about Device, see:
- API documentation
- How-to Guides
Frequently asked questions
What is Google Cloud IoT Core Device?
Google Cloud IoT Core Device is a resource for Cloud IoT Core of Google Cloud Platform. Settings can be wrote in Terraform.
Where can I find the example code for the Google Cloud IoT Core Device?
For Terraform, the s1moe2/gcp-iot-poc, badal-io/dataflow-timeseries-iot-gas-demo and niveklabs/google source code examples are useful. See the Terraform Example section for further details.