Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VPN] psk documentation and validation updates in resource/vpnaas_site_connection_v2 #2011

Merged
merged 4 commits into from Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/resources/vpnaas_site_connection_v2.md
Expand Up @@ -73,7 +73,7 @@ The following arguments are supported:

* `peer_address` - (Required) The peer gateway public IPv4 or IPv6 address or FQDN.

* `psk` - (Required) The pre-shared key. A valid value is any string.
* `psk` - (Required) The pre-shared key. A PSK can contain 6 to 128 characters. Spaces and the following special characters are not allowed: `<>&?*'"`.

* `initiator` - (Optional) A valid value is `response-only` or `bi-directional`.

Expand Down
Expand Up @@ -137,7 +137,7 @@ resource "opentelekomcloud_vpnaas_site_connection_v2" "conn_1" {
ikepolicy_id = opentelekomcloud_vpnaas_ike_policy_v2.policy_2.id
ipsecpolicy_id = opentelekomcloud_vpnaas_ipsec_policy_v2.policy_1.id
vpnservice_id = opentelekomcloud_vpnaas_service_v2.service_1.id
psk = "secret"
psk = "secret./"
peer_address = "192.168.10.1"
peer_id = "192.168.10.1"
local_ep_group_id = opentelekomcloud_vpnaas_endpoint_group_v2.group_2.id
Expand Down
Expand Up @@ -4,12 +4,14 @@ import (
"context"
"fmt"
"log"
"regexp"
"time"

"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/networking/v2/extensions/vpnaas/siteconnections"
Expand All @@ -19,6 +21,12 @@ import (
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/fmterr"
)

var (
// A PSK can contain 6 to 128 characters.
// Spaces and the following special characters are not allowed: <>&?*'"
pskRegex = regexp.MustCompile("^[^ <>&?*'\"]{6,128}$")
)

func ResourceVpnSiteConnectionV2() *schema.Resource {
return &schema.Resource{
CreateContext: resourceVpnSiteConnectionV2Create,
Expand Down Expand Up @@ -93,6 +101,8 @@ func ResourceVpnSiteConnectionV2() *schema.Resource {
"psk": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringMatch(pskRegex, "Invalid pks value. "+
"A PSK can contain 6 to 128 characters. Spaces and the following special characters are not allowed: <>&?*'\"."),
},
"initiator": {
Type: schema.TypeString,
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/vpn-psk-validation-84ab02be99ccb6db.yaml
@@ -0,0 +1,4 @@
---
other:
- |
**[VPN]** Add validation and update documentation for ``psk`` in ``resource/opentelekomcloud_vpnaas_site_connection_v2`` (`#2011 <https://github.com/opentelekomcloud/terraform-provider-opentelekomcloud/pull/2011>`_)