diff --git a/docs/data-sources/switch_routing_multicast_rendezvous_point.md b/docs/data-sources/switch_routing_multicast_rendezvous_point.md new file mode 100644 index 0000000..f9e4148 --- /dev/null +++ b/docs/data-sources/switch_routing_multicast_rendezvous_point.md @@ -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 + +### 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 diff --git a/docs/resources/switch_routing_multicast_rendezvous_point.md b/docs/resources/switch_routing_multicast_rendezvous_point.md new file mode 100644 index 0000000..21c24c0 --- /dev/null +++ b/docs/resources/switch_routing_multicast_rendezvous_point.md @@ -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 + +### 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 "," +``` diff --git a/examples/data-sources/meraki_switch_routing_multicast_rendezvous_point/data-source.tf b/examples/data-sources/meraki_switch_routing_multicast_rendezvous_point/data-source.tf new file mode 100644 index 0000000..4462144 --- /dev/null +++ b/examples/data-sources/meraki_switch_routing_multicast_rendezvous_point/data-source.tf @@ -0,0 +1,4 @@ +data "meraki_switch_routing_multicast_rendezvous_point" "example" { + id = "12345678" + network_id = "L_123456" +} diff --git a/examples/resources/meraki_switch_routing_multicast_rendezvous_point/import.sh b/examples/resources/meraki_switch_routing_multicast_rendezvous_point/import.sh new file mode 100644 index 0000000..804f06e --- /dev/null +++ b/examples/resources/meraki_switch_routing_multicast_rendezvous_point/import.sh @@ -0,0 +1 @@ +terraform import meraki_switch_routing_multicast_rendezvous_point.example "," diff --git a/examples/resources/meraki_switch_routing_multicast_rendezvous_point/resource.tf b/examples/resources/meraki_switch_routing_multicast_rendezvous_point/resource.tf new file mode 100644 index 0000000..d175efb --- /dev/null +++ b/examples/resources/meraki_switch_routing_multicast_rendezvous_point/resource.tf @@ -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" +} diff --git a/gen/definitions/switch_routing_multicast_rendezvous_point.yaml b/gen/definitions/switch_routing_multicast_rendezvous_point.yaml new file mode 100644 index 0000000..e636232 --- /dev/null +++ b/gen/definitions/switch_routing_multicast_rendezvous_point.yaml @@ -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 + } diff --git a/internal/provider/data_source_meraki_switch_routing_multicast_rendezvous_point.go b/internal/provider/data_source_meraki_switch_routing_multicast_rendezvous_point.go new file mode 100644 index 0000000..0ed877e --- /dev/null +++ b/internal/provider/data_source_meraki_switch_routing_multicast_rendezvous_point.go @@ -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 diff --git a/internal/provider/data_source_meraki_switch_routing_multicast_rendezvous_point_test.go b/internal/provider/data_source_meraki_switch_routing_multicast_rendezvous_point_test.go new file mode 100644 index 0000000..09b871b --- /dev/null +++ b/internal/provider/data_source_meraki_switch_routing_multicast_rendezvous_point_test.go @@ -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 diff --git a/internal/provider/model_meraki_switch_routing_multicast_rendezvous_point.go b/internal/provider/model_meraki_switch_routing_multicast_rendezvous_point.go new file mode 100644 index 0000000..e907f02 --- /dev/null +++ b/internal/provider/model_meraki_switch_routing_multicast_rendezvous_point.go @@ -0,0 +1,103 @@ +// 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/types" + "github.com/tidwall/gjson" + "github.com/tidwall/sjson" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin types + +type SwitchRoutingMulticastRendezvousPoint struct { + Id types.String `tfsdk:"id"` + NetworkId types.String `tfsdk:"network_id"` + InterfaceIp types.String `tfsdk:"interface_ip"` + MulticastGroup types.String `tfsdk:"multicast_group"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath + +func (data SwitchRoutingMulticastRendezvousPoint) getPath() string { + return fmt.Sprintf("/networks/%v/switch/routing/multicast/rendezvousPoints", url.QueryEscape(data.NetworkId.ValueString())) +} + +// End of section. //template:end getPath + +// Section below is generated&owned by "gen/generator.go". //template:begin toBody + +func (data SwitchRoutingMulticastRendezvousPoint) toBody(ctx context.Context, state SwitchRoutingMulticastRendezvousPoint) string { + body := "" + if !data.InterfaceIp.IsNull() { + body, _ = sjson.Set(body, "interfaceIp", data.InterfaceIp.ValueString()) + } + if !data.MulticastGroup.IsNull() { + body, _ = sjson.Set(body, "multicastGroup", data.MulticastGroup.ValueString()) + } + return body +} + +// End of section. //template:end toBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBody + +func (data *SwitchRoutingMulticastRendezvousPoint) fromBody(ctx context.Context, res gjson.Result) { + if value := res.Get("interfaceIp"); value.Exists() { + data.InterfaceIp = types.StringValue(value.String()) + } else { + data.InterfaceIp = types.StringNull() + } + if value := res.Get("multicastGroup"); value.Exists() { + data.MulticastGroup = types.StringValue(value.String()) + } else { + data.MulticastGroup = types.StringNull() + } +} + +// End of section. //template:end fromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBodyPartial + +// fromBodyPartial reads values from a gjson.Result into a tfstate model. It ignores null attributes in order to +// uncouple the provider from the exact values that the backend API might summon to replace nulls. (Such behavior might +// easily change across versions of the backend API.) For List/Set/Map attributes, the func only updates the +// "managed" elements, instead of all elements. +func (data *SwitchRoutingMulticastRendezvousPoint) fromBodyPartial(ctx context.Context, res gjson.Result) { + if value := res.Get("interfaceIp"); value.Exists() && !data.InterfaceIp.IsNull() { + data.InterfaceIp = types.StringValue(value.String()) + } else { + data.InterfaceIp = types.StringNull() + } + if value := res.Get("multicastGroup"); value.Exists() && !data.MulticastGroup.IsNull() { + data.MulticastGroup = types.StringValue(value.String()) + } else { + data.MulticastGroup = types.StringNull() + } +} + +// End of section. //template:end fromBodyPartial diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 13d7e5a..dbd1a5b 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -240,6 +240,7 @@ func (p *MerakiProvider) Resources(ctx context.Context) []func() resource.Resour NewSwitchQoSRuleOrderResource, NewSwitchRoutingInterfaceResource, NewSwitchRoutingMulticastResource, + NewSwitchRoutingMulticastRendezvousPointResource, } } @@ -266,6 +267,7 @@ func (p *MerakiProvider) DataSources(ctx context.Context) []func() datasource.Da NewSwitchQoSRuleOrderDataSource, NewSwitchRoutingInterfaceDataSource, NewSwitchRoutingMulticastDataSource, + NewSwitchRoutingMulticastRendezvousPointDataSource, } } diff --git a/internal/provider/resource_meraki_switch_routing_multicast_rendezvous_point.go b/internal/provider/resource_meraki_switch_routing_multicast_rendezvous_point.go new file mode 100644 index 0000000..da51cff --- /dev/null +++ b/internal/provider/resource_meraki_switch_routing_multicast_rendezvous_point.go @@ -0,0 +1,253 @@ +// 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" + "strings" + + "github.com/CiscoDevNet/terraform-provider-meraki/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/netascode/go-meraki" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin model + +// Ensure provider defined types fully satisfy framework interfaces +var ( + _ resource.Resource = &SwitchRoutingMulticastRendezvousPointResource{} + _ resource.ResourceWithImportState = &SwitchRoutingMulticastRendezvousPointResource{} +) + +func NewSwitchRoutingMulticastRendezvousPointResource() resource.Resource { + return &SwitchRoutingMulticastRendezvousPointResource{} +} + +type SwitchRoutingMulticastRendezvousPointResource struct { + client *meraki.Client +} + +func (r *SwitchRoutingMulticastRendezvousPointResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_switch_routing_multicast_rendezvous_point" +} + +func (r *SwitchRoutingMulticastRendezvousPointResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: helpers.NewAttributeDescription("This resource can manage the `Switch Routing Multicast Rendezvous Point` configuration.").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "network_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Network ID").String, + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "interface_ip": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("The IP address of the interface where the RP needs to be created.").String, + Required: true, + }, + "multicast_group": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("`Any`, or the IP address of a multicast group").String, + Required: true, + }, + }, + } +} + +func (r *SwitchRoutingMulticastRendezvousPointResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + + r.client = req.ProviderData.(*MerakiProviderData).Client +} + +// End of section. //template:end model + +// Section below is generated&owned by "gen/generator.go". //template:begin create + +func (r *SwitchRoutingMulticastRendezvousPointResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan SwitchRoutingMulticastRendezvousPoint + + // Read plan + diags := req.Plan.Get(ctx, &plan) + if resp.Diagnostics.Append(diags...); resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Id.ValueString())) + + // Create object + body := plan.toBody(ctx, SwitchRoutingMulticastRendezvousPoint{}) + res, err := r.client.Post(plan.getPath(), body) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (POST/PUT), got error: %s, %s", err, res.String())) + return + } + plan.Id = types.StringValue(res.Get("rendezvousPointId").String()) + + tflog.Debug(ctx, fmt.Sprintf("%s: Create finished successfully", plan.Id.ValueString())) + + diags = resp.State.Set(ctx, &plan) + resp.Diagnostics.Append(diags...) + + helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) +} + +// End of section. //template:end create + +// Section below is generated&owned by "gen/generator.go". //template:begin read + +func (r *SwitchRoutingMulticastRendezvousPointResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state SwitchRoutingMulticastRendezvousPoint + + // Read state + diags := req.State.Get(ctx, &state) + if resp.Diagnostics.Append(diags...); resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Id.String())) + res, err := r.client.Get(state.getPath() + "/" + url.QueryEscape(state.Id.ValueString())) + if err != nil && strings.Contains(err.Error(), "StatusCode 404") { + resp.State.RemoveResource(ctx) + return + } else if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String())) + return + } + + imp, diags := helpers.IsFlagImporting(ctx, req) + if resp.Diagnostics.Append(diags...); resp.Diagnostics.HasError() { + return + } + + // After `terraform import` we switch to a full read. + if imp { + state.fromBody(ctx, res) + } else { + state.fromBodyPartial(ctx, res) + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", state.Id.ValueString())) + + diags = resp.State.Set(ctx, &state) + resp.Diagnostics.Append(diags...) + + helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics) +} + +// End of section. //template:end read + +// Section below is generated&owned by "gen/generator.go". //template:begin update + +func (r *SwitchRoutingMulticastRendezvousPointResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state SwitchRoutingMulticastRendezvousPoint + + // Read plan + diags := req.Plan.Get(ctx, &plan) + if resp.Diagnostics.Append(diags...); resp.Diagnostics.HasError() { + return + } + + // Read state + diags = req.State.Get(ctx, &state) + if resp.Diagnostics.Append(diags...); resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Id.ValueString())) + + body := plan.toBody(ctx, state) + res, err := r.client.Put(plan.getPath()+"/"+url.QueryEscape(plan.Id.ValueString()), body) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (PUT), got error: %s, %s", err, res.String())) + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Update finished successfully", plan.Id.ValueString())) + + diags = resp.State.Set(ctx, &plan) + resp.Diagnostics.Append(diags...) +} + +// End of section. //template:end update + +// Section below is generated&owned by "gen/generator.go". //template:begin delete + +func (r *SwitchRoutingMulticastRendezvousPointResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state SwitchRoutingMulticastRendezvousPoint + + // Read state + diags := req.State.Get(ctx, &state) + if resp.Diagnostics.Append(diags...); resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Id.ValueString())) + res, err := r.client.Delete(state.getPath() + "/" + url.QueryEscape(state.Id.ValueString())) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (DELETE), got error: %s, %s", err, res.String())) + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Delete finished successfully", state.Id.ValueString())) + + resp.State.RemoveResource(ctx) +} + +// End of section. //template:end delete + +// Section below is generated&owned by "gen/generator.go". //template:begin import +func (r *SwitchRoutingMulticastRendezvousPointResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + idParts := strings.Split(req.ID, ",") + + if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", + fmt.Sprintf("Expected import identifier with format: ,. Got: %q", req.ID), + ) + return + } + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("network_id"), idParts[0])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), idParts[1])...) + + helpers.SetFlagImporting(ctx, true, resp.Private, &resp.Diagnostics) +} + +// End of section. //template:end import diff --git a/internal/provider/resource_meraki_switch_routing_multicast_rendezvous_point_test.go b/internal/provider/resource_meraki_switch_routing_multicast_rendezvous_point_test.go new file mode 100644 index 0000000..ee4e57b --- /dev/null +++ b/internal/provider/resource_meraki_switch_routing_multicast_rendezvous_point_test.go @@ -0,0 +1,109 @@ +// 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 ( + "os" + "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 testAcc + +func TestAccMerakiSwitchRoutingMulticastRendezvousPoint(t *testing.T) { + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("meraki_switch_routing_multicast_rendezvous_point.test", "multicast_group", "Any")) + + var steps []resource.TestStep + if os.Getenv("SKIP_MINIMUM_TEST") == "" { + steps = append(steps, resource.TestStep{ + Config: testAccMerakiSwitchRoutingMulticastRendezvousPointPrerequisitesConfig + testAccMerakiSwitchRoutingMulticastRendezvousPointConfig_minimum(), + }) + } + steps = append(steps, resource.TestStep{ + Config: testAccMerakiSwitchRoutingMulticastRendezvousPointPrerequisitesConfig + testAccMerakiSwitchRoutingMulticastRendezvousPointConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: steps, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites + +const testAccMerakiSwitchRoutingMulticastRendezvousPointPrerequisitesConfig = ` +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 testAccConfigMinimal + +func testAccMerakiSwitchRoutingMulticastRendezvousPointConfig_minimum() 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" + return config +} + +// End of section. //template:end testAccConfigMinimal + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll + +func testAccMerakiSwitchRoutingMulticastRendezvousPointConfig_all() 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" + return config +} + +// End of section. //template:end testAccConfigAll