diff --git a/sysdig/common.go b/sysdig/common.go index ea2f54d1f..85f40ed6b 100644 --- a/sysdig/common.go +++ b/sysdig/common.go @@ -59,4 +59,5 @@ const ( SchemaCloudProviderType = "provider_type" SchemaFeature = "feature" SchemaManagementAccountId = "management_account_id" + SchemaOrganizationalUnitIds = "organizational_unit_ids" ) diff --git a/sysdig/resource_sysdig_secure_organization.go b/sysdig/resource_sysdig_secure_organization.go index c5581ec63..a42d66b1b 100644 --- a/sysdig/resource_sysdig_secure_organization.go +++ b/sysdig/resource_sysdig_secure_organization.go @@ -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, + }, + }, }, } } @@ -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) } @@ -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 @@ -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 { @@ -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