Skip to content

Commit

Permalink
feat(cloudauth): organizational units
Browse files Browse the repository at this point in the history
  • Loading branch information
cgeers committed Oct 26, 2023
1 parent fc6bad7 commit 0a5f557
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions sysdig/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ const (
SchemaCloudProviderType = "provider_type"
SchemaFeature = "feature"
SchemaManagementAccountId = "management_account_id"
SchemaOrganizationalUnitIds = "organizational_unit_ids"
)
30 changes: 22 additions & 8 deletions sysdig/resource_sysdig_secure_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ func resourceSysdigSecureOrganization() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
SchemaOrganizationalUnitIds: {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}
Expand All @@ -54,7 +61,7 @@ func resourceSysdigSecureOrganizationCreate(ctx context.Context, data *schema.Re

org := secureOrganizationFromResourceData(data)

orgCreated, err := client.CreateOrganizationSecure(ctx, &org)
orgCreated, err := client.CreateOrganizationSecure(ctx, org)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -111,7 +118,7 @@ func resourceSysdigSecureOrganizationUpdate(ctx context.Context, data *schema.Re

org := secureOrganizationFromResourceData(data)

_, errStatus, err := client.UpdateOrganizationSecure(ctx, data.Id(), &org)
_, errStatus, err := client.UpdateOrganizationSecure(ctx, data.Id(), org)
if err != nil {
if strings.Contains(errStatus, "404") {
return nil
Expand All @@ -122,12 +129,14 @@ func resourceSysdigSecureOrganizationUpdate(ctx context.Context, data *schema.Re
return nil
}

func secureOrganizationFromResourceData(data *schema.ResourceData) v2.OrganizationSecure {
return v2.OrganizationSecure{
CloudOrganization: cloudauth.CloudOrganization{
ManagementAccountId: data.Get(SchemaManagementAccountId).(string),
},
}
func secureOrganizationFromResourceData(data *schema.ResourceData) *v2.OrganizationSecure {
secureOrganization := &v2.OrganizationSecure{CloudOrganization: cloudauth.CloudOrganization{}}
secureOrganization.CloudOrganization.ManagementAccountId = data.Get(SchemaManagementAccountId).(string)
secureOrganization.CloudOrganization.OrganizationalUnitIds = append(
secureOrganization.CloudOrganization.OrganizationalUnitIds,
data.Get(SchemaOrganizationalUnitIds).([]string)...,
)
return secureOrganization
}

func secureOrganizationToResourceData(data *schema.ResourceData, org *v2.OrganizationSecure) error {
Expand All @@ -136,6 +145,11 @@ func secureOrganizationToResourceData(data *schema.ResourceData, org *v2.Organiz
return err
}

err = data.Set(SchemaOrganizationalUnitIds, org.OrganizationalUnitIds)
if err != nil {
return err
}

err = data.Set(SchemaIDKey, org.Id)
if err != nil {
return err
Expand Down

0 comments on commit 0a5f557

Please sign in to comment.