Skip to content

Commit

Permalink
Add switch routing multicast rendezvous point resource and data sourxe
Browse files Browse the repository at this point in the history
  • Loading branch information
danischm committed Sep 16, 2024
1 parent 2efca84 commit 193b432
Show file tree
Hide file tree
Showing 12 changed files with 815 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/data-sources/switch_routing_multicast_rendezvous_point.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "meraki_switch_routing_multicast_rendezvous_point Data Source - terraform-provider-meraki"
subcategory: "Switches"
description: |-
This data source can read the Switch Routing Multicast Rendezvous Point configuration.
---

# meraki_switch_routing_multicast_rendezvous_point (Data Source)

This data source can read the `Switch Routing Multicast Rendezvous Point` configuration.

## Example Usage

```terraform
data "meraki_switch_routing_multicast_rendezvous_point" "example" {
id = "12345678"
network_id = "L_123456"
}
```

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

### Required

- `id` (String) The id of the object
- `network_id` (String) Network ID

### Read-Only

- `interface_ip` (String) The IP address of the interface where the RP needs to be created.
- `multicast_group` (String) `Any`, or the IP address of a multicast group
42 changes: 42 additions & 0 deletions docs/resources/switch_routing_multicast_rendezvous_point.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "meraki_switch_routing_multicast_rendezvous_point Resource - terraform-provider-meraki"
subcategory: "Switches"
description: |-
This resource can manage the Switch Routing Multicast Rendezvous Point configuration.
---

# meraki_switch_routing_multicast_rendezvous_point (Resource)

This resource can manage the `Switch Routing Multicast Rendezvous Point` configuration.

## Example Usage

```terraform
resource "meraki_switch_routing_multicast_rendezvous_point" "example" {
network_id = "L_123456"
interface_ip = "192.168.1.2"
multicast_group = "Any"
}
```

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

### Required

- `interface_ip` (String) The IP address of the interface where the RP needs to be created.
- `multicast_group` (String) `Any`, or the IP address of a multicast group
- `network_id` (String) Network ID

### Read-Only

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

## Import

Import is supported using the following syntax:

```shell
terraform import meraki_switch_routing_multicast_rendezvous_point.example "<network_id>,<id>"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data "meraki_switch_routing_multicast_rendezvous_point" "example" {
id = "12345678"
network_id = "L_123456"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import meraki_switch_routing_multicast_rendezvous_point.example "<network_id>,<id>"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "meraki_switch_routing_multicast_rendezvous_point" "example" {
network_id = "L_123456"
interface_ip = "192.168.1.2"
multicast_group = "Any"
}
44 changes: 44 additions & 0 deletions gen/definitions/switch_routing_multicast_rendezvous_point.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Switch Routing Multicast Rendezvous Point
rest_endpoint: /networks/%v/switch/routing/multicast/rendezvousPoints
id_name: rendezvousPointId
doc_category: Switches
attributes:
- tf_name: network_id
type: String
reference: true
description: Network ID
example: L_123456
test_value: meraki_network.test.id
- model_name: interfaceIp
type: String
mandatory: true
description: The IP address of the interface where the RP needs to be created.
example: 192.168.1.2
test_value: meraki_switch_routing_interface.test.interface_ip
- model_name: multicastGroup
type: String
mandatory: true
description: '`Any`, or the IP address of a multicast group'
example: Any
test_prerequisites: |
data "meraki_organization" "test" {
name = "Dev"
}
resource "meraki_network" "test" {
organization_id = data.meraki_organization.test.id
name = "Network1"
product_types = ["switch", "wireless"]
}
resource "meraki_network_device_claim" "test" {
network_id = meraki_network.test.id
serials = ["Q5KD-PCG4-HB8R"]
}
resource "meraki_switch_routing_interface" "test" {
serial = tolist(meraki_network_device_claim.test.serials)[0]
default_gateway = "192.168.1.1"
interface_ip = "192.168.1.2"
multicast_routing = "enabled"
name = "L3 interface"
subnet = "192.168.1.0/24"
vlan_id = 100
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// 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"
"net/url"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"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 = &SwitchRoutingMulticastRendezvousPointDataSource{}
_ datasource.DataSourceWithConfigure = &SwitchRoutingMulticastRendezvousPointDataSource{}
)

func NewSwitchRoutingMulticastRendezvousPointDataSource() datasource.DataSource {
return &SwitchRoutingMulticastRendezvousPointDataSource{}
}

type SwitchRoutingMulticastRendezvousPointDataSource struct {
client *meraki.Client
}

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

func (d *SwitchRoutingMulticastRendezvousPointDataSource) 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 `Switch Routing Multicast Rendezvous Point` configuration.",

Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "The id of the object",
Required: true,
},
"network_id": schema.StringAttribute{
MarkdownDescription: "Network ID",
Required: true,
},
"interface_ip": schema.StringAttribute{
MarkdownDescription: "The IP address of the interface where the RP needs to be created.",
Computed: true,
},
"multicast_group": schema.StringAttribute{
MarkdownDescription: "`Any`, or the IP address of a multicast group",
Computed: true,
},
},
}
}

func (d *SwitchRoutingMulticastRendezvousPointDataSource) 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 *SwitchRoutingMulticastRendezvousPointDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config SwitchRoutingMulticastRendezvousPoint

// 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() + "/" + url.QueryEscape(config.Id.ValueString()))
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err))
return
}
}

config.fromBody(ctx, res)

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// 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 (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

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

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

func TestAccDataSourceMerakiSwitchRoutingMulticastRendezvousPoint(t *testing.T) {
var checks []resource.TestCheckFunc
checks = append(checks, resource.TestCheckResourceAttr("data.meraki_switch_routing_multicast_rendezvous_point.test", "multicast_group", "Any"))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceMerakiSwitchRoutingMulticastRendezvousPointPrerequisitesConfig + testAccDataSourceMerakiSwitchRoutingMulticastRendezvousPointConfig(),
Check: resource.ComposeTestCheckFunc(checks...),
},
},
})
}

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

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

const testAccDataSourceMerakiSwitchRoutingMulticastRendezvousPointPrerequisitesConfig = `
data "meraki_organization" "test" {
name = "Dev"
}
resource "meraki_network" "test" {
organization_id = data.meraki_organization.test.id
name = "Network1"
product_types = ["switch", "wireless"]
}
resource "meraki_network_device_claim" "test" {
network_id = meraki_network.test.id
serials = ["Q5KD-PCG4-HB8R"]
}
resource "meraki_switch_routing_interface" "test" {
serial = tolist(meraki_network_device_claim.test.serials)[0]
default_gateway = "192.168.1.1"
interface_ip = "192.168.1.2"
multicast_routing = "enabled"
name = "L3 interface"
subnet = "192.168.1.0/24"
vlan_id = 100
}
`

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

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

func testAccDataSourceMerakiSwitchRoutingMulticastRendezvousPointConfig() string {
config := `resource "meraki_switch_routing_multicast_rendezvous_point" "test" {` + "\n"
config += ` network_id = meraki_network.test.id` + "\n"
config += ` interface_ip = meraki_switch_routing_interface.test.interface_ip` + "\n"
config += ` multicast_group = "Any"` + "\n"
config += `}` + "\n"

config += `
data "meraki_switch_routing_multicast_rendezvous_point" "test" {
id = meraki_switch_routing_multicast_rendezvous_point.test.id
network_id = meraki_network.test.id
}
`
return config
}

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

0 comments on commit 193b432

Please sign in to comment.