Skip to content

Commit b8dc045

Browse files
committed
Add network snmp resource and data source
1 parent 900c658 commit b8dc045

File tree

12 files changed

+962
-0
lines changed

12 files changed

+962
-0
lines changed

docs/data-sources/network_snmp.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "meraki_network_snmp Data Source - terraform-provider-meraki"
4+
subcategory: "Networks"
5+
description: |-
6+
This data source can read the Network SNMP configuration.
7+
---
8+
9+
# meraki_network_snmp (Data Source)
10+
11+
This data source can read the `Network SNMP` configuration.
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "meraki_network_snmp" "example" {
17+
id = "L_123456"
18+
network_id = "L_123456"
19+
}
20+
```
21+
22+
<!-- schema generated by tfplugindocs -->
23+
## Schema
24+
25+
### Required
26+
27+
- `network_id` (String) Network ID
28+
29+
### Read-Only
30+
31+
- `access` (String) The type of SNMP access. Can be one of `none` (disabled), `community` (V1/V2c), or `users` (V3).
32+
- `community_string` (String) The SNMP community string. Only relevant if `access` is set to `community`.
33+
- `id` (String) The id of the object
34+
- `users` (Attributes List) The list of SNMP users. Only relevant if `access` is set to `users`. (see [below for nested schema](#nestedatt--users))
35+
36+
<a id="nestedatt--users"></a>
37+
### Nested Schema for `users`
38+
39+
Read-Only:
40+
41+
- `passphrase` (String) The passphrase for the SNMP user. Required.
42+
- `username` (String) The username for the SNMP user. Required.

docs/resources/network_snmp.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "meraki_network_snmp Resource - terraform-provider-meraki"
4+
subcategory: "Networks"
5+
description: |-
6+
This resource can manage the Network SNMP configuration.
7+
---
8+
9+
# meraki_network_snmp (Resource)
10+
11+
This resource can manage the `Network SNMP` configuration.
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "meraki_network_snmp" "example" {
17+
network_id = "L_123456"
18+
access = "users"
19+
community_string = "MerakiCommunity"
20+
users = [
21+
{
22+
username = "User1"
23+
passphrase = "Password123"
24+
}
25+
]
26+
}
27+
```
28+
29+
<!-- schema generated by tfplugindocs -->
30+
## Schema
31+
32+
### Required
33+
34+
- `network_id` (String) Network ID
35+
36+
### Optional
37+
38+
- `access` (String) The type of SNMP access. Can be one of `none` (disabled), `community` (V1/V2c), or `users` (V3).
39+
- Choices: `none`, `community`, `users`
40+
- `community_string` (String) The SNMP community string. Only relevant if `access` is set to `community`.
41+
- `users` (Attributes List) The list of SNMP users. Only relevant if `access` is set to `users`. (see [below for nested schema](#nestedatt--users))
42+
43+
### Read-Only
44+
45+
- `id` (String) The id of the object
46+
47+
<a id="nestedatt--users"></a>
48+
### Nested Schema for `users`
49+
50+
Required:
51+
52+
- `passphrase` (String) The passphrase for the SNMP user. Required.
53+
- `username` (String) The username for the SNMP user. Required.
54+
55+
## Import
56+
57+
Import is supported using the following syntax:
58+
59+
```shell
60+
terraform import meraki_network_snmp.example "<network_id>"
61+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
data "meraki_network_snmp" "example" {
2+
id = "L_123456"
3+
network_id = "L_123456"
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform import meraki_network_snmp.example "<network_id>"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
resource "meraki_network_snmp" "example" {
2+
network_id = "L_123456"
3+
access = "users"
4+
community_string = "MerakiCommunity"
5+
users = [
6+
{
7+
username = "User1"
8+
passphrase = "Password123"
9+
}
10+
]
11+
}

gen/definitions/network_snmp.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
name: Network SNMP
3+
rest_endpoint: /networks/%v/snmp
4+
no_delete: true
5+
put_create: true
6+
doc_category: Networks
7+
attributes:
8+
- tf_name: network_id
9+
type: String
10+
id: true
11+
reference: true
12+
description: Network ID
13+
example: L_123456
14+
test_value: meraki_network.test.id
15+
- model_name: access
16+
type: String
17+
enum_values: [none, community, users]
18+
description: The type of SNMP access. Can be one of `none` (disabled), `community` (V1/V2c), or `users` (V3).
19+
example: users
20+
minimum_test_value: '"community"'
21+
- model_name: communityString
22+
type: String
23+
description: The SNMP community string. Only relevant if `access` is set to `community`.
24+
example: MerakiCommunity
25+
minimum_test_value: '"MerakiCommunity"'
26+
exclude_test: true
27+
- model_name: users
28+
type: List
29+
description: The list of SNMP users. Only relevant if `access` is set to `users`.
30+
attributes:
31+
- model_name: username
32+
type: String
33+
description: The username for the SNMP user. Required.
34+
mandatory: true
35+
id: true
36+
example: User1
37+
- model_name: passphrase
38+
type: String
39+
description: The passphrase for the SNMP user. Required.
40+
mandatory: true
41+
example: Password123
42+
43+
test_prerequisites: |
44+
data "meraki_organization" "test" {
45+
name = "Dev"
46+
}
47+
resource "meraki_network" "test" {
48+
organization_id = data.meraki_organization.test.id
49+
name = "Network1"
50+
product_types = ["switch", "wireless"]
51+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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+
25+
"github.com/hashicorp/terraform-plugin-framework/datasource"
26+
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
27+
"github.com/hashicorp/terraform-plugin-log/tflog"
28+
"github.com/netascode/go-meraki"
29+
"github.com/tidwall/gjson"
30+
)
31+
32+
// End of section. //template:end imports
33+
34+
// Section below is generated&owned by "gen/generator.go". //template:begin model
35+
36+
// Ensure the implementation satisfies the expected interfaces.
37+
var (
38+
_ datasource.DataSource = &NetworkSNMPDataSource{}
39+
_ datasource.DataSourceWithConfigure = &NetworkSNMPDataSource{}
40+
)
41+
42+
func NewNetworkSNMPDataSource() datasource.DataSource {
43+
return &NetworkSNMPDataSource{}
44+
}
45+
46+
type NetworkSNMPDataSource struct {
47+
client *meraki.Client
48+
}
49+
50+
func (d *NetworkSNMPDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
51+
resp.TypeName = req.ProviderTypeName + "_network_snmp"
52+
}
53+
54+
func (d *NetworkSNMPDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
55+
resp.Schema = schema.Schema{
56+
// This description is used by the documentation generator and the language server.
57+
MarkdownDescription: "This data source can read the `Network SNMP` configuration.",
58+
59+
Attributes: map[string]schema.Attribute{
60+
"id": schema.StringAttribute{
61+
MarkdownDescription: "The id of the object",
62+
Computed: true,
63+
},
64+
"network_id": schema.StringAttribute{
65+
MarkdownDescription: "Network ID",
66+
Required: true,
67+
},
68+
"access": schema.StringAttribute{
69+
MarkdownDescription: "The type of SNMP access. Can be one of `none` (disabled), `community` (V1/V2c), or `users` (V3).",
70+
Computed: true,
71+
},
72+
"community_string": schema.StringAttribute{
73+
MarkdownDescription: "The SNMP community string. Only relevant if `access` is set to `community`.",
74+
Computed: true,
75+
},
76+
"users": schema.ListNestedAttribute{
77+
MarkdownDescription: "The list of SNMP users. Only relevant if `access` is set to `users`.",
78+
Computed: true,
79+
NestedObject: schema.NestedAttributeObject{
80+
Attributes: map[string]schema.Attribute{
81+
"username": schema.StringAttribute{
82+
MarkdownDescription: "The username for the SNMP user. Required.",
83+
Computed: true,
84+
},
85+
"passphrase": schema.StringAttribute{
86+
MarkdownDescription: "The passphrase for the SNMP user. Required.",
87+
Computed: true,
88+
},
89+
},
90+
},
91+
},
92+
},
93+
}
94+
}
95+
96+
func (d *NetworkSNMPDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) {
97+
if req.ProviderData == nil {
98+
return
99+
}
100+
101+
d.client = req.ProviderData.(*MerakiProviderData).Client
102+
}
103+
104+
// End of section. //template:end model
105+
106+
// Section below is generated&owned by "gen/generator.go". //template:begin read
107+
108+
func (d *NetworkSNMPDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
109+
var config NetworkSNMP
110+
111+
// Read config
112+
diags := req.Config.Get(ctx, &config)
113+
resp.Diagnostics.Append(diags...)
114+
if resp.Diagnostics.HasError() {
115+
return
116+
}
117+
118+
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String()))
119+
120+
var res gjson.Result
121+
var err error
122+
123+
if !res.Exists() {
124+
res, err = d.client.Get(config.getPath())
125+
if err != nil {
126+
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err))
127+
return
128+
}
129+
}
130+
131+
config.fromBody(ctx, res)
132+
config.Id = config.NetworkId
133+
134+
tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.Id.ValueString()))
135+
136+
diags = resp.State.Set(ctx, &config)
137+
resp.Diagnostics.Append(diags...)
138+
}
139+
140+
// End of section. //template:end read

0 commit comments

Comments
 (0)