Skip to content

Commit

Permalink
feat(iot): add hub devices support (scaleway#508)
Browse files Browse the repository at this point in the history
Co-authored-by: Clément Decoodt <[email protected]>
  • Loading branch information
Lichard Torman and Clément Decoodt authored Jan 28, 2021
1 parent 7200d6d commit aa1f090
Show file tree
Hide file tree
Showing 6 changed files with 2,023 additions and 0 deletions.
80 changes: 80 additions & 0 deletions docs/resources/iot_device.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
layout: "scaleway"
page_title: "Scaleway: scaleway_iot_hub_device"
description: |-
Manages Scaleway IoT Hub device.
---

# scaleway_iot_hub_device

-> **Note:** This terraform resource is currently in beta and might include breaking change in future releases.

Creates and manages Scaleway IoT Hub Instances. For more information, see [the documentation](https://developers.scaleway.com/en/products/iot/api).

## Examples

### Basic

```hcl
resource scaleway_iot_hub main {
name = "test-iot"
product_plan = "plan_shared"
}
resource scaleway_iot_hub_device main {
hub_id = scaleway_iot_hub.main.id
name = "test-iot"
}
```

## Arguments Reference

The following arguments are supported:

- `hub_id` - (Required) The ID of the hub on which this device will be created.

- `name` - (Required) The name of the IoT device you want to create (e.g. `my-device`).

~> **Important:** Updates to `name` will destroy and recreate a new resource.

- `description` - (Optional) The description of the IoT device (e.g. `living room`).

- `allow_insecure` - (Optional) Allow plain and server-authenticated TLS connections in addition to mutually-authenticated ones.

~> **Important:** Updates to `allow_insecure` can disconnect eventually connected devices.

- `allow_multiple_connections` - (Optional) Allow more than one simultaneous connection using the same device credentials.

~> **Important:** Updates to `allow_multiple_connections` can disconnect eventually connected devices.

- `message_filters` - (Optional) Rules that define which messages are authorized or denied based on their topic.
- `publish` - (Optional) Rules used to restrict topics the device can publish to.
- `policy` (Optional) Filtering policy (eg `accept` or `reject`)
- `topics` (Optional) List of topics to match (eg `foo/bar/+/baz/#`)
- `subscribe` - (Optional) Rules used to restrict topics the device can subscribe to.
- `policy` (Optional) Same as publish rules.
- `topics` (Optional) Same as publish rules.


## Attributes Reference

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

- `id` - The ID of the device.
- `created_at` - The date and time the device was created.
- `updated_at` - The date and time the device resource was updated.
- `certificate` - The certificate bundle of the device.
- `crt` - The certificate of the device.
- `key` - The private key of the device.
- `status` - The current status of the device.
- `last_activity_at` - The last MQTT activity of the device.
- `is_connected` - The current connection status of the device.


## Import

IoT devices can be imported using the `{region}/{id}`, e.g.

```bash
$ terraform import scaleway_iot_device.device01 fr-par/11111111-1111-1111-1111-111111111111
```
11 changes: 11 additions & 0 deletions scaleway/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,17 @@ func expandStrings(data interface{}) []string {
return stringSlice
}

func expandStringsOrEmpty(data interface{}) []string {
if data == nil {
return []string{}
}
stringSlice := []string{}
for _, s := range data.([]interface{}) {
stringSlice = append(stringSlice, s.(string))
}
return stringSlice
}

func expandSliceStringPtr(data interface{}) []*string {
if data == nil {
return nil
Expand Down
1 change: 1 addition & 0 deletions scaleway/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func Provider(config *ProviderConfig) plugin.ProviderFunc {
"scaleway_instance_placement_group": resourceScalewayInstancePlacementGroup(),
"scaleway_instance_private_nic": resourceScalewayInstancePrivateNIC(),
"scaleway_iot_hub": resourceScalewayIotHub(),
"scaleway_iot_device": resourceScalewayIotDevice(),
"scaleway_k8s_cluster": resourceScalewayK8SCluster(),
"scaleway_k8s_pool": resourceScalewayK8SPool(),
"scaleway_lb": resourceScalewayLb(),
Expand Down
Loading

0 comments on commit aa1f090

Please sign in to comment.