Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
vmanilo committed Dec 2, 2023
1 parent 78a3c52 commit 5bf80fa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
10 changes: 8 additions & 2 deletions docs/resources/resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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`.

Expand Down
6 changes: 6 additions & 0 deletions examples/resources/twingate_resource/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
11 changes: 5 additions & 6 deletions twingate/internal/provider/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
16 changes: 4 additions & 12 deletions twingate/internal/test/acctests/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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"),
),
},
},
Expand Down

0 comments on commit 5bf80fa

Please sign in to comment.