Skip to content

Commit 6e9e204

Browse files
author
Marcin Parafiniuk
committed
network_settings example
1 parent 7562c30 commit 6e9e204

27 files changed

+814
-16
lines changed

docs/data-sources/network_settings.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "meraki_network_settings Data Source - terraform-provider-meraki"
4+
subcategory: "Networks"
5+
description: |-
6+
This data source can read the Network Settings configuration.
7+
---
8+
9+
# meraki_network_settings (Data Source)
10+
11+
This data source can read the `Network Settings` configuration.
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "meraki_network_settings" "example" {
17+
id = "12345678"
18+
network_id = "L_123456"
19+
}
20+
```
21+
22+
<!-- schema generated by tfplugindocs -->
23+
## Schema
24+
25+
### Required
26+
27+
- `id` (String) The id of the object
28+
- `network_id` (String) Network ID
29+
30+
### Read-Only
31+
32+
- `local_status_page_enabled` (Boolean) asdasdas

docs/resources/network_settings.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "meraki_network_settings Resource - terraform-provider-meraki"
4+
subcategory: "Networks"
5+
description: |-
6+
This resource can manage the Network Settings configuration.
7+
---
8+
9+
# meraki_network_settings (Resource)
10+
11+
This resource can manage the `Network Settings` configuration.
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "meraki_network_settings" "example" {
17+
network_id = "L_123456"
18+
local_status_page_enabled = false
19+
}
20+
```
21+
22+
<!-- schema generated by tfplugindocs -->
23+
## Schema
24+
25+
### Required
26+
27+
- `network_id` (String) Network ID
28+
29+
### Optional
30+
31+
- `local_status_page_enabled` (Boolean) asdasdas
32+
33+
### Read-Only
34+
35+
- `id` (String) The id of the object
36+
37+
## Import
38+
39+
Import is supported using the following syntax:
40+
41+
```shell
42+
terraform import meraki_network_settings.example "<network_id>,<id>"
43+
```

docs/resources/organization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This resource can manage the `Organization` configuration.
1414

1515
```terraform
1616
resource "meraki_organization" "example" {
17-
name = "My organization"
17+
name = "Dev"
1818
management_details = [
1919
{
2020
name = "MSP ID"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
data "meraki_network_settings" "example" {
2+
id = "12345678"
3+
network_id = "L_123456"
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform import meraki_network_settings.example "<network_id>,<id>"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
resource "meraki_network_settings" "example" {
2+
network_id = "L_123456"
3+
local_status_page_enabled = false
4+
}

examples/resources/meraki_organization/resource.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "meraki_organization" "example" {
2-
name = "My organization"
2+
name = "Dev"
33
management_details = [
44
{
55
name = "MSP ID"

gen/definitions/admin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ attributes:
6161
example: west
6262
test_prerequisites: |
6363
data "meraki_organization" "test" {
64-
name = "TF Test"
64+
name = "Dev"
6565
}
6666
resource "meraki_network" "test" {
6767
organization_id = data.meraki_organization.test.id

gen/definitions/network.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ attributes:
3636
example: tag1
3737
test_prerequisites: |
3838
data "meraki_organization" "test" {
39-
name = "TF Test"
39+
name = "Dev"
4040
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: Network Settings
3+
rest_endpoint: /networks/%v/settings
4+
no_delete: true
5+
put_create: true
6+
doc_category: Networks
7+
get_from_all: true
8+
attributes:
9+
- tf_name: network_id
10+
type: String
11+
reference: true
12+
description: Network ID
13+
example: L_123456
14+
test_value: meraki_network.test.id
15+
- model_name: localStatusPageEnabled
16+
type: Bool
17+
description: asdasdas
18+
example: false
19+
test_prerequisites: |
20+
data "meraki_organization" "test" {
21+
name = "Dev"
22+
}
23+
resource "meraki_network" "test" {
24+
organization_id = data.meraki_organization.test.id
25+
name = "Network1"
26+
product_types = ["switch"]
27+
}

gen/definitions/organization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ attributes:
88
type: String
99
mandatory: true
1010
description: The name of the organization
11-
example: My organization
11+
example: Dev
1212
- model_name: details
1313
data_path: [management]
1414
description: Details related to organization management, possibly empty

gen/templates/data_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ func (d *{{camelCase .Name}}DataSource) Read(ctx context.Context, req datasource
181181

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

184-
{{- if .DataSourceNameQuery}}
185184
var res gjson.Result
186185
var err error
186+
{{- if .DataSourceNameQuery}}
187187
if config.Id.IsNull() && !config.Name.IsNull() {
188188
res, err = d.client.Get(config.getPath())
189189
if err != nil {

internal/provider/data_source_meraki_admin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ func (d *AdminDataSource) Read(ctx context.Context, req datasource.ReadRequest,
149149
}
150150

151151
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String()))
152+
152153
var res gjson.Result
153154
var err error
154155
if config.Id.IsNull() && !config.Name.IsNull() {

internal/provider/data_source_meraki_admin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestAccDataSourceMerakiAdmin(t *testing.T) {
5858

5959
const testAccDataSourceMerakiAdminPrerequisitesConfig = `
6060
data "meraki_organization" "test" {
61-
name = "TF Test"
61+
name = "Dev"
6262
}
6363
resource "meraki_network" "test" {
6464
organization_id = data.meraki_organization.test.id

internal/provider/data_source_meraki_network.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func (d *NetworkDataSource) Read(ctx context.Context, req datasource.ReadRequest
128128
}
129129

130130
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String()))
131+
131132
var res gjson.Result
132133
var err error
133134
if config.Id.IsNull() && !config.Name.IsNull() {
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Copyright © 2024 Cisco Systems, Inc. and its affiliates.
2+
// All rights reserved.
3+
//
4+
// Licensed under the Mozilla Public License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// https://mozilla.org/MPL/2.0/
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
// SPDX-License-Identifier: MPL-2.0
17+
18+
package provider
19+
20+
// Section below is generated&owned by "gen/generator.go". //template:begin imports
21+
import (
22+
"context"
23+
"fmt"
24+
25+
"github.com/hashicorp/terraform-plugin-framework/datasource"
26+
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
27+
"github.com/hashicorp/terraform-plugin-log/tflog"
28+
"github.com/netascode/go-meraki"
29+
"github.com/tidwall/gjson"
30+
)
31+
32+
// End of section. //template:end imports
33+
34+
// Section below is generated&owned by "gen/generator.go". //template:begin model
35+
36+
// Ensure the implementation satisfies the expected interfaces.
37+
var (
38+
_ datasource.DataSource = &NetworkSettingsDataSource{}
39+
_ datasource.DataSourceWithConfigure = &NetworkSettingsDataSource{}
40+
)
41+
42+
func NewNetworkSettingsDataSource() datasource.DataSource {
43+
return &NetworkSettingsDataSource{}
44+
}
45+
46+
type NetworkSettingsDataSource struct {
47+
client *meraki.Client
48+
}
49+
50+
func (d *NetworkSettingsDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
51+
resp.TypeName = req.ProviderTypeName + "_network_settings"
52+
}
53+
54+
func (d *NetworkSettingsDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
55+
resp.Schema = schema.Schema{
56+
// This description is used by the documentation generator and the language server.
57+
MarkdownDescription: "This data source can read the `Network Settings` configuration.",
58+
59+
Attributes: map[string]schema.Attribute{
60+
"id": schema.StringAttribute{
61+
MarkdownDescription: "The id of the object",
62+
Required: true,
63+
},
64+
"network_id": schema.StringAttribute{
65+
MarkdownDescription: "Network ID",
66+
Required: true,
67+
},
68+
"local_status_page_enabled": schema.BoolAttribute{
69+
MarkdownDescription: "asdasdas",
70+
Computed: true,
71+
},
72+
},
73+
}
74+
}
75+
76+
func (d *NetworkSettingsDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) {
77+
if req.ProviderData == nil {
78+
return
79+
}
80+
81+
d.client = req.ProviderData.(*MerakiProviderData).Client
82+
}
83+
84+
// End of section. //template:end model
85+
86+
// Section below is generated&owned by "gen/generator.go". //template:begin read
87+
88+
func (d *NetworkSettingsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
89+
var config NetworkSettings
90+
91+
// Read config
92+
diags := req.Config.Get(ctx, &config)
93+
resp.Diagnostics.Append(diags...)
94+
if resp.Diagnostics.HasError() {
95+
return
96+
}
97+
98+
tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String()))
99+
100+
var res gjson.Result
101+
var err error
102+
103+
if !res.Exists() {
104+
res, err = d.client.Get(config.getPath())
105+
if err != nil {
106+
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err))
107+
return
108+
}
109+
}
110+
if len(res.Array()) > 0 {
111+
res.ForEach(func(k, v gjson.Result) bool {
112+
if config.Id.ValueString() == v.Get("id").String() {
113+
res = v
114+
return false
115+
}
116+
return true
117+
})
118+
}
119+
120+
config.fromBody(ctx, res)
121+
122+
tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.Id.ValueString()))
123+
124+
diags = resp.State.Set(ctx, &config)
125+
resp.Diagnostics.Append(diags...)
126+
}
127+
128+
// End of section. //template:end read

0 commit comments

Comments
 (0)