Skip to content

Commit 8b531cb

Browse files
committed
Add organization and inventory claim resources
1 parent 3776273 commit 8b531cb

18 files changed

+1076
-7
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "meraki_network_device_claim Resource - terraform-provider-meraki"
4+
subcategory: "Networks"
5+
description: |-
6+
This resource allows claiming and removing serials to a network. It will not not touch any existing serials already claimed and not included in serials. Removing a serial from a network will return it to the organization inventory.
7+
---
8+
9+
# meraki_network_device_claim (Resource)
10+
11+
This resource allows claiming and removing serials to a network. It will not not touch any existing serials already claimed and not included in `serials`. Removing a serial from a network will return it to the organization inventory.
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "meraki_network_device_claim" "example" {
17+
network_id = "123456"
18+
serials = ["1234-1234-1234"]
19+
}
20+
```
21+
22+
<!-- schema generated by tfplugindocs -->
23+
## Schema
24+
25+
### Required
26+
27+
- `network_id` (String) Netowrk ID
28+
- `serials` (Set of String) A list of serials of devices to claim
29+
30+
### Read-Only
31+
32+
- `id` (String) The id of the object
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "meraki_organization_inventory_claim Resource - terraform-provider-meraki"
4+
subcategory: "Organizations"
5+
description: |-
6+
This resource allows claiming and releasing serials from the organization inventory. It will not not touch any existing serials already claimed and not included in serials.
7+
---
8+
9+
# meraki_organization_inventory_claim (Resource)
10+
11+
This resource allows claiming and releasing serials from the organization inventory. It will not not touch any existing serials already claimed and not included in `serials`.
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "meraki_organization_inventory_claim" "example" {
17+
organization_id = "123456"
18+
serials = ["1234-1234-1234"]
19+
}
20+
```
21+
22+
<!-- schema generated by tfplugindocs -->
23+
## Schema
24+
25+
### Required
26+
27+
- `organization_id` (String) Organization ID
28+
- `serials` (Set of String) The list of serials to be claimed to the organization
29+
30+
### Read-Only
31+
32+
- `id` (String) The id of the object
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
resource "meraki_network_device_claim" "example" {
2+
network_id = "123456"
3+
serials = ["1234-1234-1234"]
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
resource "meraki_organization_inventory_claim" "example" {
2+
organization_id = "123456"
3+
serials = ["1234-1234-1234"]
4+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
name: Network Device Claim
3+
rest_endpoint: /networks/%v/devices/claim
4+
no_data_source: true
5+
no_import: true
6+
doc_category: Networks
7+
test_tags: [TF_VAR_CLAIM_SERIAL_1, TF_VAR_CLAIM_SERIAL_2]
8+
res_description: This resource allows claiming and removing serials to a network. It will not not touch any existing serials already claimed and not included in `serials`. Removing a serial from a network will return it to the organization inventory.
9+
attributes:
10+
- tf_name: network_id
11+
type: String
12+
reference: true
13+
id: true
14+
description: Netowrk ID
15+
example: 123456
16+
test_value: meraki_network.test.id
17+
- model_name: serials
18+
type: Set
19+
element_type: String
20+
mandatory: true
21+
description: A list of serials of devices to claim
22+
example: 1234-1234-1234
23+
test_value: "[var.CLAIM_SERIAL_1]"
24+
25+
test_prerequisites: |
26+
variable "CLAIM_SERIAL_1" {}
27+
variable "CLAIM_SERIAL_2" {}
28+
29+
data "meraki_organization" "test" {
30+
name = "Dev"
31+
}
32+
33+
resource "meraki_network" "test" {
34+
organization_id = data.meraki_organization.test.id
35+
name = "Network1"
36+
product_types = ["appliance", "switch", "wireless"]
37+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: Organization Inventory Claim
3+
rest_endpoint: /organizations/%v/inventory/claim
4+
no_data_source: true
5+
no_import: true
6+
doc_category: Organizations
7+
test_tags: [TF_VAR_CLAIM_SERIAL_1, TF_VAR_CLAIM_SERIAL_2]
8+
res_description: This resource allows claiming and releasing serials from the organization inventory. It will not not touch any existing serials already claimed and not included in `serials`.
9+
attributes:
10+
- tf_name: organization_id
11+
type: String
12+
reference: true
13+
id: true
14+
description: Organization ID
15+
example: 123456
16+
test_value: data.meraki_organization.test.id
17+
- model_name: serials
18+
type: Set
19+
element_type: String
20+
mandatory: true
21+
description: The list of serials to be claimed to the organization
22+
example: 1234-1234-1234
23+
test_value: "[var.CLAIM_SERIAL_1]"
24+
25+
test_prerequisites: |
26+
variable "CLAIM_SERIAL_1" {}
27+
variable "CLAIM_SERIAL_2" {}
28+
29+
data "meraki_organization" "test" {
30+
name = "Dev"
31+
}

gen/schema/schema.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ res_description: str(required=False) # Define a resource description
1515
doc_category: str(required=False) # Define a documentation category
1616
skip_minimum_test: bool(required=False) # Do not perform a "minimum" (only mandatory attributes) test
1717
attributes: list(include('attribute'), required=False) # List of attributes
18-
test_tags: list(str(), required=False) # List of test tags, tests are only executed if an environment variable with one of these tags is configured
18+
test_tags: list(str(), required=False) # List of test tags, tests are only executed if an environment variable with for each of these tags is configured
1919
test_prerequisites: str(required=False) # HCL code that is included in the acceptance tests to define prerequisites
2020
---
2121
attribute:

gen/templates/data_source_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131

3232
func TestAccDataSourceMeraki{{camelCase .Name}}(t *testing.T) {
3333
{{- if len .TestTags}}
34-
if {{range $i, $e := .TestTags}}{{if $i}} && {{end}}os.Getenv("{{$e}}") == ""{{end}} {
34+
if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") == ""{{end}} {
3535
t.Skip("skipping test, set environment variable {{range $i, $e := .TestTags}}{{if $i}} or {{end}}{{$e}}{{end}}")
3636
}
3737
{{- end}}

gen/templates/resource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131

3232
func TestAccMeraki{{camelCase .Name}}(t *testing.T) {
3333
{{- if len .TestTags}}
34-
if {{range $i, $e := .TestTags}}{{if $i}} && {{end}}os.Getenv("{{$e}}") == ""{{end}} {
34+
if {{range $i, $e := .TestTags}}{{if $i}} || {{end}}os.Getenv("{{$e}}") == ""{{end}} {
3535
t.Skip("skipping test, set environment variable {{range $i, $e := .TestTags}}{{if $i}} or {{end}}{{$e}}{{end}}")
3636
}
3737
{{- end}}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/hashicorp/terraform-plugin-go v0.23.0
1212
github.com/hashicorp/terraform-plugin-log v0.9.0
1313
github.com/hashicorp/terraform-plugin-testing v1.10.0
14-
github.com/netascode/go-meraki v0.0.0-20240901102824-a67592c39438
14+
github.com/netascode/go-meraki v0.0.0-20240912063604-fb6bdcff45e5
1515
github.com/tidwall/gjson v1.17.3
1616
github.com/tidwall/sjson v1.2.5
1717
golang.org/x/tools v0.25.0
@@ -88,7 +88,7 @@ require (
8888
golang.org/x/text v0.18.0 // indirect
8989
google.golang.org/appengine v1.6.8 // indirect
9090
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
91-
google.golang.org/grpc v1.66.1 // indirect
91+
google.golang.org/grpc v1.66.2 // indirect
9292
google.golang.org/protobuf v1.34.2 // indirect
9393
gopkg.in/yaml.v2 v2.3.0 // indirect
9494
)

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR
164164
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
165165
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
166166
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
167-
github.com/netascode/go-meraki v0.0.0-20240901102824-a67592c39438 h1:dsFYRJ2aXEddmIz76weQAZ6QzliSmMpVaZxGlW4wTUA=
168-
github.com/netascode/go-meraki v0.0.0-20240901102824-a67592c39438/go.mod h1:xZ/kiJA+SZY32p5t1J9Jdhvtig9BU4SMbxKnfAJrmLE=
167+
github.com/netascode/go-meraki v0.0.0-20240912063604-fb6bdcff45e5 h1:Jt2mPdO+cReX7ClLo++GN4GkHFl9zHllSt4I1+FWzKE=
168+
github.com/netascode/go-meraki v0.0.0-20240912063604-fb6bdcff45e5/go.mod h1:xZ/kiJA+SZY32p5t1J9Jdhvtig9BU4SMbxKnfAJrmLE=
169169
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
170170
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
171171
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
@@ -285,6 +285,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:
285285
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
286286
google.golang.org/grpc v1.66.1 h1:hO5qAXR19+/Z44hmvIM4dQFMSYX9XcWsByfoxutBpAM=
287287
google.golang.org/grpc v1.66.1/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y=
288+
google.golang.org/grpc v1.66.2 h1:3QdXkuq3Bkh7w+ywLdLvM56cmGvQHUMZpiCzt6Rqaoo=
289+
google.golang.org/grpc v1.66.2/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y=
288290
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
289291
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
290292
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright © 2024 Cisco Systems, Inc. and its affiliates.
2+
// All rights reserved.
3+
//
4+
// Licensed under the Mozilla Public License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// https://mozilla.org/MPL/2.0/
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
// SPDX-License-Identifier: MPL-2.0
17+
18+
package provider
19+
20+
// Section below is generated&owned by "gen/generator.go". //template:begin imports
21+
import (
22+
"context"
23+
"fmt"
24+
"net/url"
25+
26+
"github.com/hashicorp/terraform-plugin-framework/types"
27+
"github.com/netascode/terraform-provider-meraki/internal/provider/helpers"
28+
"github.com/tidwall/gjson"
29+
"github.com/tidwall/sjson"
30+
)
31+
32+
// End of section. //template:end imports
33+
34+
// Section below is generated&owned by "gen/generator.go". //template:begin types
35+
36+
type NetworkDeviceClaim struct {
37+
Id types.String `tfsdk:"id"`
38+
NetworkId types.String `tfsdk:"network_id"`
39+
Serials types.Set `tfsdk:"serials"`
40+
}
41+
42+
// End of section. //template:end types
43+
44+
// Section below is generated&owned by "gen/generator.go". //template:begin getPath
45+
46+
func (data NetworkDeviceClaim) getPath() string {
47+
return fmt.Sprintf("/networks/%v/devices/claim", url.QueryEscape(data.NetworkId.ValueString()))
48+
}
49+
50+
// End of section. //template:end getPath
51+
52+
func (data NetworkDeviceClaim) getRemovePath() string {
53+
return fmt.Sprintf("/networks/%v/devices/remove", url.QueryEscape(data.NetworkId.ValueString()))
54+
}
55+
56+
func (data NetworkDeviceClaim) getDevicesPath() string {
57+
return fmt.Sprintf("/networks/%v/devices", url.QueryEscape(data.NetworkId.ValueString()))
58+
}
59+
60+
// Section below is generated&owned by "gen/generator.go". //template:begin toBody
61+
62+
func (data NetworkDeviceClaim) toBody(ctx context.Context, state NetworkDeviceClaim) string {
63+
body := ""
64+
if !data.Serials.IsNull() {
65+
var values []string
66+
data.Serials.ElementsAs(ctx, &values, false)
67+
body, _ = sjson.Set(body, "serials", values)
68+
}
69+
return body
70+
}
71+
72+
// End of section. //template:end toBody
73+
74+
// Section below is generated&owned by "gen/generator.go". //template:begin fromBody
75+
76+
func (data *NetworkDeviceClaim) fromBody(ctx context.Context, res gjson.Result) {
77+
if value := res.Get("serials"); value.Exists() {
78+
data.Serials = helpers.GetStringSet(value.Array())
79+
} else {
80+
data.Serials = types.SetNull(types.StringType)
81+
}
82+
}
83+
84+
// End of section. //template:end fromBody
85+
86+
// Section below is generated&owned by "gen/generator.go". //template:begin fromBodyPartial
87+
88+
// fromBodyPartial reads values from a gjson.Result into a tfstate model. It ignores null attributes in order to
89+
// uncouple the provider from the exact values that the backend API might summon to replace nulls. (Such behavior might
90+
// easily change across versions of the backend API.) For List/Set/Map attributes, the func only updates the
91+
// "managed" elements, instead of all elements.
92+
func (data *NetworkDeviceClaim) fromBodyPartial(ctx context.Context, res gjson.Result) {
93+
if value := res.Get("serials"); value.Exists() && !data.Serials.IsNull() {
94+
data.Serials = helpers.GetStringSet(value.Array())
95+
} else {
96+
data.Serials = types.SetNull(types.StringType)
97+
}
98+
}
99+
100+
// End of section. //template:end fromBodyPartial

0 commit comments

Comments
 (0)