forked from CiscoDevNet/terraform-provider-sdwan
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add policy object security port profile parcel resource and data source
- Loading branch information
Showing
15 changed files
with
861 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
42 changes: 42 additions & 0 deletions
42
docs/data-sources/policy_object_security_port_profile_parcel.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,42 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "sdwan_policy_object_security_port_profile_parcel Data Source - terraform-provider-sdwan" | ||
subcategory: "Profile Parcels" | ||
description: |- | ||
This data source can read the Policy Object Security Port profile parcel. | ||
--- | ||
|
||
# sdwan_policy_object_security_port_profile_parcel (Data Source) | ||
|
||
This data source can read the Policy Object Security Port profile parcel. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "sdwan_policy_object_security_port_profile_parcel" "example" { | ||
id = "f6b2c44c-693c-4763-b010-895aa3d236bd" | ||
feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `feature_profile_id` (String) Feature Profile ID | ||
- `id` (String) The id of the profile parcel | ||
|
||
### Read-Only | ||
|
||
- `description` (String) The description of the profile parcel | ||
- `entries` (Attributes List) Port List (see [below for nested schema](#nestedatt--entries)) | ||
- `name` (String) The name of the profile parcel | ||
- `version` (Number) The version of the profile parcel | ||
|
||
<a id="nestedatt--entries"></a> | ||
### Nested Schema for `entries` | ||
|
||
Read-Only: | ||
|
||
- `port` (String) can be single port or port range |
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
61 changes: 61 additions & 0 deletions
61
docs/resources/policy_object_security_port_profile_parcel.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,61 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "sdwan_policy_object_security_port_profile_parcel Resource - terraform-provider-sdwan" | ||
subcategory: "Profile Parcels" | ||
description: |- | ||
This resource can manage a Policy Object Security Port profile parcel. | ||
Minimum SD-WAN Manager version: 20.12.0 | ||
--- | ||
|
||
# sdwan_policy_object_security_port_profile_parcel (Resource) | ||
|
||
This resource can manage a Policy Object Security Port profile parcel. | ||
- Minimum SD-WAN Manager version: `20.12.0` | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "sdwan_policy_object_security_port_profile_parcel" "example" { | ||
name = "Example" | ||
description = "My Example" | ||
feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" | ||
entries = [ | ||
{ | ||
port = "100" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `entries` (Attributes List) Port List (see [below for nested schema](#nestedatt--entries)) | ||
- `feature_profile_id` (String) Feature Profile ID | ||
- `name` (String) The name of the profile parcel | ||
|
||
### Optional | ||
|
||
- `description` (String) The description of the profile parcel | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The id of the profile parcel | ||
- `version` (Number) The version of the profile parcel | ||
|
||
<a id="nestedatt--entries"></a> | ||
### Nested Schema for `entries` | ||
|
||
Optional: | ||
|
||
- `port` (String) can be single port or port range | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
terraform import sdwan_policy_object_security_port_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" | ||
``` |
4 changes: 4 additions & 0 deletions
4
examples/data-sources/sdwan_policy_object_security_port_profile_parcel/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,4 @@ | ||
data "sdwan_policy_object_security_port_profile_parcel" "example" { | ||
id = "f6b2c44c-693c-4763-b010-895aa3d236bd" | ||
feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" | ||
} |
1 change: 1 addition & 0 deletions
1
examples/resources/sdwan_policy_object_security_port_profile_parcel/import.sh
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 @@ | ||
terraform import sdwan_policy_object_security_port_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" |
10 changes: 10 additions & 0 deletions
10
examples/resources/sdwan_policy_object_security_port_profile_parcel/resource.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,10 @@ | ||
resource "sdwan_policy_object_security_port_profile_parcel" "example" { | ||
name = "Example" | ||
description = "My Example" | ||
feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" | ||
entries = [ | ||
{ | ||
port = "100" | ||
} | ||
] | ||
} |
24 changes: 24 additions & 0 deletions
24
gen/definitions/profile_parcels/policy_object_security_port.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,24 @@ | ||
--- | ||
name: Policy Object Security Port | ||
rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/security-port | ||
minimum_version: 20.12.0 | ||
test_tags: [SDWAN_2012, TF_VAR_policy_object_feature_template_id] | ||
skip_minimum_test: true | ||
attributes: | ||
- tf_name: feature_profile_id | ||
reference: true | ||
type: String | ||
mandatory: true | ||
description: Feature Profile ID | ||
example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac | ||
test_value: var.policy_object_feature_template_id | ||
- model_name: entries | ||
mandatory: true | ||
attributes: | ||
- model_name: port | ||
id: true | ||
mandatory: true | ||
example: 100 | ||
|
||
test_prerequisites: | | ||
variable "policy_object_feature_template_id" {} |
133 changes: 133 additions & 0 deletions
133
internal/provider/data_source_sdwan_policy_object_security_port_profile_parcel.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,133 @@ | ||
// Copyright © 2023 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-sdwan" | ||
) | ||
|
||
// 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 = &PolicyObjectSecurityPortProfileParcelDataSource{} | ||
_ datasource.DataSourceWithConfigure = &PolicyObjectSecurityPortProfileParcelDataSource{} | ||
) | ||
|
||
func NewPolicyObjectSecurityPortProfileParcelDataSource() datasource.DataSource { | ||
return &PolicyObjectSecurityPortProfileParcelDataSource{} | ||
} | ||
|
||
type PolicyObjectSecurityPortProfileParcelDataSource struct { | ||
client *sdwan.Client | ||
} | ||
|
||
func (d *PolicyObjectSecurityPortProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_policy_object_security_port_profile_parcel" | ||
} | ||
|
||
func (d *PolicyObjectSecurityPortProfileParcelDataSource) 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 Policy Object Security Port profile parcel.", | ||
|
||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
MarkdownDescription: "The id of the profile parcel", | ||
Required: true, | ||
}, | ||
"version": schema.Int64Attribute{ | ||
MarkdownDescription: "The version of the profile parcel", | ||
Computed: true, | ||
}, | ||
"name": schema.StringAttribute{ | ||
MarkdownDescription: "The name of the profile parcel", | ||
Computed: true, | ||
}, | ||
"description": schema.StringAttribute{ | ||
MarkdownDescription: "The description of the profile parcel", | ||
Computed: true, | ||
}, | ||
"feature_profile_id": schema.StringAttribute{ | ||
MarkdownDescription: "Feature Profile ID", | ||
Required: true, | ||
}, | ||
"entries": schema.ListNestedAttribute{ | ||
MarkdownDescription: "Port List", | ||
Computed: true, | ||
NestedObject: schema.NestedAttributeObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"port": schema.StringAttribute{ | ||
MarkdownDescription: "can be single port or port range", | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *PolicyObjectSecurityPortProfileParcelDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) { | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
d.client = req.ProviderData.(*SdwanProviderData).Client | ||
} | ||
|
||
// End of section. //template:end model | ||
|
||
// Section below is generated&owned by "gen/generator.go". //template:begin read | ||
func (d *PolicyObjectSecurityPortProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var config PolicyObjectSecurityPort | ||
|
||
// 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())) | ||
|
||
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.Name.ValueString())) | ||
|
||
diags = resp.State.Set(ctx, &config) | ||
resp.Diagnostics.Append(diags...) | ||
} | ||
|
||
// End of section. //template:end read |
78 changes: 78 additions & 0 deletions
78
internal/provider/data_source_sdwan_policy_object_security_port_profile_parcel_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,78 @@ | ||
// Copyright © 2023 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 TestAccDataSourceSdwanPolicyObjectSecurityPortProfileParcel(t *testing.T) { | ||
if os.Getenv("SDWAN_2012") == "" && os.Getenv("TF_VAR_policy_object_feature_template_id") == "" { | ||
t.Skip("skipping test, set environment variable SDWAN_2012 or TF_VAR_policy_object_feature_template_id") | ||
} | ||
var checks []resource.TestCheckFunc | ||
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_security_port_profile_parcel.test", "entries.0.port", "100")) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceSdwanPolicyObjectSecurityPortPrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectSecurityPortProfileParcelConfig(), | ||
Check: resource.ComposeTestCheckFunc(checks...), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
// End of section. //template:end testAccDataSource | ||
|
||
// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites | ||
const testAccDataSourceSdwanPolicyObjectSecurityPortPrerequisitesProfileParcelConfig = ` | ||
variable "policy_object_feature_template_id" {} | ||
` | ||
|
||
// End of section. //template:end testPrerequisites | ||
|
||
// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig | ||
func testAccDataSourceSdwanPolicyObjectSecurityPortProfileParcelConfig() string { | ||
config := `resource "sdwan_policy_object_security_port_profile_parcel" "test" {` + "\n" | ||
config += ` name = "TF_TEST"` + "\n" | ||
config += ` description = "Terraform integration test"` + "\n" | ||
config += ` feature_profile_id = var.policy_object_feature_template_id` + "\n" | ||
config += ` entries = [{` + "\n" | ||
config += ` port = "100"` + "\n" | ||
config += ` }]` + "\n" | ||
config += `}` + "\n" | ||
|
||
config += ` | ||
data "sdwan_policy_object_security_port_profile_parcel" "test" { | ||
id = sdwan_policy_object_security_port_profile_parcel.test.id | ||
feature_profile_id = var.policy_object_feature_template_id | ||
} | ||
` | ||
return config | ||
} | ||
|
||
// End of section. //template:end testAccDataSourceConfig |
Oops, something went wrong.