Skip to content

Commit

Permalink
[Docs] Improved examples for access_group (#546)
Browse files Browse the repository at this point in the history
Co-authored-by: Eran Kampf <[email protected]>
  • Loading branch information
alexb-twingate and ekampf authored Jun 17, 2024
1 parent 1bff20c commit 84ea991
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 18 deletions.
56 changes: 47 additions & 9 deletions docs/resources/resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ resource "twingate_group" "aws" {
name = "aws_group"
}
data "twingate_group" "security" {
id = "securityGroupID"
}
data "twingate_groups" "devops" {
name_contains = "DevOps"
}
data "twingate_groups" "sre" {
name_contains = "SRE"
}
resource "twingate_service_account" "github_actions_prod" {
name = "Github Actions PROD"
}
Expand All @@ -35,8 +47,8 @@ data "twingate_security_policy" "test_policy" {
}
resource "twingate_resource" "resource" {
name = "network"
address = "internal.int"
name = "network"
address = "internal.int"
remote_network_id = twingate_remote_network.aws_network.id
security_policy_id = data.twingate_security_policy.test_policy.id
Expand All @@ -45,26 +57,52 @@ resource "twingate_resource" "resource" {
allow_icmp = true
tcp = {
policy = "RESTRICTED"
ports = ["80", "82-83"]
ports = ["80", "82-83"]
}
udp = {
policy = "ALLOW_ALL"
}
}
// Adding a single group via `access_group`
access_group {
group_id = twingate_group.aws.id
security_policy_id = data.twingate_security_policy.test_policy.id
usage_based_autolock_duration_days = 30
}
// Adding multiple groups by individual ID
dynamic "access_group" {
for_each = [twingate_group.aws.id]
for_each = toset([twingate_group.aws.id, data.twingate_group.security.id])
content {
group_id = access_group.value
security_policy_id = data.twingate_security_policy.test_policy.id
group_id = access_group.value
security_policy_id = data.twingate_security_policy.test_policy.id
usage_based_autolock_duration_days = 30
}
}
dynamic "access_service" {
for_each = [twingate_service_account.github_actions_prod.id]
// Adding multiple groups from twingate_groups data sources
dynamic "access_group" {
for_each = setunion(
data.twingate_groups.devops.groups[*].id,
data.twingate_groups.sre.groups[*].id,
// Single IDs can be added by wrapping them in a set
toset([data.twingate_group.security.id])
)
content {
group_id = access_group.value
security_policy_id = data.twingate_security_policy.test_policy.id
usage_based_autolock_duration_days = 30
}
}
// Service acoount access is specified similarly
// A `for_each` block may be used like above to assign access to multiple
// service accounts in a single configuration block.
access_service {
content {
service_account_id = access_service.value
service_account_id = twingate_service_account.github_actions_prod.id
}
}
Expand Down
56 changes: 47 additions & 9 deletions examples/resources/twingate_resource/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ resource "twingate_group" "aws" {
name = "aws_group"
}

data "twingate_group" "security" {
id = "securityGroupID"
}

data "twingate_groups" "devops" {
name_contains = "DevOps"
}

data "twingate_groups" "sre" {
name_contains = "SRE"
}

resource "twingate_service_account" "github_actions_prod" {
name = "Github Actions PROD"
}
Expand All @@ -20,8 +32,8 @@ data "twingate_security_policy" "test_policy" {
}

resource "twingate_resource" "resource" {
name = "network"
address = "internal.int"
name = "network"
address = "internal.int"
remote_network_id = twingate_remote_network.aws_network.id

security_policy_id = data.twingate_security_policy.test_policy.id
Expand All @@ -30,26 +42,52 @@ resource "twingate_resource" "resource" {
allow_icmp = true
tcp = {
policy = "RESTRICTED"
ports = ["80", "82-83"]
ports = ["80", "82-83"]
}
udp = {
policy = "ALLOW_ALL"
}
}

// Adding a single group via `access_group`
access_group {
group_id = twingate_group.aws.id
security_policy_id = data.twingate_security_policy.test_policy.id
usage_based_autolock_duration_days = 30
}

// Adding multiple groups by individual ID
dynamic "access_group" {
for_each = [twingate_group.aws.id]
for_each = toset([twingate_group.aws.id, data.twingate_group.security.id])
content {
group_id = access_group.value
security_policy_id = data.twingate_security_policy.test_policy.id
group_id = access_group.value
security_policy_id = data.twingate_security_policy.test_policy.id
usage_based_autolock_duration_days = 30
}
}

dynamic "access_service" {
for_each = [twingate_service_account.github_actions_prod.id]
// Adding multiple groups from twingate_groups data sources
dynamic "access_group" {
for_each = setunion(
data.twingate_groups.devops.groups[*].id,
data.twingate_groups.sre.groups[*].id,
// Single IDs can be added by wrapping them in a set
toset([data.twingate_group.security.id])
)
content {
group_id = access_group.value
security_policy_id = data.twingate_security_policy.test_policy.id
usage_based_autolock_duration_days = 30

}
}

// Service acoount access is specified similarly
// A `for_each` block may be used like above to assign access to multiple
// service accounts in a single configuration block.
access_service {
content {
service_account_id = access_service.value
service_account_id = twingate_service_account.github_actions_prod.id
}
}

Expand Down

0 comments on commit 84ea991

Please sign in to comment.