Skip to content

Commit

Permalink
refactoring test case code and adding docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kikumar552 committed Jul 6, 2023
1 parent 6337bc3 commit 37abdb2
Showing 3 changed files with 108 additions and 7 deletions.
74 changes: 74 additions & 0 deletions docs/resources/devices_cellular_sims.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "meraki_devices_cellular_sims Resource - terraform-provider-meraki"
subcategory: ""
description: |-
Updates the SIM and APN configurations for a cellular device.
---

# meraki_devices_cellular_sims (Resource)

Updates the SIM and APN configurations for a cellular device.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `sims` (Attributes Set) List of SIMs. If a SIM was previously configured and not specified in this request, it will remain unchanged. (see [below for nested schema](#nestedatt--sims))

### Optional

- `serial` (String) serial.
- `sim_failover` (Attributes) (see [below for nested schema](#nestedatt--sim_failover))

### Read-Only

- `id` (String) The ID of this resource.

<a id="nestedatt--sims"></a>
### Nested Schema for `sims`

Required:

- `apns` (Attributes Set) APN configurations. If empty, the default APN will be used. (see [below for nested schema](#nestedatt--sims--apns))

Optional:

- `is_primary` (Boolean) If true, this SIM is used for boot. Must be true on single-sim devices.
- `slot` (String) SIM slot being configured. Must be 'sim1' on single-sim devices.

<a id="nestedatt--sims--apns"></a>
### Nested Schema for `sims.apns`

Required:

- `allowed_ip_types` (Set of String) IP versions to support (permitted values include 'ipv4', 'ipv6').
- `name` (String) serial.

Optional:

- `authentication` (Attributes) APN authentication configurations. (see [below for nested schema](#nestedatt--sims--apns--authentication))

<a id="nestedatt--sims--apns--authentication"></a>
### Nested Schema for `sims.apns.authentication`

Optional:

- `password` (String) APN password, if type is set (if APN password is not supplied, the password is left unchanged).
- `type` (String) APN auth type. Valid values are 'chap', 'none', 'pap'.
- `username` (String) APN username, if type is set.




<a id="nestedatt--sim_failover"></a>
### Nested Schema for `sim_failover`

Optional:

- `enabled` (Boolean) Failover to secondary SIM.


29 changes: 29 additions & 0 deletions internal/provider/device_cellular_sims_resource.go
Original file line number Diff line number Diff line change
@@ -223,6 +223,13 @@ func (r *DevicesCellularSimsResource) Create(ctx context.Context, req resource.C

_, httpResp, err := r.client.CellularApi.UpdateDeviceCellularSims(context.Background(), data.Serial.ValueString()).UpdateDeviceCellularSims(updateDeviceCellularSims).Execute()

if err != nil {
resp.Diagnostics.AddError(
"Failed to read resource",
fmt.Sprintf("%v\n", err.Error()),
)
}

if httpResp != nil {
tools.CollectHttpDiagnostics(ctx, &resp.Diagnostics, httpResp)
}
@@ -274,6 +281,14 @@ func (r *DevicesCellularSimsResource) Read(ctx context.Context, req resource.Rea
fmt.Sprintf("%v\n", err.Error()),
)
}

if err != nil {
resp.Diagnostics.AddError(
"Failed to read resource",
fmt.Sprintf("%v\n", err.Error()),
)
}

// collect diagnostics
if httpResp != nil {
tools.CollectHttpDiagnostics(ctx, &resp.Diagnostics, httpResp)
@@ -353,6 +368,13 @@ func (r *DevicesCellularSimsResource) Update(ctx context.Context, req resource.U

_, httpResp, err := r.client.CellularApi.UpdateDeviceCellularSims(context.Background(), data.Serial.ValueString()).UpdateDeviceCellularSims(updateDeviceCellularSims).Execute()

if err != nil {
resp.Diagnostics.AddError(
"Failed to read resource",
fmt.Sprintf("%v\n", err.Error()),
)
}

if httpResp != nil {
tools.CollectHttpDiagnostics(ctx, &resp.Diagnostics, httpResp)
}
@@ -433,6 +455,13 @@ func (r *DevicesCellularSimsResource) Delete(ctx context.Context, req resource.D

_, httpResp, err := r.client.CellularApi.UpdateDeviceCellularSims(context.Background(), data.Serial.ValueString()).UpdateDeviceCellularSims(updateDeviceCellularSims).Execute()

if err != nil {
resp.Diagnostics.AddError(
"Failed to read resource",
fmt.Sprintf("%v\n", err.Error()),
)
}

if httpResp != nil {
tools.CollectHttpDiagnostics(ctx, &resp.Diagnostics, httpResp)
}
12 changes: 5 additions & 7 deletions internal/provider/device_cellular_sims_resource_test.go
Original file line number Diff line number Diff line change
@@ -22,11 +22,8 @@ func TestAccDevicesCellularSimsResource(t *testing.T) {
resource.TestCheckResourceAttr("meraki_network.test", "timezone", "America/Los_Angeles"),
resource.TestCheckResourceAttr("meraki_network.test", "tags.#", "1"),
resource.TestCheckResourceAttr("meraki_network.test", "tags.0", "tag1"),
resource.TestCheckResourceAttr("meraki_network.test", "product_types.#", "4"),
resource.TestCheckResourceAttr("meraki_network.test", "product_types.0", "appliance"),
resource.TestCheckResourceAttr("meraki_network.test", "product_types.1", "cellularGateway"),
resource.TestCheckResourceAttr("meraki_network.test", "product_types.2", "switch"),
resource.TestCheckResourceAttr("meraki_network.test", "product_types.3", "wireless"),
resource.TestCheckResourceAttr("meraki_network.test", "product_types.#", "1"),
resource.TestCheckResourceAttr("meraki_network.test", "product_types.0", "cellularGateway"),
resource.TestCheckResourceAttr("meraki_network.test", "notes", "Additional description of the network"),
),
},
@@ -62,7 +59,7 @@ func testAccDevicesCellularSimsResourceConfigCreate(orgId string) string {
result := fmt.Sprintf(`
resource "meraki_network" "test" {
organization_id = "%s"
product_types = ["appliance", "switch", "wireless", "cellularGateway"]
product_types = ["cellularGateway"]
tags = ["tag1"]
name = "Main Office"
timezone = "America/Los_Angeles"
@@ -78,7 +75,7 @@ func testAccDevicesCellularSimsResourceConfigUpdate(orgId string, serial string)
result := fmt.Sprintf(`
resource "meraki_network" "test" {
organization_id = "%s"
product_types = ["appliance", "switch", "wireless", "cellularGateway"]
product_types = ["cellularGateway"]
}
resource "meraki_networks_devices_claim" "test" {
depends_on = [resource.meraki_network.test]
@@ -88,6 +85,7 @@ resource "meraki_networks_devices_claim" "test" {
]
}
resource "meraki_devices_cellular_sims" "test" {
depends_on = [resource.meraki_network.test, resource.meraki_networks_devices_claim.test]
serial = "%s"
sims = [{
slot = "sim1"

0 comments on commit 37abdb2

Please sign in to comment.