Skip to content

Commit

Permalink
Fix: crash on invalid alias value (#553)
Browse files Browse the repository at this point in the history
* added fix and test for invalid alias value

* enable ci tests

* revert ci changes
  • Loading branch information
vmanilo authored Jun 26, 2024
1 parent f22780f commit 010fe67
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
6 changes: 3 additions & 3 deletions twingate/internal/provider/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,10 +827,10 @@ func (r *twingateResource) Update(ctx context.Context, req resource.UpdateReques

if resource != nil {
resource.IsAuthoritative = input.IsAuthoritative
}

if planSecurityPolicy != nil && *planSecurityPolicy == "" {
resource.SecurityPolicyID = planSecurityPolicy
if planSecurityPolicy != nil && *planSecurityPolicy == "" {
resource.SecurityPolicyID = planSecurityPolicy
}
}

r.helper(ctx, resource, &state, &plan, &resp.State, &resp.Diagnostics, err, operationUpdate)
Expand Down
46 changes: 45 additions & 1 deletion twingate/internal/test/acctests/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package resource

import (
"fmt"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"regexp"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/acctest"

"github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/attr"
"github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/model"
"github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/provider/resource"
Expand Down Expand Up @@ -2047,6 +2048,49 @@ func TestAccTwingateResourceCreateWithAlias(t *testing.T) {
})
}

func TestAccTwingateResourceUpdateWithInvalidAlias(t *testing.T) {
const terraformResourceName = "test29_update_invalid"
theResource := acctests.TerraformResource(terraformResourceName)
remoteNetworkName := test.RandomName()
resourceName := test.RandomResourceName()

sdk.Test(t, sdk.TestCase{
ProtoV6ProviderFactories: acctests.ProviderFactories,
PreCheck: func() { acctests.PreCheck(t) },
CheckDestroy: acctests.CheckTwingateResourceDestroy,
Steps: []sdk.TestStep{
{
Config: createResource29WithoutAlias(terraformResourceName, remoteNetworkName, resourceName),
Check: acctests.ComposeTestCheckFunc(
sdk.TestCheckNoResourceAttr(theResource, attr.Alias),
),
},
{
Config: createResource29(terraformResourceName, remoteNetworkName, resourceName, "test-com"),
ExpectError: regexp.MustCompile("Alias must be a[\\n\\s]+valid DNS name"),
},
},
})
}

func TestAccTwingateResourceCreateWithInvalidAlias(t *testing.T) {
const terraformResourceName = "test29_create_invalid"
remoteNetworkName := test.RandomName()
resourceName := test.RandomResourceName()

sdk.Test(t, sdk.TestCase{
ProtoV6ProviderFactories: acctests.ProviderFactories,
PreCheck: func() { acctests.PreCheck(t) },
CheckDestroy: acctests.CheckTwingateResourceDestroy,
Steps: []sdk.TestStep{
{
Config: createResource29(terraformResourceName, remoteNetworkName, resourceName, "test-com"),
ExpectError: regexp.MustCompile("Alias must be a[\\n\\s]+valid DNS name"),
},
},
})
}

func createResource29(terraformResourceName, networkName, resourceName, aliasName string) string {
return fmt.Sprintf(`
resource "twingate_remote_network" "%s" {
Expand Down

0 comments on commit 010fe67

Please sign in to comment.