From 57265acc0f459d71298a97f27a88fa0baf911187 Mon Sep 17 00:00:00 2001 From: Kurt McAlpine Date: Thu, 9 May 2024 16:54:08 +1200 Subject: [PATCH] Add class_c_timeout --- docs/resources/device_profile.md | 1 + internal/provider/device_profile_resource.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/docs/resources/device_profile.md b/docs/resources/device_profile.md index 8bc5a29..e3c044a 100644 --- a/docs/resources/device_profile.md +++ b/docs/resources/device_profile.md @@ -46,6 +46,7 @@ resource "chirpstack_device_profile" "mydeviceprofile" { - `adr_algorithm` (String) The ADR algorithm that will be used for controlling the device data-rate. - `allow_roaming` (Boolean) If enabled (and if roaming is configured on the server), this allows the device to use roaming. +- `class_c_timeout` (Number) Class-C timeout (seconds). This is the maximum time ChirpStack will wait to receive an acknowledgement from the device (if requested). - `description` (String) Device profile description - `device_status_request_frequency` (Number) Frequency to initiate an End-Device status request (request/day). Set to 0 to disable. - `device_supports_class_b` (Boolean) Device supports Class-B diff --git a/internal/provider/device_profile_resource.go b/internal/provider/device_profile_resource.go index 1fc819d..d1a2ba5 100644 --- a/internal/provider/device_profile_resource.go +++ b/internal/provider/device_profile_resource.go @@ -49,6 +49,7 @@ type DeviceProfileResourceModel struct { DeviceSupportsOTAA types.Bool `tfsdk:"device_supports_otaa"` DeviceSupportsClassB types.Bool `tfsdk:"device_supports_class_b"` DeviceSupportsClassC types.Bool `tfsdk:"device_supports_class_c"` + ClassCTimeout types.Int64 `tfsdk:"class_c_timeout"` } func (r *DeviceProfileResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { @@ -128,6 +129,11 @@ func (r *DeviceProfileResource) Schema(ctx context.Context, req resource.SchemaR MarkdownDescription: "Device supports Class-C", Optional: true, }, + "class_c_timeout": schema.Int64Attribute{ + MarkdownDescription: "Class-C timeout (seconds). This is the maximum time ChirpStack will wait to receive an acknowledgement from the device (if requested).", + Optional: true, + Computed: true, + }, }, } } @@ -198,6 +204,7 @@ func deviceProfileFromData(data *DeviceProfileResourceModel) *api.DeviceProfile if !data.DeviceSupportsClassC.IsNull() { deviceProfile.SupportsClassC = data.DeviceSupportsClassC.ValueBool() } + deviceProfile.ClassCTimeout = uint32(data.ClassCTimeout.ValueInt64()) return deviceProfile } @@ -226,6 +233,7 @@ func deviceProfileToData(deviceProfile *api.DeviceProfile, data *DeviceProfileRe data.DeviceSupportsOTAA = types.BoolValue(deviceProfile.SupportsOtaa) data.DeviceSupportsClassB = types.BoolValue(deviceProfile.SupportsClassB) data.DeviceSupportsClassC = types.BoolValue(deviceProfile.SupportsClassC) + data.ClassCTimeout = types.Int64Value(int64(deviceProfile.ClassCTimeout)) } func (r *DeviceProfileResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { @@ -256,6 +264,7 @@ func (r *DeviceProfileResource) Create(ctx context.Context, req resource.CreateR // For the purposes of this device profile code, hardcoding a response value to // save into the Terraform state. data.Id = types.StringValue(id) + deviceProfileToData(deviceProfile, &data) // Write logs using the tflog package // Documentation: https://terraform.io/plugin/log @@ -317,6 +326,7 @@ func (r *DeviceProfileResource) Update(ctx context.Context, req resource.UpdateR resp.Diagnostics.AddError("Chirpstack Error", fmt.Sprintf("Unable to update device profile, got error: %s", err)) return } + deviceProfileToData(deviceProfile, &data) // Save updated data into Terraform state resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)