Skip to content

Commit 8120b3e

Browse files
authored
fix(team-service-account): api key not set (#428)
* fix api_key not set * fix field other than name cannot be updated * updated doc
1 parent c637e28 commit 8120b3e

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

sysdig/resource_sysdig_team_service_account.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,23 @@ func resourceSysdigTeamServiceAccount() *schema.Resource {
3434
Type: schema.TypeString,
3535
Optional: true,
3636
Default: "ROLE_TEAM_READ",
37+
ForceNew: true,
3738
},
3839
SchemaExpirationDateKey: {
3940
Type: schema.TypeInt,
4041
Required: true,
42+
ForceNew: true,
4143
},
4244
SchemaTeamIDKey: {
4345
Type: schema.TypeInt,
4446
Required: true,
47+
ForceNew: true,
4548
},
4649
SchemaSystemRoleKey: {
4750
Type: schema.TypeString,
4851
Optional: true,
4952
Default: "ROLE_SERVICE_ACCOUNT",
53+
ForceNew: true,
5054
},
5155
SchemaCreatedDateKey: {
5256
Type: schema.TypeInt,
@@ -104,6 +108,10 @@ func resourceSysdigTeamServiceAccountCreate(ctx context.Context, d *schema.Resou
104108
}
105109

106110
d.SetId(strconv.Itoa(teamServiceAccount.ID))
111+
err = d.Set(SchemaApiKeyKey, teamServiceAccount.ApiKey)
112+
if err != nil {
113+
return diag.FromErr(err)
114+
}
107115

108116
resourceSysdigTeamServiceAccountRead(ctx, d, m)
109117

@@ -189,10 +197,6 @@ func teamServiceAccountToResourceData(teamServiceAccount *v2.TeamServiceAccount,
189197
if err != nil {
190198
return err
191199
}
192-
err = d.Set(SchemaApiKeyKey, teamServiceAccount.ApiKey)
193-
if err != nil {
194-
return err
195-
}
196200

197201
return nil
198202
}

sysdig/resource_sysdig_team_service_account_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@ func TestAccTeamServiceAccount(t *testing.T) {
3636
"role",
3737
"ROLE_TEAM_READ",
3838
),
39+
resource.TestCheckResourceAttrSet("sysdig_team_service_account.service-account-monitor",
40+
"api_key",
41+
),
42+
resource.TestCheckResourceAttr("sysdig_team_service_account.service-account-monitor",
43+
"expiration_date",
44+
"4070908800",
45+
),
46+
),
47+
},
48+
{
49+
Config: teamServiceAccountMonitorTeamNewExpirationDate(monitorsvc),
50+
Check: resource.ComposeTestCheckFunc(
51+
resource.TestCheckResourceAttr("sysdig_team_service_account.service-account-monitor",
52+
"name",
53+
monitorsvc,
54+
),
55+
resource.TestCheckResourceAttr("sysdig_team_service_account.service-account-monitor",
56+
"role",
57+
"ROLE_TEAM_READ",
58+
),
59+
resource.TestCheckResourceAttrSet("sysdig_team_service_account.service-account-monitor",
60+
"api_key",
61+
),
62+
resource.TestCheckResourceAttr("sysdig_team_service_account.service-account-monitor",
63+
"expiration_date",
64+
"4070995200",
65+
),
3966
),
4067
},
4168
{
@@ -49,6 +76,9 @@ func TestAccTeamServiceAccount(t *testing.T) {
4976
"role",
5077
"ROLE_TEAM_READ",
5178
),
79+
resource.TestCheckResourceAttrSet("sysdig_team_service_account.service-account-secure",
80+
"api_key",
81+
),
5282
),
5383
},
5484
},
@@ -77,6 +107,28 @@ resource "sysdig_team_service_account" "service-account-monitor" {
77107
`, name, name)
78108
}
79109

110+
func teamServiceAccountMonitorTeamNewExpirationDate(name string) string {
111+
return fmt.Sprintf(`
112+
resource "time_static" "example" {
113+
rfc3339 = "2099-01-02T00:00:00Z"
114+
}
115+
116+
resource "sysdig_monitor_team" "sample" {
117+
name = "monitor-sample-%s"
118+
119+
entrypoint {
120+
type = "Explore"
121+
}
122+
}
123+
124+
resource "sysdig_team_service_account" "service-account-monitor" {
125+
name = "%s"
126+
expiration_date = time_static.example.unix
127+
team_id = sysdig_monitor_team.sample.id
128+
}
129+
`, name, name)
130+
}
131+
80132
func teamServiceAccountSecureTeam(name string) string {
81133
return fmt.Sprintf(`
82134
resource "time_static" "example" {

website/docs/r/team_service_account.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ resource "sysdig_team_service_account" "service-account" {
3131
name = "read only"
3232
role = "ROLE_TEAM_READ"
3333
expiration_date = time_static.example.unix
34-
team_id = sysdig_monitor_teamt.sample.id
34+
team_id = sysdig_monitor_team.devops.id
3535
}
3636
3737
```
@@ -64,4 +64,3 @@ Sysdig team service account can be imported using the ID, e.g.
6464
```
6565
$ terraform import sysdig_team_service_account.my_team_service_account 10
6666
```
67-

0 commit comments

Comments
 (0)