-
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 policies by client data source
- Loading branch information
Showing
10 changed files
with
489 additions
and
0 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
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,57 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "meraki_network_policies_by_client Data Source - terraform-provider-meraki" | ||
subcategory: "" | ||
description: |- | ||
This data source can read the Network Policies By Client configuration. | ||
--- | ||
|
||
# meraki_network_policies_by_client (Data Source) | ||
|
||
This data source can read the `Network Policies By Client` configuration. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "meraki_network_policies_by_client" "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: | ||
|
||
- `assigned` (Attributes List) Assigned policies (see [below for nested schema](#nestedatt--items--assigned)) | ||
- `client_id` (String) ID of client | ||
- `id` (String) The id of the object | ||
- `name` (String) Name of client | ||
|
||
<a id="nestedatt--items--assigned"></a> | ||
### Nested Schema for `items.assigned` | ||
|
||
Read-Only: | ||
|
||
- `group_policy_id` (String) id of policy | ||
- `name` (String) name of policy | ||
- `ssid` (Attributes List) ssid (see [below for nested schema](#nestedatt--items--assigned--ssid)) | ||
- `type` (String) type of policy | ||
|
||
<a id="nestedatt--items--assigned--ssid"></a> | ||
### Nested Schema for `items.assigned.ssid` | ||
|
||
Read-Only: | ||
|
||
- `ssid_number` (Number) number of ssid |
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_policies_by_client/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_policies_by_client" "example" { | ||
network_id = "L_123456" | ||
} |
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,61 @@ | ||
name: Network Policies By Client | ||
bulk_name: Network Policies By Client | ||
spec_endpoint: /networks/{networkId}/policies/byClient | ||
rest_endpoint: /networks/%v/policies/byClient | ||
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: clientId | ||
type: String | ||
description: ID of client | ||
example: abc | ||
- model_name: name | ||
type: String | ||
description: Name of client | ||
example: my phone | ||
- model_name: assigned | ||
type: List | ||
description: Assigned policies | ||
attributes: | ||
- model_name: groupPolicyId | ||
type: String | ||
description: id of policy | ||
example: "100" | ||
- model_name: name | ||
type: String | ||
description: name of policy | ||
example: Allowed | ||
- model_name: type | ||
type: String | ||
description: type of policy | ||
example: ssid | ||
- model_name: ssid | ||
type: List | ||
description: ssid | ||
attributes: | ||
- model_name: ssidNumber | ||
type: Int64 | ||
description: number of ssid | ||
example: "1" | ||
test_prerequisites: |2 | ||
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"] | ||
} |
158 changes: 158 additions & 0 deletions
158
internal/provider/data_source_meraki_network_policies_by_client.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,158 @@ | ||
// 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 = &NetworkPoliciesByClientDataSource{} | ||
_ datasource.DataSourceWithConfigure = &NetworkPoliciesByClientDataSource{} | ||
) | ||
|
||
func NewNetworkPoliciesByClientDataSource() datasource.DataSource { | ||
return &NetworkPoliciesByClientDataSource{} | ||
} | ||
|
||
type NetworkPoliciesByClientDataSource struct { | ||
client *meraki.Client | ||
} | ||
|
||
func (d *NetworkPoliciesByClientDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_network_policies_by_client" | ||
} | ||
|
||
func (d *NetworkPoliciesByClientDataSource) 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 Policies By Client` 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, | ||
}, | ||
"client_id": schema.StringAttribute{ | ||
MarkdownDescription: "ID of client", | ||
Computed: true, | ||
}, | ||
"name": schema.StringAttribute{ | ||
MarkdownDescription: "Name of client", | ||
Computed: true, | ||
}, | ||
"assigned": schema.ListNestedAttribute{ | ||
MarkdownDescription: "Assigned policies", | ||
Computed: true, | ||
NestedObject: schema.NestedAttributeObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"group_policy_id": schema.StringAttribute{ | ||
MarkdownDescription: "id of policy", | ||
Computed: true, | ||
}, | ||
"name": schema.StringAttribute{ | ||
MarkdownDescription: "name of policy", | ||
Computed: true, | ||
}, | ||
"type": schema.StringAttribute{ | ||
MarkdownDescription: "type of policy", | ||
Computed: true, | ||
}, | ||
"ssid": schema.ListNestedAttribute{ | ||
MarkdownDescription: "ssid", | ||
Computed: true, | ||
NestedObject: schema.NestedAttributeObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"ssid_number": schema.Int64Attribute{ | ||
MarkdownDescription: "number of ssid", | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *NetworkPoliciesByClientDataSource) 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 *NetworkPoliciesByClientDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var config NetworkPoliciesByClient | ||
|
||
// 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", "NetworkPoliciesByClientDataSource")) | ||
|
||
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", "NetworkPoliciesByClientDataSource")) | ||
|
||
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_policies_by_client_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 TestAccDataSourceMerakiNetworkPoliciesByClient(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: testAccDataSourceMerakiNetworkPoliciesByClientPrerequisitesConfig + testAccDataSourceMerakiNetworkPoliciesByClientConfig(), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
// End of section. //template:end testAccDataSource | ||
|
||
// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites | ||
|
||
const testAccDataSourceMerakiNetworkPoliciesByClientPrerequisitesConfig = ` | ||
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 testAccDataSourceMerakiNetworkPoliciesByClientConfig() string { | ||
config := `data "meraki_network_policies_by_client" "test" { | ||
network_id = meraki_network.test.id | ||
} | ||
` | ||
return config | ||
} | ||
|
||
// End of section. //template:end testAccDataSourceConfig |
Oops, something went wrong.