-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add network vlan profile assignments by device data source
- Loading branch information
Showing
10 changed files
with
461 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
docs/data-sources/network_vlan_profile_assignments_by_device.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "meraki_network_vlan_profile_assignments_by_device Data Source - terraform-provider-meraki" | ||
subcategory: "" | ||
description: |- | ||
This data source can read the Network VLAN Profile Assignments By Device configuration. | ||
--- | ||
|
||
# meraki_network_vlan_profile_assignments_by_device (Data Source) | ||
|
||
This data source can read the `Network VLAN Profile Assignments By Device` configuration. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "meraki_network_vlan_profile_assignments_by_device" "example" { | ||
network_id = "L_123456" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `network_id` (String) Network ID | ||
|
||
### Read-Only | ||
|
||
- `items` (Attributes List) The list of items (see [below for nested schema](#nestedatt--items)) | ||
|
||
<a id="nestedatt--items"></a> | ||
### Nested Schema for `items` | ||
|
||
Read-Only: | ||
|
||
- `id` (String) The id of the object | ||
- `mac` (String) MAC address of the device | ||
- `name` (String) Name of the Device | ||
- `product_type` (String) The product type | ||
- `serial` (String) Serial of the Device | ||
- `stack_id` (String) ID of the Switch Stack | ||
- `vlan_profile_iname` (String) IName of the VLAN Profile | ||
- `vlan_profile_is_default` (Boolean) Is this VLAN profile the default for the network? | ||
- `vlan_profile_name` (String) Name of the VLAN Profile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
examples/data-sources/meraki_network_vlan_profile_assignments_by_device/data-source.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
data "meraki_network_vlan_profile_assignments_by_device" "example" { | ||
network_id = "L_123456" | ||
} |
65 changes: 65 additions & 0 deletions
65
gen/definitions/network_vlan_profile_assignments_by_device.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Network VLAN Profile Assignments By Device | ||
bulk_name: Network VLAN Profile Assignments By Device | ||
spec_endpoint: /networks/{networkId}/vlanProfiles/assignments/byDevice | ||
rest_endpoint: /networks/%v/vlanProfiles/assignments/byDevice | ||
no_data_source: true | ||
no_resource: true | ||
bulk_data_source: true | ||
no_update: true | ||
no_delete: true | ||
data_source_name_query: true | ||
doc_category: Networks | ||
test_variables: [test_org, test_network] | ||
attributes: | ||
- tf_name: network_id | ||
type: String | ||
id: true | ||
reference: true | ||
description: Network ID | ||
example: L_123456 | ||
test_value: meraki_network.test.id | ||
- model_name: mac | ||
type: String | ||
description: MAC address of the device | ||
example: "00:11:22:33:44:55" | ||
- model_name: name | ||
type: String | ||
description: Name of the Device | ||
example: My switch | ||
- model_name: productType | ||
type: String | ||
description: The product type | ||
example: switch | ||
- model_name: serial | ||
type: String | ||
description: Serial of the Device | ||
example: Q234-ABCD-5678 | ||
- model_name: id | ||
type: String | ||
data_path: [stack] | ||
description: ID of the Switch Stack | ||
example: "1234" | ||
- model_name: iname | ||
type: String | ||
data_path: [vlanProfile] | ||
description: IName of the VLAN Profile | ||
example: Profile1 | ||
- model_name: isDefault | ||
type: Bool | ||
data_path: [vlanProfile] | ||
description: Is this VLAN profile the default for the network? | ||
example: "true" | ||
- model_name: name | ||
type: String | ||
data_path: [vlanProfile] | ||
description: Name of the VLAN Profile | ||
example: My VLAN Profile | ||
test_prerequisites: | | ||
data "meraki_organization" "test" { | ||
name = var.test_org | ||
} | ||
resource "meraki_network" "test" { | ||
organization_id = data.meraki_organization.test.id | ||
name = var.test_network | ||
product_types = ["switch", "wireless", "appliance"] | ||
} |
150 changes: 150 additions & 0 deletions
150
internal/provider/data_source_meraki_network_vlan_profile_assignments_by_device.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// 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/CiscoDevNet/terraform-provider-meraki/internal/provider/helpers" | ||
"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" | ||
) | ||
|
||
// 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 = &NetworkVLANProfileAssignmentsByDeviceDataSource{} | ||
_ datasource.DataSourceWithConfigure = &NetworkVLANProfileAssignmentsByDeviceDataSource{} | ||
) | ||
|
||
func NewNetworkVLANProfileAssignmentsByDeviceDataSource() datasource.DataSource { | ||
return &NetworkVLANProfileAssignmentsByDeviceDataSource{} | ||
} | ||
|
||
type NetworkVLANProfileAssignmentsByDeviceDataSource struct { | ||
client *meraki.Client | ||
} | ||
|
||
func (d *NetworkVLANProfileAssignmentsByDeviceDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_network_vlan_profile_assignments_by_device" | ||
} | ||
|
||
func (d *NetworkVLANProfileAssignmentsByDeviceDataSource) 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: helpers.NewAttributeDescription("This data source can read the `Network VLAN Profile Assignments By Device` configuration.").String, | ||
|
||
Attributes: map[string]schema.Attribute{ | ||
"network_id": schema.StringAttribute{ | ||
MarkdownDescription: "Network ID", | ||
Required: true, | ||
}, | ||
"items": schema.ListNestedAttribute{ | ||
MarkdownDescription: "The list of items", | ||
Computed: true, | ||
NestedObject: schema.NestedAttributeObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
MarkdownDescription: "The id of the object", | ||
Computed: true, | ||
}, | ||
"mac": schema.StringAttribute{ | ||
MarkdownDescription: "MAC address of the device", | ||
Computed: true, | ||
}, | ||
"name": schema.StringAttribute{ | ||
MarkdownDescription: "Name of the Device", | ||
Computed: true, | ||
}, | ||
"product_type": schema.StringAttribute{ | ||
MarkdownDescription: "The product type", | ||
Computed: true, | ||
}, | ||
"serial": schema.StringAttribute{ | ||
MarkdownDescription: "Serial of the Device", | ||
Computed: true, | ||
}, | ||
"stack_id": schema.StringAttribute{ | ||
MarkdownDescription: "ID of the Switch Stack", | ||
Computed: true, | ||
}, | ||
"vlan_profile_iname": schema.StringAttribute{ | ||
MarkdownDescription: "IName of the VLAN Profile", | ||
Computed: true, | ||
}, | ||
"vlan_profile_is_default": schema.BoolAttribute{ | ||
MarkdownDescription: "Is this VLAN profile the default for the network?", | ||
Computed: true, | ||
}, | ||
"vlan_profile_name": schema.StringAttribute{ | ||
MarkdownDescription: "Name of the VLAN Profile", | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *NetworkVLANProfileAssignmentsByDeviceDataSource) 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 *NetworkVLANProfileAssignmentsByDeviceDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var config NetworkVLANProfileAssignmentsByDevice | ||
|
||
// 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", "NetworkVLANProfileAssignmentsByDeviceDataSource")) | ||
|
||
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) | ||
|
||
tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", "NetworkVLANProfileAssignmentsByDeviceDataSource")) | ||
|
||
diags = resp.State.Set(ctx, &config) | ||
resp.Diagnostics.Append(diags...) | ||
} | ||
|
||
// End of section. //template:end read |
77 changes: 77 additions & 0 deletions
77
internal/provider/data_source_meraki_network_vlan_profile_assignments_by_device_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// 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 testAccDataSource | ||
|
||
func TestAccDataSourceMerakiNetworkVLANProfileAssignmentsByDevice(t *testing.T) { | ||
if os.Getenv("TF_VAR_test_org") == "" || os.Getenv("TF_VAR_test_network") == "" { | ||
t.Skip("skipping test, set environment variable TF_VAR_test_org and TF_VAR_test_network") | ||
} | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceMerakiNetworkVLANProfileAssignmentsByDevicePrerequisitesConfig + testAccDataSourceMerakiNetworkVLANProfileAssignmentsByDeviceConfig(), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
// End of section. //template:end testAccDataSource | ||
|
||
// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites | ||
|
||
const testAccDataSourceMerakiNetworkVLANProfileAssignmentsByDevicePrerequisitesConfig = ` | ||
variable "test_org" {} | ||
variable "test_network" {} | ||
data "meraki_organization" "test" { | ||
name = var.test_org | ||
} | ||
resource "meraki_network" "test" { | ||
organization_id = data.meraki_organization.test.id | ||
name = var.test_network | ||
product_types = ["switch", "wireless", "appliance"] | ||
} | ||
` | ||
|
||
// End of section. //template:end testPrerequisites | ||
|
||
// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig | ||
|
||
func testAccDataSourceMerakiNetworkVLANProfileAssignmentsByDeviceConfig() string { | ||
config := `data "meraki_network_vlan_profile_assignments_by_device" "test" { | ||
network_id = meraki_network.test.id | ||
} | ||
` | ||
return config | ||
} | ||
|
||
// End of section. //template:end testAccDataSourceConfig |
Oops, something went wrong.