Skip to content

Commit

Permalink
Fix inconsistent values in tenants and scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuolun-citrix committed Sep 6, 2024
1 parent 24754c3 commit 0a5ba69
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 12 deletions.
4 changes: 4 additions & 0 deletions internal/daas/application/application_group_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ func (r *applicationGroupResource) Create(ctx context.Context, req resource.Crea
if !plan.Tenants.IsNull() {
associatedTenants := util.StringSetToStringArray(ctx, &resp.Diagnostics, plan.Tenants)
createApplicationGroupRequest.SetTenants(associatedTenants)
} else {
createApplicationGroupRequest.SetTenants([]string{})
}

addApplicationsGroupRequest := r.client.ApiClient.ApplicationGroupsAPIsDAAS.ApplicationGroupsCreateApplicationGroup(ctx)
Expand Down Expand Up @@ -235,6 +237,8 @@ func (r *applicationGroupResource) Update(ctx context.Context, req resource.Upda
if !plan.Tenants.IsNull() {
associatedTenants := util.StringSetToStringArray(ctx, &resp.Diagnostics, plan.Tenants)
editApplicationGroupRequestBody.SetTenants(associatedTenants)
} else {
editApplicationGroupRequestBody.SetTenants([]string{})
}

// Update Application
Expand Down
7 changes: 4 additions & 3 deletions internal/daas/application/application_group_resource_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ApplicationGroupResourceModel struct {
DeliveryGroups types.Set `tfsdk:"delivery_groups"` // Set[string]
Scopes types.Set `tfsdk:"scopes"` // Set[string]
ApplicationGroupFolderPath types.String `tfsdk:"application_group_folder_path"`
Tenants types.Set `tfsdk:"tenants"` // Set[string]
Tenants types.Set `tfsdk:"tenants"` // Set[string]
}

func (ApplicationGroupResourceModel) GetSchema() schema.Schema {
Expand Down Expand Up @@ -140,7 +140,8 @@ func (r ApplicationGroupResourceModel) RefreshPropertyValues(ctx context.Context
}

if applicationGroup.GetScopes() != nil {
scopeIds := util.GetIdsForScopeObjects(applicationGroup.GetScopes())
scopeIdsInState := util.StringSetToStringArray(ctx, diagnostics, r.Scopes)
scopeIds := util.GetIdsForFilteredScopeObjects(scopeIdsInState, applicationGroup.GetScopes())
r.Scopes = util.StringArrayToStringSet(ctx, diagnostics, scopeIds)
}

Expand All @@ -165,7 +166,7 @@ func (r ApplicationGroupResourceModel) RefreshPropertyValues(ctx context.Context
} else {
r.ApplicationGroupFolderPath = types.StringNull()
}

if len(applicationGroup.GetTenants()) > 0 || !r.Tenants.IsNull() {
var remoteTenants []string
for _, tenant := range applicationGroup.GetTenants() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,9 @@ func (r DeliveryGroupResourceModel) RefreshPropertyValues(ctx context.Context, d

minimumFunctionalLevel := deliveryGroup.GetMinimumFunctionalLevel()
r.MinimumFunctionalLevel = types.StringValue(string(minimumFunctionalLevel))
scopeIds := util.GetIdsForScopeObjects(deliveryGroup.GetScopes())

scopeIdsInState := util.StringSetToStringArray(ctx, diagnostics, r.Scopes)
scopeIds := util.GetIdsForFilteredScopeObjects(scopeIdsInState, deliveryGroup.GetScopes())
r.Scopes = util.StringArrayToStringSet(ctx, diagnostics, scopeIds)

if deliveryGroup.GetReuseMachinesWithoutShutdownInOutage() {
Expand Down
4 changes: 4 additions & 0 deletions internal/daas/delivery_group/delivery_group_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,8 @@ func getRequestModelForDeliveryGroupCreate(ctx context.Context, diagnostics *dia
if !plan.Tenants.IsNull() {
associatedTenants := util.StringSetToStringArray(ctx, diagnostics, plan.Tenants)
body.SetTenants(associatedTenants)
} else {
body.SetTenants([]string{})
}

return body, nil
Expand Down Expand Up @@ -995,6 +997,8 @@ func getRequestModelForDeliveryGroupUpdate(ctx context.Context, diagnostics *dia
if !plan.Tenants.IsNull() {
associatedTenants := util.StringSetToStringArray(ctx, diagnostics, plan.Tenants)
editDeliveryGroupRequestBody.SetTenants(associatedTenants)
} else {
editDeliveryGroupRequestBody.SetTenants([]string{})
}

return editDeliveryGroupRequestBody, nil
Expand Down
3 changes: 2 additions & 1 deletion internal/daas/hypervisor/aws_hypervisor_resource_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ func (r AwsHypervisorResourceModel) RefreshPropertyValues(ctx context.Context, d
r.Zone = types.StringValue(hypZone.GetId())
r.Region = types.StringValue(hypervisor.GetRegion())
r.ApiKey = types.StringValue(hypervisor.GetApiKey())
scopeIds := util.GetIdsForScopeObjects(hypervisor.GetScopes())
scopeIdsInState := util.StringSetToStringArray(ctx, diagnostics, r.Scopes)
scopeIds := util.GetIdsForFilteredScopeObjects(scopeIdsInState, hypervisor.GetScopes())
r.Scopes = util.StringArrayToStringSet(ctx, diagnostics, scopeIds)

return r
Expand Down
3 changes: 2 additions & 1 deletion internal/daas/hypervisor/azure_hypervisor_resource_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ func (r AzureHypervisorResourceModel) RefreshPropertyValues(ctx context.Context,
r.ApplicationId = types.StringValue(hypervisor.GetApplicationId())
r.SubscriptionId = types.StringValue(hypervisor.GetSubscriptionId())
r.ActiveDirectoryId = types.StringValue(hypervisor.GetActiveDirectoryId())
scopeIds := util.GetIdsForScopeObjects(hypervisor.GetScopes())
scopeIdsInState := util.StringSetToStringArray(ctx, diagnostics, r.Scopes)
scopeIds := util.GetIdsForFilteredScopeObjects(scopeIdsInState, hypervisor.GetScopes())
r.Scopes = util.StringArrayToStringSet(ctx, diagnostics, scopeIds)

customPropertiesString := hypervisor.GetCustomProperties()
Expand Down
3 changes: 2 additions & 1 deletion internal/daas/hypervisor/gcp_hypervisor_resource_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ func (r GcpHypervisorResourceModel) RefreshPropertyValues(ctx context.Context, d
hypZone := hypervisor.GetZone()
r.Zone = types.StringValue(hypZone.GetId())
r.ServiceAccountId = types.StringValue(hypervisor.GetServiceAccountId())
scopeIds := util.GetIdsForScopeObjects(hypervisor.GetScopes())
scopeIdsInState := util.StringSetToStringArray(ctx, diagnostics, r.Scopes)
scopeIds := util.GetIdsForFilteredScopeObjects(scopeIdsInState, hypervisor.GetScopes())
r.Scopes = util.StringArrayToStringSet(ctx, diagnostics, scopeIds)

return r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ func (r NutanixHypervisorResourceModel) RefreshPropertyValues(ctx context.Contex
r.MaxAbsoluteActiveActions = types.Int64Value(int64(hypervisor.GetMaxAbsoluteActiveActions()))
r.MaxAbsoluteNewActionsPerMinute = types.Int64Value(int64(hypervisor.GetMaxAbsoluteNewActionsPerMinute()))
r.MaxPowerActionsPercentageOfMachines = types.Int64Value(int64(hypervisor.GetMaxPowerActionsPercentageOfMachines()))
scopeIds := util.GetIdsForScopeObjects(hypervisor.GetScopes())
scopeIdsInState := util.StringSetToStringArray(ctx, diagnostics, r.Scopes)
scopeIds := util.GetIdsForFilteredScopeObjects(scopeIdsInState, hypervisor.GetScopes())
r.Scopes = util.StringArrayToStringSet(ctx, diagnostics, scopeIds)

hypZone := hypervisor.GetZone()
Expand Down
3 changes: 2 additions & 1 deletion internal/daas/hypervisor/scvmm_hypervisor_resource_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ func (r SCVMMMHypervisorResourceModel) RefreshPropertyValues(ctx context.Context
r.MaxAbsoluteActiveActions = types.Int64Value(int64(hypervisor.GetMaxAbsoluteActiveActions()))
r.MaxAbsoluteNewActionsPerMinute = types.Int64Value(int64(hypervisor.GetMaxAbsoluteNewActionsPerMinute()))
r.MaxPowerActionsPercentageOfMachines = types.Int64Value(int64(hypervisor.GetMaxPowerActionsPercentageOfMachines()))
scopeIds := util.GetIdsForScopeObjects(hypervisor.GetScopes())
scopeIdsInState := util.StringSetToStringArray(ctx, diagnostics, r.Scopes)
scopeIds := util.GetIdsForFilteredScopeObjects(scopeIdsInState, hypervisor.GetScopes())
r.Scopes = util.StringArrayToStringSet(ctx, diagnostics, scopeIds)

hypZone := hypervisor.GetZone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ func (r VsphereHypervisorResourceModel) RefreshPropertyValues(ctx context.Contex
r.SslThumbprints = types.ListNull(types.StringType)
}

scopeIds := util.GetIdsForScopeObjects(hypervisor.GetScopes())
scopeIdsInState := util.StringSetToStringArray(ctx, diagnostics, r.Scopes)
scopeIds := util.GetIdsForFilteredScopeObjects(scopeIdsInState, hypervisor.GetScopes())
r.Scopes = util.StringArrayToStringSet(ctx, diagnostics, scopeIds)

hypZone := hypervisor.GetZone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ func (r XenserverHypervisorResourceModel) RefreshPropertyValues(ctx context.Cont
r.MaxAbsoluteActiveActions = types.Int64Value(int64(hypervisor.GetMaxAbsoluteActiveActions()))
r.MaxAbsoluteNewActionsPerMinute = types.Int64Value(int64(hypervisor.GetMaxAbsoluteNewActionsPerMinute()))
r.MaxPowerActionsPercentageOfMachines = types.Int64Value(int64(hypervisor.GetMaxPowerActionsPercentageOfMachines()))
scopeIds := util.GetIdsForScopeObjects(hypervisor.GetScopes())
scopeIdsInState := util.StringSetToStringArray(ctx, diagnostics, r.Scopes)
scopeIds := util.GetIdsForFilteredScopeObjects(scopeIdsInState, hypervisor.GetScopes())
r.Scopes = util.StringArrayToStringSet(ctx, diagnostics, scopeIds)

sslThumbprints := util.RefreshListValues(ctx, diagnostics, r.SslThumbprints, hypervisor.GetSslThumbprints())
Expand Down
4 changes: 4 additions & 0 deletions internal/daas/machine_catalog/machine_catalog_common_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func getRequestModelForCreateMachineCatalog(plan MachineCatalogResourceModel, ct
if !plan.Tenants.IsNull() {
associatedTenants := util.StringSetToStringArray(ctx, diagnostics, plan.Tenants)
body.SetTenants(associatedTenants)
} else {
body.SetTenants([]string{})
}

if !plan.Scopes.IsNull() {
Expand Down Expand Up @@ -161,6 +163,8 @@ func getRequestModelForUpdateMachineCatalog(plan MachineCatalogResourceModel, ct
if !plan.Tenants.IsNull() {
associatedTenants := util.StringSetToStringArray(ctx, &resp.Diagnostics, plan.Tenants)
body.SetTenants(associatedTenants)
} else {
body.SetTenants([]string{})
}

if !plan.Scopes.IsNull() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,8 @@ func (r MachineCatalogResourceModel) RefreshPropertyValues(ctx context.Context,
return r
}

scopeIds := util.GetIdsForScopeObjects(catalog.GetScopes())
scopeIdsInState := util.StringSetToStringArray(ctx, diagnostics, r.Scopes)
scopeIds := util.GetIdsForFilteredScopeObjects(scopeIdsInState, catalog.GetScopes())
r.Scopes = util.StringArrayToStringSet(ctx, diagnostics, scopeIds)

// Provisioning Scheme Properties
Expand Down
23 changes: 23 additions & 0 deletions internal/util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,29 @@ func GetIdsForOrchestrationObjects[objType any](slice []objType) []string {
return ids
}

// <summary>
// Filter and Extract Ids from a list of scope responses
// </summary>
// <param name="scopeIdsInState">List of scope Ids in state or config</param>
// <param name="scopeResponses">List of scope objects from remote</param>
// <returns>List of Ids extracted from response</returns>
func GetIdsForFilteredScopeObjects(scopeIdsInState []string, scopeResponses []citrixorchestration.ScopeResponseModel) []string {
if scopeIdsInState == nil {
scopeIdsInState = []string{}
}
filteredScopes := []citrixorchestration.ScopeResponseModel{}
for _, scope := range scopeResponses {
if scope.GetIsTenantScope() && !slices.ContainsFunc(scopeIdsInState, func(scopeId string) bool {
return strings.EqualFold(scopeId, scope.GetId())
}) {
continue
}
filteredScopes = append(filteredScopes, scope)
}
scopeIds := GetIdsForScopeObjects(filteredScopes)
return scopeIds
}

// <summary>
// Extract Ids from a list of scope objects
// </summary>
Expand Down

0 comments on commit 0a5ba69

Please sign in to comment.