Skip to content

Commit ab1ca09

Browse files
authored
feat(cloud-account): add new workload identity field for gcp organizational (#235)
* adding new workload identity field * testing a flag * resetting the flag * merging with latest master * adding codeowners and docs
1 parent c1fc125 commit ab1ca09

File tree

5 files changed

+63
-12
lines changed

5 files changed

+63
-12
lines changed

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*fargate* @marojor @achandras @francesco-racciatti
33

44
# compliance
5-
*benchmark* @haresh-suresh @nkraemer-sysdig
5+
*benchmark* @haresh-suresh @nkraemer-sysdig @sameer-in
66

77
# monitor
88
*monitor*alert* @arturodilecce @dbonf

sysdig/internal/client/secure/models.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,13 @@ func VulnerabilityExceptionFromJSON(body []byte) *VulnerabilityException {
366366
// -------- CloudAccount --------
367367

368368
type CloudAccount struct {
369-
AccountID string `json:"accountId"`
370-
Provider string `json:"provider"`
371-
Alias string `json:"alias"`
372-
RoleAvailable bool `json:"roleAvailable"`
373-
RoleName string `json:"roleName"`
374-
ExternalID string `json:"externalId,omitempty"`
369+
AccountID string `json:"accountId"`
370+
Provider string `json:"provider"`
371+
Alias string `json:"alias"`
372+
RoleAvailable bool `json:"roleAvailable"`
373+
RoleName string `json:"roleName"`
374+
ExternalID string `json:"externalId,omitempty"`
375+
WorkLoadIdentityAccountID string `json:"workloadIdentityAccountId,omitempty"`
375376
}
376377

377378
func (e *CloudAccount) ToJSON() io.Reader {

sysdig/resource_sysdig_secure_cloud_account.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ func resourceSysdigSecureCloudAccount() *schema.Resource {
5858
Type: schema.TypeString,
5959
Computed: true,
6060
},
61+
"workload_identity_account_id": {
62+
Type: schema.TypeString,
63+
Optional: true,
64+
},
6165
},
6266
}
6367
}
@@ -80,6 +84,7 @@ func resourceSysdigSecureCloudAccountCreate(ctx context.Context, d *schema.Resou
8084
_ = d.Set("role_enabled", cloudAccount.RoleAvailable)
8185
_ = d.Set("role_name", cloudAccount.RoleName)
8286
_ = d.Set("external_id", cloudAccount.ExternalID)
87+
_ = d.Set("workload_identity_account_id", cloudAccount.WorkLoadIdentityAccountID)
8388

8489
return nil
8590
}
@@ -106,6 +111,7 @@ func resourceSysdigSecureCloudAccountRead(ctx context.Context, d *schema.Resourc
106111
_ = d.Set("role_enabled", cloudAccount.RoleAvailable)
107112
_ = d.Set("role_name", cloudAccount.RoleName)
108113
_ = d.Set("external_id", cloudAccount.ExternalID)
114+
_ = d.Set("workload_identity_account_id", cloudAccount.WorkLoadIdentityAccountID)
109115

110116
return nil
111117
}
@@ -145,10 +151,11 @@ func resourceSysdigSecureCloudAccountDelete(ctx context.Context, d *schema.Resou
145151

146152
func cloudAccountFromResourceData(d *schema.ResourceData) *secure.CloudAccount {
147153
return &secure.CloudAccount{
148-
AccountID: d.Get("account_id").(string),
149-
Provider: d.Get("cloud_provider").(string),
150-
Alias: d.Get("alias").(string),
151-
RoleAvailable: d.Get("role_enabled").(bool),
152-
RoleName: d.Get("role_name").(string),
154+
AccountID: d.Get("account_id").(string),
155+
Provider: d.Get("cloud_provider").(string),
156+
Alias: d.Get("alias").(string),
157+
RoleAvailable: d.Get("role_enabled").(bool),
158+
RoleName: d.Get("role_name").(string),
159+
WorkLoadIdentityAccountID: d.Get("workload_identity_account_id").(string),
153160
}
154161
}

sysdig/resource_sysdig_secure_cloud_account_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,43 @@ resource "sysdig_secure_cloud_account" "sample" {
6161
cloud_provider = "aws"
6262
}`, accountID)
6363
}
64+
65+
func TestAccSecureCloudAccountWID(t *testing.T) {
66+
rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) }
67+
accID := rText()
68+
resource.ParallelTest(t, resource.TestCase{
69+
PreCheck: func() {
70+
if v := os.Getenv("SYSDIG_SECURE_API_TOKEN"); v == "" {
71+
t.Fatal("SYSDIG_SECURE_API_TOKEN must be set for acceptance tests")
72+
}
73+
},
74+
ProviderFactories: map[string]func() (*schema.Provider, error){
75+
"sysdig": func() (*schema.Provider, error) {
76+
return sysdig.Provider(), nil
77+
},
78+
},
79+
Steps: []resource.TestStep{
80+
{
81+
Config: secureCloudAccountWithWID(accID),
82+
},
83+
{
84+
ResourceName: "sysdig_secure_cloud_account.sample-1",
85+
ImportState: true,
86+
ImportStateVerify: true,
87+
},
88+
},
89+
})
90+
}
91+
92+
func secureCloudAccountWithWID(accountID string) string {
93+
return fmt.Sprintf(`
94+
resource "sysdig_secure_cloud_account" "sample-1" {
95+
account_id = "sample-1-%s"
96+
cloud_provider = "aws"
97+
alias = "%s"
98+
role_enabled = "false"
99+
role_name = "CustomRoleName"
100+
workload_identity_account_id = "sample-1-%s"
101+
}
102+
`, accountID, accountID, accountID)
103+
}

website/docs/r/secure_cloud_account.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ resource "sysdig_secure_cloud_account" "sample" {
2121
alias = "prod"
2222
role_enabled = "false"
2323
role_name = "CustomRoleName"
24+
workload_identity_account_id = "457345678065"
2425
}
2526
```
2627

@@ -36,6 +37,8 @@ resource "sysdig_secure_cloud_account" "sample" {
3637

3738
* `role_name` - (Optional) The name of the role Sysdig will have permission to AssumeRole if `role_enaled` is set to `true`. Default: `SysdigCloudBench`.
3839

40+
* `workload_identity_account_id` - (Optional) For GCP only. The account id in which workload identity is present for this account in gcp org.
41+
3942
## Attributes Reference
4043

4144
No additional attributes are exported.

0 commit comments

Comments
 (0)