From 5bf80fa1138b9a69733b87f4ce060c69f386f64d Mon Sep 17 00:00:00 2001 From: Volodymyr Manilo Date: Sat, 2 Dec 2023 07:40:01 +0100 Subject: [PATCH] fix test --- docs/resources/resource.md | 10 ++++++++-- examples/resources/twingate_resource/resource.tf | 6 ++++++ twingate/internal/provider/resource/resource.go | 11 +++++------ .../test/acctests/resource/resource_test.go | 16 ++++------------ 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/docs/resources/resource.md b/docs/resources/resource.md index 38a28653..d4341bb8 100644 --- a/docs/resources/resource.md +++ b/docs/resources/resource.md @@ -30,11 +30,17 @@ resource "twingate_service_account" "github_actions_prod" { name = "Github Actions PROD" } +data "twingate_security_policy" "test_policy" { + name = "Test Policy" +} + resource "twingate_resource" "resource" { name = "network" address = "internal.int" remote_network_id = twingate_remote_network.aws_network.id + security_policy_id = data.twingate_security_policy.test_policy.id + protocols = { allow_icmp = true tcp = { @@ -67,8 +73,8 @@ resource "twingate_resource" "resource" { - `access` (Block List) Restrict access to certain groups or service accounts (see [below for nested schema](#nestedblock--access)) - `alias` (String) Set a DNS alias address for the Resource. Must be a DNS-valid name string. - `is_authoritative` (Boolean) Determines whether assignments in the access block will override any existing assignments. Default is `true`. If set to `false`, assignments made outside of Terraform will be ignored. -- `is_browser_shortcut_enabled` (Boolean) Controls whether an "Open in Browser" shortcut will be shown for this Resource in the Twingate Client. -- `is_visible` (Boolean) Controls whether this Resource will be visible in the main Resource list in the Twingate Client. +- `is_browser_shortcut_enabled` (Boolean) Controls whether an "Open in Browser" shortcut will be shown for this Resource in the Twingate Client. Default is false. +- `is_visible` (Boolean) Controls whether this Resource will be visible in the main Resource list in the Twingate Client. Default is true. - `protocols` (Attributes) Restrict access to certain protocols and ports. By default or when this argument is not defined, there is no restriction, and all protocols and ports are allowed. (see [below for nested schema](#nestedatt--protocols)) - `security_policy_id` (String) The ID of a `twingate_security_policy` to set as this Resource's Security Policy. Default is `Default Policy`. diff --git a/examples/resources/twingate_resource/resource.tf b/examples/resources/twingate_resource/resource.tf index 925b8a57..e4421d20 100644 --- a/examples/resources/twingate_resource/resource.tf +++ b/examples/resources/twingate_resource/resource.tf @@ -15,11 +15,17 @@ resource "twingate_service_account" "github_actions_prod" { name = "Github Actions PROD" } +data "twingate_security_policy" "test_policy" { + name = "Test Policy" +} + resource "twingate_resource" "resource" { name = "network" address = "internal.int" remote_network_id = twingate_remote_network.aws_network.id + security_policy_id = data.twingate_security_policy.test_policy.id + protocols = { allow_icmp = true tcp = { diff --git a/twingate/internal/provider/resource/resource.go b/twingate/internal/provider/resource/resource.go index 40eefb09..39e3df1c 100644 --- a/twingate/internal/provider/resource/resource.go +++ b/twingate/internal/provider/resource/resource.go @@ -162,24 +162,23 @@ func (r *twingateResource) Schema(_ context.Context, _ resource.SchemaRequest, r attr.Protocols: protocols(), // computed attr.SecurityPolicyID: schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "The ID of a `twingate_security_policy` to set as this Resource's Security Policy. Default is `Default Policy`.", - //Default: stringdefault.StaticString(""), + Optional: true, + Computed: true, + Description: "The ID of a `twingate_security_policy` to set as this Resource's Security Policy. Default is `Default Policy`.", Default: stringdefault.StaticString(DefaultSecurityPolicyID), PlanModifiers: []planmodifier.String{UseDefaultPolicyForUnknownModifier()}, }, attr.IsVisible: schema.BoolAttribute{ Optional: true, Computed: true, - Description: "Controls whether this Resource will be visible in the main Resource list in the Twingate Client.", + Description: "Controls whether this Resource will be visible in the main Resource list in the Twingate Client. Default is true.", Default: booldefault.StaticBool(true), PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()}, }, attr.IsBrowserShortcutEnabled: schema.BoolAttribute{ Optional: true, Computed: true, - Description: `Controls whether an "Open in Browser" shortcut will be shown for this Resource in the Twingate Client.`, + Description: `Controls whether an "Open in Browser" shortcut will be shown for this Resource in the Twingate Client. Default is false.`, Default: booldefault.StaticBool(false), }, attr.ID: schema.StringAttribute{ diff --git a/twingate/internal/test/acctests/resource/resource_test.go b/twingate/internal/test/acctests/resource/resource_test.go index ade5ff8d..b1a1df2e 100644 --- a/twingate/internal/test/acctests/resource/resource_test.go +++ b/twingate/internal/test/acctests/resource/resource_test.go @@ -1594,16 +1594,13 @@ func TestAccTwingateCreateResourceWithFlagIsVisible(t *testing.T) { Config: createSimpleResource(terraformResourceName, remoteNetworkName, resourceName), Check: acctests.ComposeTestCheckFunc( acctests.CheckTwingateResourceExists(theResource), - sdk.TestCheckNoResourceAttr(theResource, attr.IsVisible), + sdk.TestCheckResourceAttr(theResource, attr.IsVisible, "true"), ), }, { - // expecting no changes - default value on the backend side is `true` + // expecting no changes - default value is `true` PlanOnly: true, Config: createResourceWithFlagIsVisible(terraformResourceName, remoteNetworkName, resourceName, true), - Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckResourceAttr(theResource, attr.IsVisible, "true"), - ), }, { Config: createResourceWithFlagIsVisible(terraformResourceName, remoteNetworkName, resourceName, false), @@ -1615,16 +1612,11 @@ func TestAccTwingateCreateResourceWithFlagIsVisible(t *testing.T) { // expecting no changes - no drift after re-applying changes PlanOnly: true, Config: createResourceWithFlagIsVisible(terraformResourceName, remoteNetworkName, resourceName, false), - Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckResourceAttr(theResource, attr.IsVisible, "false"), - ), }, { - // expecting no changes - flag not set - PlanOnly: true, - Config: createSimpleResource(terraformResourceName, remoteNetworkName, resourceName), + Config: createSimpleResource(terraformResourceName, remoteNetworkName, resourceName), Check: acctests.ComposeTestCheckFunc( - sdk.TestCheckNoResourceAttr(theResource, attr.IsVisible), + sdk.TestCheckResourceAttr(theResource, attr.IsVisible, "true"), ), }, },