Skip to content

Commit

Permalink
fix(team-service-account): api key not set (#428)
Browse files Browse the repository at this point in the history
* fix api_key not set

* fix field other than name cannot be updated

* updated doc
  • Loading branch information
Shadow649 authored Oct 5, 2023
1 parent c637e28 commit 8120b3e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
12 changes: 8 additions & 4 deletions sysdig/resource_sysdig_team_service_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,23 @@ func resourceSysdigTeamServiceAccount() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Default: "ROLE_TEAM_READ",
ForceNew: true,
},
SchemaExpirationDateKey: {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
},
SchemaTeamIDKey: {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
},
SchemaSystemRoleKey: {
Type: schema.TypeString,
Optional: true,
Default: "ROLE_SERVICE_ACCOUNT",
ForceNew: true,
},
SchemaCreatedDateKey: {
Type: schema.TypeInt,
Expand Down Expand Up @@ -104,6 +108,10 @@ func resourceSysdigTeamServiceAccountCreate(ctx context.Context, d *schema.Resou
}

d.SetId(strconv.Itoa(teamServiceAccount.ID))
err = d.Set(SchemaApiKeyKey, teamServiceAccount.ApiKey)
if err != nil {
return diag.FromErr(err)
}

resourceSysdigTeamServiceAccountRead(ctx, d, m)

Expand Down Expand Up @@ -189,10 +197,6 @@ func teamServiceAccountToResourceData(teamServiceAccount *v2.TeamServiceAccount,
if err != nil {
return err
}
err = d.Set(SchemaApiKeyKey, teamServiceAccount.ApiKey)
if err != nil {
return err
}

return nil
}
52 changes: 52 additions & 0 deletions sysdig/resource_sysdig_team_service_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,33 @@ func TestAccTeamServiceAccount(t *testing.T) {
"role",
"ROLE_TEAM_READ",
),
resource.TestCheckResourceAttrSet("sysdig_team_service_account.service-account-monitor",
"api_key",
),
resource.TestCheckResourceAttr("sysdig_team_service_account.service-account-monitor",
"expiration_date",
"4070908800",
),
),
},
{
Config: teamServiceAccountMonitorTeamNewExpirationDate(monitorsvc),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("sysdig_team_service_account.service-account-monitor",
"name",
monitorsvc,
),
resource.TestCheckResourceAttr("sysdig_team_service_account.service-account-monitor",
"role",
"ROLE_TEAM_READ",
),
resource.TestCheckResourceAttrSet("sysdig_team_service_account.service-account-monitor",
"api_key",
),
resource.TestCheckResourceAttr("sysdig_team_service_account.service-account-monitor",
"expiration_date",
"4070995200",
),
),
},
{
Expand All @@ -49,6 +76,9 @@ func TestAccTeamServiceAccount(t *testing.T) {
"role",
"ROLE_TEAM_READ",
),
resource.TestCheckResourceAttrSet("sysdig_team_service_account.service-account-secure",
"api_key",
),
),
},
},
Expand Down Expand Up @@ -77,6 +107,28 @@ resource "sysdig_team_service_account" "service-account-monitor" {
`, name, name)
}

func teamServiceAccountMonitorTeamNewExpirationDate(name string) string {
return fmt.Sprintf(`
resource "time_static" "example" {
rfc3339 = "2099-01-02T00:00:00Z"
}
resource "sysdig_monitor_team" "sample" {
name = "monitor-sample-%s"
entrypoint {
type = "Explore"
}
}
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" {
Expand Down
3 changes: 1 addition & 2 deletions website/docs/r/team_service_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ resource "sysdig_team_service_account" "service-account" {
name = "read only"
role = "ROLE_TEAM_READ"
expiration_date = time_static.example.unix
team_id = sysdig_monitor_teamt.sample.id
team_id = sysdig_monitor_team.devops.id
}
```
Expand Down Expand Up @@ -64,4 +64,3 @@ Sysdig team service account can be imported using the ID, e.g.
```
$ terraform import sysdig_team_service_account.my_team_service_account 10
```

0 comments on commit 8120b3e

Please sign in to comment.