Skip to content

Commit

Permalink
Restricting machine_account_creation_rules and machine_domain_identit…
Browse files Browse the repository at this point in the history
…y update when no machines are being added
  • Loading branch information
Sourav Samanta[Sourav.Samanta] authored and sourav-citrix committed Oct 24, 2024
1 parent 23d96c0 commit bf4e1d2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
48 changes: 48 additions & 0 deletions internal/daas/machine_catalog/machine_catalog_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,4 +897,52 @@ func (r *machineCatalogResource) ModifyPlan(ctx context.Context, req resource.Mo
resp.Diagnostics.AddError(util.ProviderInitializationErrorMsg, util.MissingProviderClientIdAndSecretErrorMsg)
return
}

if req.Plan.Raw.IsNull() || req.State.Raw.IsNull() {
return
}

var plan MachineCatalogResourceModel
diags := req.Plan.Get(ctx, &plan)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

var state MachineCatalogResourceModel
diags = req.State.Get(ctx, &state)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

if !plan.ProvisioningScheme.IsNull() {
provSchemePlan := util.ObjectValueToTypedObject[ProvisioningSchemeModel](ctx, &resp.Diagnostics, plan.ProvisioningScheme)
provSchemeState := util.ObjectValueToTypedObject[ProvisioningSchemeModel](ctx, &resp.Diagnostics, state.ProvisioningScheme)

machineAccountCreationRulesPlan := util.ObjectValueToTypedObject[MachineAccountCreationRulesModel](ctx, &resp.Diagnostics, provSchemePlan.MachineAccountCreationRules)
machineAccountCreationRulesState := util.ObjectValueToTypedObject[MachineAccountCreationRulesModel](ctx, &resp.Diagnostics, provSchemeState.MachineAccountCreationRules)
machineDomainIdentityPlan := util.ObjectValueToTypedObject[MachineDomainIdentityModel](ctx, &resp.Diagnostics, provSchemePlan.MachineDomainIdentity)
machineDomainIdentityState := util.ObjectValueToTypedObject[MachineDomainIdentityModel](ctx, &resp.Diagnostics, provSchemeState.MachineDomainIdentity)

if machineDomainIdentityPlan != machineDomainIdentityState &&
provSchemePlan.NumTotalMachines.ValueInt64() == provSchemeState.NumTotalMachines.ValueInt64() {

resp.Diagnostics.AddError(
"Error updating Machine Catalog",
"machine_domain_identity can only be updated when adding or removing machines.",
)
return
}

if machineAccountCreationRulesPlan != machineAccountCreationRulesState &&
provSchemePlan.NumTotalMachines.ValueInt64() <= provSchemeState.NumTotalMachines.ValueInt64() {
resp.Diagnostics.AddError(
"Error updating Machine Catalog",
"machine_account_creation_rules can only be updated when adding machines.",
)
return
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ func (MachineDomainIdentityModel) GetSchema() schema.SingleNestedAttribute {
Validators: []validator.String{
stringvalidator.RegexMatches(regexp.MustCompile(util.DomainFqdnRegex), "must be in FQDN format"),
},
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"domain_ou": schema.StringAttribute{
Description: "The organization unit that computer accounts will be created into.",
Expand Down

0 comments on commit bf4e1d2

Please sign in to comment.