Skip to content

Commit

Permalink
add test for secure
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadow649 committed Jul 20, 2023
1 parent 2c8f28f commit a44b519
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions sysdig/resource_sysdig_team_service_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ package sysdig_test
import (
"fmt"
"github.com/draios/terraform-provider-sysdig/sysdig"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"testing"
)

func TestAccTeamServiceAccount(t *testing.T) {
name := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
monitorsvc := randomText(10)
securesvc := randomText(10)

resource.ParallelTest(t, resource.TestCase{
PreCheck: preCheckAnyEnv(t, SysdigMonitorApiTokenEnv, SysdigSecureApiTokenEnv),
Expand All @@ -26,13 +26,26 @@ func TestAccTeamServiceAccount(t *testing.T) {
},
Steps: []resource.TestStep{
{
Config: teamServiceAccount(name),
Config: teamServiceAccountMonitorTeam(monitorsvc),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("sysdig_team_service_account.service-account",
resource.TestCheckResourceAttr("sysdig_team_service_account.service-account-monitor",
"name",
name,
monitorsvc,
),
resource.TestCheckResourceAttr("sysdig_team_service_account.service-account",
resource.TestCheckResourceAttr("sysdig_team_service_account.service-account-monitor",
"role",
"ROLE_TEAM_READ",
),
),
},
{
Config: teamServiceAccountSecureTeam(securesvc),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("sysdig_team_service_account.service-account-secure",
"name",
securesvc,
),
resource.TestCheckResourceAttr("sysdig_team_service_account.service-account-secure",
"role",
"ROLE_TEAM_READ",
),
Expand All @@ -42,24 +55,43 @@ func TestAccTeamServiceAccount(t *testing.T) {
})
}

func teamServiceAccount(name string) string {
func teamServiceAccountMonitorTeam(name string) string {
return fmt.Sprintf(`
resource "time_static" "example" {
rfc3339 = "2099-01-01T00:00:00Z"
}
resource "sysdig_monitor_team" "sample" {
name = "sample-%s"
name = "monitor-sample-%s"
entrypoint {
type = "Explore"
}
}
resource "sysdig_team_service_account" "service-account" {
resource "sysdig_team_service_account" "service-account-monitor" {
name = "%s"
expiration_date = time_static.example.unix
team_id = sysdig_monitor_team.sample.id
}
`, name, name)
}

func teamServiceAccountSecureTeam(name string) string {
return fmt.Sprintf(`
resource "time_static" "example" {
rfc3339 = "2099-01-01T00:00:00Z"
}
resource "sysdig_secure_team" "sample" {
name = "secure-sample-%s"
all_zones = "true"
}
resource "sysdig_team_service_account" "service-account-secure" {
name = "%s"
expiration_date = time_static.example.unix
team_id = sysdig_secure_team.sample.id
}
`, name, name)
}

0 comments on commit a44b519

Please sign in to comment.