From 8055790c3eea931064db1544ad1666af59e1f59b Mon Sep 17 00:00:00 2001 From: Volodymyr Manilo Date: Wed, 26 Jun 2024 16:35:59 +0200 Subject: [PATCH 1/3] added fix and test for invalid alias value --- .../internal/provider/resource/resource.go | 6 +-- .../test/acctests/resource/resource_test.go | 46 ++++++++++++++++++- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/twingate/internal/provider/resource/resource.go b/twingate/internal/provider/resource/resource.go index a5986633..4dc8e390 100644 --- a/twingate/internal/provider/resource/resource.go +++ b/twingate/internal/provider/resource/resource.go @@ -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) diff --git a/twingate/internal/test/acctests/resource/resource_test.go b/twingate/internal/test/acctests/resource/resource_test.go index 7b67bbe0..b81df06c 100644 --- a/twingate/internal/test/acctests/resource/resource_test.go +++ b/twingate/internal/test/acctests/resource/resource_test.go @@ -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" @@ -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" { From fc038b04d9b03322eb475c36269b1dc7772f4f58 Mon Sep 17 00:00:00 2001 From: Volodymyr Manilo Date: Wed, 26 Jun 2024 16:37:08 +0200 Subject: [PATCH 2/3] enable ci tests --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 390c3a04..22261e89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,7 @@ on: - 'README.md' branches: - main + - fix/crash-on-invalid-alias-value # Ensures only 1 action runs per PR and previous is canceled on new trigger concurrency: From 41bcd206058321a6513a56452fd64ea92cb35f46 Mon Sep 17 00:00:00 2001 From: Volodymyr Manilo Date: Wed, 26 Jun 2024 17:30:10 +0200 Subject: [PATCH 3/3] revert ci changes --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22261e89..390c3a04 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,6 @@ on: - 'README.md' branches: - main - - fix/crash-on-invalid-alias-value # Ensures only 1 action runs per PR and previous is canceled on new trigger concurrency: