Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/data-sources/organization_snmp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "meraki_organization_snmp Data Source - terraform-provider-meraki"
subcategory: "Organizations"
description: |-
This data source can read the Organization SNMP configuration.
---

# meraki_organization_snmp (Data Source)

This data source can read the `Organization SNMP` configuration.

## Example Usage

```terraform
data "meraki_organization_snmp" "example" {
organization_id = "123"
}
```

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

### Required

- `organization_id` (String) Organization ID

### Read-Only

- `id` (String) The id of the object
- `peer_ips` (List of String) The list of IPv4 addresses that are allowed to access the SNMP server.
- `v2c_enabled` (Boolean) Boolean indicating whether SNMP version 2c is enabled for the organization.
- `v3_auth_mode` (String) The SNMP version 3 authentication mode. Can be either `MD5` or `SHA`.
- `v3_auth_pass` (String) The SNMP version 3 authentication password. Must be at least 8 characters if specified.
- `v3_enabled` (Boolean) Boolean indicating whether SNMP version 3 is enabled for the organization.
- `v3_priv_mode` (String) The SNMP version 3 privacy mode. Can be either `DES` or `AES128`.
- `v3_priv_pass` (String) The SNMP version 3 privacy password. Must be at least 8 characters if specified.
57 changes: 57 additions & 0 deletions docs/resources/organization_snmp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "meraki_organization_snmp Resource - terraform-provider-meraki"
subcategory: "Organizations"
description: |-
This resource can manage the Organization SNMP configuration.
---

# meraki_organization_snmp (Resource)

This resource can manage the `Organization SNMP` configuration.

## Example Usage

```terraform
resource "meraki_organization_snmp" "example" {
organization_id = "123"
v2c_enabled = false
v3_auth_mode = "SHA"
v3_auth_pass = "password"
v3_enabled = true
v3_priv_mode = "AES128"
v3_priv_pass = "password"
peer_ips = ["123.123.123.1"]
}
```

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

### Required

- `organization_id` (String) Organization ID

### Optional

- `peer_ips` (List of String) The list of IPv4 addresses that are allowed to access the SNMP server.
- `v2c_enabled` (Boolean) Boolean indicating whether SNMP version 2c is enabled for the organization.
- `v3_auth_mode` (String) The SNMP version 3 authentication mode. Can be either `MD5` or `SHA`.
- Choices: `MD5`, `SHA`
- `v3_auth_pass` (String) The SNMP version 3 authentication password. Must be at least 8 characters if specified.
- `v3_enabled` (Boolean) Boolean indicating whether SNMP version 3 is enabled for the organization.
- `v3_priv_mode` (String) The SNMP version 3 privacy mode. Can be either `DES` or `AES128`.
- Choices: `AES128`, `DES`
- `v3_priv_pass` (String) The SNMP version 3 privacy password. Must be at least 8 characters if specified.

### Read-Only

- `id` (String) The id of the object

## Import

Import is supported using the following syntax:

```shell
terraform import meraki_organization_snmp.example "<organization_id>"
```
3 changes: 3 additions & 0 deletions examples/data-sources/meraki_organization_snmp/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "meraki_organization_snmp" "example" {
organization_id = "123"
}
1 change: 1 addition & 0 deletions examples/resources/meraki_organization_snmp/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import meraki_organization_snmp.example "<organization_id>"
10 changes: 10 additions & 0 deletions examples/resources/meraki_organization_snmp/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "meraki_organization_snmp" "example" {
organization_id = "123"
v2c_enabled = false
v3_auth_mode = "SHA"
v3_auth_pass = "password"
v3_enabled = true
v3_priv_mode = "AES128"
v3_priv_pass = "password"
peer_ips = ["123.123.123.1"]
}
53 changes: 53 additions & 0 deletions gen/definitions/organization_snmp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# @endpoint: /organizations/{organizationId}/snmp
name: Organization SNMP
rest_endpoint: /organizations/%v/snmp
put_create: true
no_delete: true
doc_category: Organizations
test_variables: [test_org]
attributes:
- tf_name: organization_id
type: String
id: true
reference: true
description: Organization ID
example: "123"
test_value: data.meraki_organization.test.id
- model_name: v2cEnabled
type: Bool
description: Boolean indicating whether SNMP version 2c is enabled for the organization.
example: "false"
minimum_test_value: "false"
- model_name: v3AuthMode
type: String
description: The SNMP version 3 authentication mode. Can be either `MD5` or `SHA`.
example: SHA
enum_values: [MD5, SHA]
- model_name: v3AuthPass
type: String
write_only: true
description: The SNMP version 3 authentication password. Must be at least 8 characters if specified.
example: password
- model_name: v3Enabled
type: Bool
description: Boolean indicating whether SNMP version 3 is enabled for the organization.
example: "true"
- model_name: v3PrivMode
type: String
description: The SNMP version 3 privacy mode. Can be either `DES` or `AES128`.
example: AES128
enum_values: [AES128, DES]
- model_name: v3PrivPass
type: String
write_only: true
description: The SNMP version 3 privacy password. Must be at least 8 characters if specified.
example: password
- model_name: peerIps
type: List
element_type: String
description: The list of IPv4 addresses that are allowed to access the SNMP server.
example: 123.123.123.1
test_prerequisites: |
data "meraki_organization" "test" {
name = var.test_org
}
2 changes: 1 addition & 1 deletion gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func updateDefinitions() {
}
cmd := exec.Command("go", "run", "gen/definition.go", commentsEndpoint, config.Name)
if out, err := cmd.Output(); err != nil {
log.Fatal(out, err)
log.Fatal(string(out), err)
}
}
}
Expand Down
146 changes: 146 additions & 0 deletions internal/provider/data_source_meraki_organization_snmp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// Copyright © 2024 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// Licensed under the Mozilla Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://mozilla.org/MPL/2.0/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: MPL-2.0

package provider

// Section below is generated&owned by "gen/generator.go". //template:begin imports
import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/netascode/go-meraki"
"github.com/tidwall/gjson"
)

// End of section. //template:end imports

// Section below is generated&owned by "gen/generator.go". //template:begin model

// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &OrganizationSNMPDataSource{}
_ datasource.DataSourceWithConfigure = &OrganizationSNMPDataSource{}
)

func NewOrganizationSNMPDataSource() datasource.DataSource {
return &OrganizationSNMPDataSource{}
}

type OrganizationSNMPDataSource struct {
client *meraki.Client
}

func (d *OrganizationSNMPDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_organization_snmp"
}

func (d *OrganizationSNMPDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
// This description is used by the documentation generator and the language server.
MarkdownDescription: "This data source can read the `Organization SNMP` configuration.",

Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "The id of the object",
Computed: true,
},
"organization_id": schema.StringAttribute{
MarkdownDescription: "Organization ID",
Required: true,
},
"v2c_enabled": schema.BoolAttribute{
MarkdownDescription: "Boolean indicating whether SNMP version 2c is enabled for the organization.",
Computed: true,
},
"v3_auth_mode": schema.StringAttribute{
MarkdownDescription: "The SNMP version 3 authentication mode. Can be either `MD5` or `SHA`.",
Computed: true,
},
"v3_auth_pass": schema.StringAttribute{
MarkdownDescription: "The SNMP version 3 authentication password. Must be at least 8 characters if specified.",
Computed: true,
},
"v3_enabled": schema.BoolAttribute{
MarkdownDescription: "Boolean indicating whether SNMP version 3 is enabled for the organization.",
Computed: true,
},
"v3_priv_mode": schema.StringAttribute{
MarkdownDescription: "The SNMP version 3 privacy mode. Can be either `DES` or `AES128`.",
Computed: true,
},
"v3_priv_pass": schema.StringAttribute{
MarkdownDescription: "The SNMP version 3 privacy password. Must be at least 8 characters if specified.",
Computed: true,
},
"peer_ips": schema.ListAttribute{
MarkdownDescription: "The list of IPv4 addresses that are allowed to access the SNMP server.",
ElementType: types.StringType,
Computed: true,
},
},
}
}

func (d *OrganizationSNMPDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}

d.client = req.ProviderData.(*MerakiProviderData).Client
}

// End of section. //template:end model

// Section below is generated&owned by "gen/generator.go". //template:begin read

func (d *OrganizationSNMPDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config OrganizationSNMP

// Read config
diags := req.Config.Get(ctx, &config)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String()))

var res gjson.Result
var err error

if !res.Exists() {
res, err = d.client.Get(config.getPath())
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err))
return
}
}

config.fromBody(ctx, res)
config.Id = config.OrganizationId

tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.Id.ValueString()))

diags = resp.State.Set(ctx, &config)
resp.Diagnostics.Append(diags...)
}

// End of section. //template:end read
Loading
Loading