diff --git a/CHANGELOG.md b/CHANGELOG.md index 9879bbbc..20109a51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ - Add `sdwan_policy_object_unified_intrusion_prevention` resource and data source - Add `sdwan_policy_object_unified_advanced_inspection_profile` resource and data source - Add `sdwan_policy_object_unified_tls_ssl_decryption` resource and data source +- Add `sdwan_policy_object_security_protocol_list` resource and data source ## 0.4.1 diff --git a/docs/data-sources/policy_object_security_protocol_list.md b/docs/data-sources/policy_object_security_protocol_list.md new file mode 100644 index 00000000..93a054d3 --- /dev/null +++ b/docs/data-sources/policy_object_security_protocol_list.md @@ -0,0 +1,42 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_protocol_list Data Source - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This data source can read the Policy Object Security Protocol List Policy_object. +--- + +# sdwan_policy_object_security_protocol_list (Data Source) + +This data source can read the Policy Object Security Protocol List Policy_object. + +## Example Usage + +```terraform +data "sdwan_policy_object_security_protocol_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Policy_object + +### Read-Only + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) (see [below for nested schema](#nestedatt--entries)) +- `name` (String) The name of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Read-Only: + +- `protocol_names` (String) diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index 452efa62..9de35d85 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -40,6 +40,7 @@ description: |- - Add `sdwan_policy_object_unified_intrusion_prevention` resource and data source - Add `sdwan_policy_object_unified_advanced_inspection_profile` resource and data source - Add `sdwan_policy_object_unified_tls_ssl_decryption` resource and data source +- Add `sdwan_policy_object_security_protocol_list` resource and data source ## 0.4.1 diff --git a/docs/resources/policy_object_security_protocol_list.md b/docs/resources/policy_object_security_protocol_list.md new file mode 100644 index 00000000..83f3c7c5 --- /dev/null +++ b/docs/resources/policy_object_security_protocol_list.md @@ -0,0 +1,61 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_protocol_list Resource - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This resource can manage a Policy Object Security Protocol List Policy_object. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_policy_object_security_protocol_list (Resource) + +This resource can manage a Policy Object Security Protocol List Policy_object. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_policy_object_security_protocol_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + protocol_names = "aol" + } + ] +} +``` + + +## Schema + +### Required + +- `entries` (Attributes List) (see [below for nested schema](#nestedatt--entries)) +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Policy_object + +### Optional + +- `description` (String) The description of the Policy_object + +### Read-Only + +- `id` (String) The id of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Optional: + +- `protocol_names` (String) - Choices: `snmp`, `icmp`, `tcp`, `udp`, `echo`, `telnet`, `wins`, `n2h2server`, `nntp`, `pptp`, `rtsp`, `bootpc`, `gdoi`, `tacacs`, `gopher`, `icabrowser`, `skinny`, `sunrpc`, `biff`, `router`, `ircs`, `orasrv`, `ms-cluster-net`, `kermit`, `isakmp`, `sshell`, `realsecure`, `ircu`, `appleqtc`, `pwdgen`, `rdb-dbs-disp`, `creativepartnr`, `finger`, `ftps`, `giop`, `rsvd`, `hp-alarm-mgr`, `uucp`, `kerberos`, `imap`, `time`, `bootps`, `tftp`, `oracle`, `snmptrap`, `http`, `qmtp`, `radius`, `oracle-em-vp`, `tarantella`, `pcanywheredata`, `ldap`, `mgcp`, `sqlsrv`, `hsrp`, `cisco-net-mgmt`, `smtp`, `pcanywherestat`, `exec`, `send`, `stun`, `syslog`, `ms-sql-m`, `citrix`, `creativeserver`, `cifs`, `cisco-sys`, `cisco-tna`, `ms-dotnetster`, `gtpv1`, `gtpv0`, `imap3`, `fcip-port`, `netbios-dgm`, `sip-tls`, `pop3s`, `cisco-fna`, `802-11-iapp`, `oem-agent`, `cisco-tdp`, `tr-rsrb`, `r-winsock`, `sql-net`, `syslog-conn`, `tacacs-ds`, `h225ras`, `ace-svr`, `dhcp-failover`, `igmpv3lite`, `irc-serv`, `entrust-svcs`, `dbcontrol_agent`, `cisco-svcs`, `ipsec-msft`, `microsoft-ds`, `ms-sna`, `rsvp_tunnel`, `rsvp-encap`, `hp-collector`, `netbios-ns`, `msexch-routing`, `h323`, `l2tp`, `ldap-admin`, `pop3`, `h323callsigalt`, `ms-sql`, `iscsi-target`, `webster`, `lotusnote`, `ipx`, `entrust-svc-hand`, `citriximaclient`, `rtc-pm-port`, `ftp`, `aol`, `xdmcp`, `oraclenames`, `login`, `iscsi`, `ttc`, `imaps`, `socks`, `ssh`, `dnsix`, `daytime`, `sip`, `discard`, `ntp`, `ldaps`, `https`, `vdolive`, `ica`, `net8-cman`, `cuseeme`, `netstat`, `sms`, `streamworks`, `rtelnet`, `who`, `kazaa`, `ssp`, `dbase`, `timed`, `cddbp`, `telnets`, `ymsgr`, `ident`, `bgp`, `ddns-v3`, `vqp`, `irc`, `ipass`, `x11`, `dns`, `lotusmtap`, `mysql`, `nfs`, `msnmsgr`, `netshow`, `sqlserv`, `hp-managed-node`, `ncp`, `shell`, `realmedia`, `msrpc`, `clp` + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_policy_object_security_protocol_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/examples/data-sources/sdwan_policy_object_security_protocol_list/data-source.tf b/examples/data-sources/sdwan_policy_object_security_protocol_list/data-source.tf new file mode 100644 index 00000000..8982518c --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_security_protocol_list/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_security_protocol_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/resources/sdwan_policy_object_security_protocol_list/import.sh b/examples/resources/sdwan_policy_object_security_protocol_list/import.sh new file mode 100644 index 00000000..a3722f52 --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_protocol_list/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_security_protocol_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_security_protocol_list/resource.tf b/examples/resources/sdwan_policy_object_security_protocol_list/resource.tf new file mode 100644 index 00000000..d19b8042 --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_protocol_list/resource.tf @@ -0,0 +1,10 @@ +resource "sdwan_policy_object_security_protocol_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + protocol_names = "aol" + } + ] +} diff --git a/gen/definitions/profile_parcels/policy_object_security_protocol_list.yaml b/gen/definitions/profile_parcels/policy_object_security_protocol_list.yaml new file mode 100644 index 00000000..023636c4 --- /dev/null +++ b/gen/definitions/profile_parcels/policy_object_security_protocol_list.yaml @@ -0,0 +1,29 @@ +--- +name: Policy Object Security Protocol List +rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/security-protocolname +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +skip_minimum_test: true +parcel_type: policy_object +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_policy_object_feature_profile.test.id + - model_name: entries + mandatory: true + attributes: + - model_name: protocolName + tf_name: protocol_names + id: true + mandatory: true + example: aol + +test_prerequisites: | + resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" + } \ No newline at end of file diff --git a/gen/models/profile_parcels/policy_object_security_protocolname.json b/gen/models/profile_parcels/policy_object_security_protocol_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_security_protocolname.json rename to gen/models/profile_parcels/policy_object_security_protocol_list.json diff --git a/internal/provider/data_source_sdwan_policy_object_security_protocol_list.go b/internal/provider/data_source_sdwan_policy_object_security_protocol_list.go new file mode 100644 index 00000000..9c9cf9a8 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_protocol_list.go @@ -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 = &PolicyObjectSecurityProtocolListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectSecurityProtocolListProfileParcelDataSource{} +) + +func NewPolicyObjectSecurityProtocolListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectSecurityProtocolListProfileParcelDataSource{} +} + +type PolicyObjectSecurityProtocolListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectSecurityProtocolListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_protocol_list" +} + +func (d *PolicyObjectSecurityProtocolListProfileParcelDataSource) 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 Protocol List Policy_object.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "protocol_names": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectSecurityProtocolListProfileParcelDataSource) 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 *PolicyObjectSecurityProtocolListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectSecurityProtocolList + + // 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 diff --git a/internal/provider/data_source_sdwan_policy_object_security_protocol_list_test.go b/internal/provider/data_source_sdwan_policy_object_security_protocol_list_test.go new file mode 100644 index 00000000..63318c0a --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_protocol_list_test.go @@ -0,0 +1,81 @@ +// 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 TestAccDataSourceSdwanPolicyObjectSecurityProtocolListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_security_protocol_list.test", "entries.0.protocol_names", "aol")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectSecurityProtocolListPrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectSecurityProtocolListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanPolicyObjectSecurityProtocolListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectSecurityProtocolListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_security_protocol_list" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` protocol_names = "aol"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_security_protocol_list" "test" { + id = sdwan_policy_object_security_protocol_list.test.id + feature_profile_id = sdwan_policy_object_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/model_sdwan_policy_object_security_protocol_list.go b/internal/provider/model_sdwan_policy_object_security_protocol_list.go new file mode 100644 index 00000000..faa1fb3c --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_security_protocol_list.go @@ -0,0 +1,178 @@ +// 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/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 PolicyObjectSecurityProtocolList struct { + Id types.String `tfsdk:"id"` + Version types.Int64 `tfsdk:"version"` + Name types.String `tfsdk:"name"` + Description types.String `tfsdk:"description"` + FeatureProfileId types.String `tfsdk:"feature_profile_id"` + Entries []PolicyObjectSecurityProtocolListEntries `tfsdk:"entries"` +} + +type PolicyObjectSecurityProtocolListEntries struct { + ProtocolNames types.String `tfsdk:"protocol_names"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectSecurityProtocolList) getModel() string { + return "policy_object_security_protocol_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectSecurityProtocolList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/security-protocolname", url.QueryEscape(data.FeatureProfileId.ValueString())) +} + +// End of section. //template:end getPath + +// Section below is generated&owned by "gen/generator.go". //template:begin toBody +func (data PolicyObjectSecurityProtocolList) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + + for _, item := range data.Entries { + itemBody := "" + if !item.ProtocolNames.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "protocolName.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "protocolName.value", item.ProtocolNames.ValueString()) + } + } + body, _ = sjson.SetRaw(body, path+"entries.-1", itemBody) + } + } + return body +} + +// End of section. //template:end toBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBody +func (data *PolicyObjectSecurityProtocolList) fromBody(ctx context.Context, res gjson.Result) { + data.Name = types.StringValue(res.Get("payload.name").String()) + if value := res.Get("payload.description"); value.Exists() && value.String() != "" { + data.Description = types.StringValue(value.String()) + } else { + data.Description = types.StringNull() + } + path := "payload.data." + if value := res.Get(path + "entries"); value.Exists() { + data.Entries = make([]PolicyObjectSecurityProtocolListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectSecurityProtocolListEntries{} + item.ProtocolNames = types.StringNull() + + if t := v.Get("protocolName.optionType"); t.Exists() { + va := v.Get("protocolName.value") + if t.String() == "global" { + item.ProtocolNames = types.StringValue(va.String()) + } + } + data.Entries = append(data.Entries, item) + return true + }) + } +} + +// End of section. //template:end fromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody +func (data *PolicyObjectSecurityProtocolList) updateFromBody(ctx context.Context, res gjson.Result) { + data.Name = types.StringValue(res.Get("payload.name").String()) + if value := res.Get("payload.description"); value.Exists() && value.String() != "" { + data.Description = types.StringValue(value.String()) + } else { + data.Description = types.StringNull() + } + path := "payload.data." + for i := range data.Entries { + keys := [...]string{"protocolName"} + keyValues := [...]string{data.Entries[i].ProtocolNames.ValueString()} + keyValuesVariables := [...]string{""} + + var r gjson.Result + res.Get(path + "entries").ForEach( + func(_, v gjson.Result) bool { + found := false + for ik := range keys { + tt := v.Get(keys[ik] + ".optionType") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + r = v + return false + } + return true + }, + ) + data.Entries[i].ProtocolNames = types.StringNull() + + if t := r.Get("protocolName.optionType"); t.Exists() { + va := r.Get("protocolName.value") + if t.String() == "global" { + data.Entries[i].ProtocolNames = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectSecurityProtocolList) isNull(ctx context.Context, res gjson.Result) bool { + if !data.FeatureProfileId.IsNull() { + return false + } + if len(data.Entries) > 0 { + return false + } + return true +} + +// End of section. //template:end isNull diff --git a/internal/provider/provider.go b/internal/provider/provider.go index a7d11d59..0befe8e0 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -307,6 +307,7 @@ func (p *SdwanProvider) Resources(ctx context.Context) []func() resource.Resourc NewPolicyObjectSecurityLocalApplicationListProfileParcelResource, NewPolicyObjectSecurityLocalDomainListProfileParcelResource, NewPolicyObjectSecurityPortListProfileParcelResource, + NewPolicyObjectSecurityProtocolListProfileParcelResource, NewPolicyObjectSecurityScalableGroupTagListProfileParcelResource, NewPolicyObjectSecurityURLAllowListProfileParcelResource, NewPolicyObjectSecurityURLBlockListProfileParcelResource, @@ -517,6 +518,7 @@ func (p *SdwanProvider) DataSources(ctx context.Context) []func() datasource.Dat NewPolicyObjectSecurityLocalApplicationListProfileParcelDataSource, NewPolicyObjectSecurityLocalDomainListProfileParcelDataSource, NewPolicyObjectSecurityPortListProfileParcelDataSource, + NewPolicyObjectSecurityProtocolListProfileParcelDataSource, NewPolicyObjectSecurityScalableGroupTagListProfileParcelDataSource, NewPolicyObjectSecurityURLAllowListProfileParcelDataSource, NewPolicyObjectSecurityURLBlockListProfileParcelDataSource, diff --git a/internal/provider/resource_sdwan_policy_object_security_protocol_list.go b/internal/provider/resource_sdwan_policy_object_security_protocol_list.go new file mode 100644 index 00000000..a1c13e47 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_protocol_list.go @@ -0,0 +1,257 @@ +// 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" + "sync" + + "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "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/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "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 provider defined types fully satisfy framework interfaces +var _ resource.Resource = &PolicyObjectSecurityProtocolListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectSecurityProtocolListProfileParcelResource{} + +func NewPolicyObjectSecurityProtocolListProfileParcelResource() resource.Resource { + return &PolicyObjectSecurityProtocolListProfileParcelResource{} +} + +type PolicyObjectSecurityProtocolListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectSecurityProtocolListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_protocol_list" +} + +func (r *PolicyObjectSecurityProtocolListProfileParcelResource) 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 a Policy Object Security Protocol List Policy_object.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "protocol_names": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").AddStringEnumDescription("snmp", "icmp", "tcp", "udp", "echo", "telnet", "wins", "n2h2server", "nntp", "pptp", "rtsp", "bootpc", "gdoi", "tacacs", "gopher", "icabrowser", "skinny", "sunrpc", "biff", "router", "ircs", "orasrv", "ms-cluster-net", "kermit", "isakmp", "sshell", "realsecure", "ircu", "appleqtc", "pwdgen", "rdb-dbs-disp", "creativepartnr", "finger", "ftps", "giop", "rsvd", "hp-alarm-mgr", "uucp", "kerberos", "imap", "time", "bootps", "tftp", "oracle", "snmptrap", "http", "qmtp", "radius", "oracle-em-vp", "tarantella", "pcanywheredata", "ldap", "mgcp", "sqlsrv", "hsrp", "cisco-net-mgmt", "smtp", "pcanywherestat", "exec", "send", "stun", "syslog", "ms-sql-m", "citrix", "creativeserver", "cifs", "cisco-sys", "cisco-tna", "ms-dotnetster", "gtpv1", "gtpv0", "imap3", "fcip-port", "netbios-dgm", "sip-tls", "pop3s", "cisco-fna", "802-11-iapp", "oem-agent", "cisco-tdp", "tr-rsrb", "r-winsock", "sql-net", "syslog-conn", "tacacs-ds", "h225ras", "ace-svr", "dhcp-failover", "igmpv3lite", "irc-serv", "entrust-svcs", "dbcontrol_agent", "cisco-svcs", "ipsec-msft", "microsoft-ds", "ms-sna", "rsvp_tunnel", "rsvp-encap", "hp-collector", "netbios-ns", "msexch-routing", "h323", "l2tp", "ldap-admin", "pop3", "h323callsigalt", "ms-sql", "iscsi-target", "webster", "lotusnote", "ipx", "entrust-svc-hand", "citriximaclient", "rtc-pm-port", "ftp", "aol", "xdmcp", "oraclenames", "login", "iscsi", "ttc", "imaps", "socks", "ssh", "dnsix", "daytime", "sip", "discard", "ntp", "ldaps", "https", "vdolive", "ica", "net8-cman", "cuseeme", "netstat", "sms", "streamworks", "rtelnet", "who", "kazaa", "ssp", "dbase", "timed", "cddbp", "telnets", "ymsgr", "ident", "bgp", "ddns-v3", "vqp", "irc", "ipass", "x11", "dns", "lotusmtap", "mysql", "nfs", "msnmsgr", "netshow", "sqlserv", "hp-managed-node", "ncp", "shell", "realmedia", "msrpc", "clp").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOf("snmp", "icmp", "tcp", "udp", "echo", "telnet", "wins", "n2h2server", "nntp", "pptp", "rtsp", "bootpc", "gdoi", "tacacs", "gopher", "icabrowser", "skinny", "sunrpc", "biff", "router", "ircs", "orasrv", "ms-cluster-net", "kermit", "isakmp", "sshell", "realsecure", "ircu", "appleqtc", "pwdgen", "rdb-dbs-disp", "creativepartnr", "finger", "ftps", "giop", "rsvd", "hp-alarm-mgr", "uucp", "kerberos", "imap", "time", "bootps", "tftp", "oracle", "snmptrap", "http", "qmtp", "radius", "oracle-em-vp", "tarantella", "pcanywheredata", "ldap", "mgcp", "sqlsrv", "hsrp", "cisco-net-mgmt", "smtp", "pcanywherestat", "exec", "send", "stun", "syslog", "ms-sql-m", "citrix", "creativeserver", "cifs", "cisco-sys", "cisco-tna", "ms-dotnetster", "gtpv1", "gtpv0", "imap3", "fcip-port", "netbios-dgm", "sip-tls", "pop3s", "cisco-fna", "802-11-iapp", "oem-agent", "cisco-tdp", "tr-rsrb", "r-winsock", "sql-net", "syslog-conn", "tacacs-ds", "h225ras", "ace-svr", "dhcp-failover", "igmpv3lite", "irc-serv", "entrust-svcs", "dbcontrol_agent", "cisco-svcs", "ipsec-msft", "microsoft-ds", "ms-sna", "rsvp_tunnel", "rsvp-encap", "hp-collector", "netbios-ns", "msexch-routing", "h323", "l2tp", "ldap-admin", "pop3", "h323callsigalt", "ms-sql", "iscsi-target", "webster", "lotusnote", "ipx", "entrust-svc-hand", "citriximaclient", "rtc-pm-port", "ftp", "aol", "xdmcp", "oraclenames", "login", "iscsi", "ttc", "imaps", "socks", "ssh", "dnsix", "daytime", "sip", "discard", "ntp", "ldaps", "https", "vdolive", "ica", "net8-cman", "cuseeme", "netstat", "sms", "streamworks", "rtelnet", "who", "kazaa", "ssp", "dbase", "timed", "cddbp", "telnets", "ymsgr", "ident", "bgp", "ddns-v3", "vqp", "irc", "ipass", "x11", "dns", "lotusmtap", "mysql", "nfs", "msnmsgr", "netshow", "sqlserv", "hp-managed-node", "ncp", "shell", "realmedia", "msrpc", "clp"), + }, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectSecurityProtocolListProfileParcelResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + + r.client = req.ProviderData.(*SdwanProviderData).Client + r.updateMutex = req.ProviderData.(*SdwanProviderData).UpdateMutex +} + +// End of section. //template:end model + +// Section below is generated&owned by "gen/generator.go". //template:begin create +func (r *PolicyObjectSecurityProtocolListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectSecurityProtocolList + + // Read plan + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Name.ValueString())) + + // Create object + body := plan.toBody(ctx) + + res, err := r.client.Post(plan.getPath(), body) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (POST), got error: %s, %s", err, res.String())) + return + } + + plan.Id = types.StringValue(res.Get("parcelId").String()) + plan.Version = types.Int64Value(0) + + tflog.Debug(ctx, fmt.Sprintf("%s: Create finished successfully", plan.Name.ValueString())) + + diags = resp.State.Set(ctx, &plan) + resp.Diagnostics.Append(diags...) +} + +// End of section. //template:end create + +// Section below is generated&owned by "gen/generator.go". //template:begin read +func (r *PolicyObjectSecurityProtocolListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectSecurityProtocolList + + // Read state + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Name.String())) + + res, err := r.client.Get(state.getPath() + "/" + url.QueryEscape(state.Id.ValueString())) + if res.Get("error.message").String() == "Invalid feature Id" { + 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 + } + + // If every attribute is set to null we are dealing with an import operation and therefore reading all attributes + if state.isNull(ctx, res) { + state.fromBody(ctx, res) + } else { + state.updateFromBody(ctx, res) + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", state.Name.ValueString())) + + diags = resp.State.Set(ctx, &state) + resp.Diagnostics.Append(diags...) +} + +// End of section. //template:end read + +// Section below is generated&owned by "gen/generator.go". //template:begin update +func (r *PolicyObjectSecurityProtocolListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectSecurityProtocolList + + // Read plan + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + // Read state + diags = req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Name.ValueString())) + + body := plan.toBody(ctx) + 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 + } + + plan.Version = types.Int64Value(state.Version.ValueInt64() + 1) + + tflog.Debug(ctx, fmt.Sprintf("%s: Update finished successfully", plan.Name.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 *PolicyObjectSecurityProtocolListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectSecurityProtocolList + + // Read state + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Name.ValueString())) + + res, err := r.client.Delete(state.getPath() + "/" + url.QueryEscape(state.Id.ValueString())) + if err != nil && res.Get("error.message").String() != "Invalid Template Id" { + 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.Name.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 *PolicyObjectSecurityProtocolListProfileParcelResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} + +// End of section. //template:end import diff --git a/internal/provider/resource_sdwan_policy_object_security_protocol_list_test.go b/internal/provider/resource_sdwan_policy_object_security_protocol_list_test.go new file mode 100644 index 00000000..70a2e6f1 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_protocol_list_test.go @@ -0,0 +1,79 @@ +// 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 testAcc +func TestAccSdwanPolicyObjectSecurityProtocolListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_security_protocol_list.test", "entries.0.protocol_names", "aol")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanPolicyObjectSecurityProtocolListPrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectSecurityProtocolListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanPolicyObjectSecurityProtocolListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectSecurityProtocolListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_security_protocol_list" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` protocol_names = "aol"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index 452efa62..9de35d85 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -40,6 +40,7 @@ description: |- - Add `sdwan_policy_object_unified_intrusion_prevention` resource and data source - Add `sdwan_policy_object_unified_advanced_inspection_profile` resource and data source - Add `sdwan_policy_object_unified_tls_ssl_decryption` resource and data source +- Add `sdwan_policy_object_security_protocol_list` resource and data source ## 0.4.1