Skip to content

Commit

Permalink
add code to create to fail out if keys that don't exist in the global…
Browse files Browse the repository at this point in the history
… catalog are in the blueprint property set
  • Loading branch information
rajagopalans committed Nov 21, 2023
1 parent 753c149 commit 394e742
Showing 1 changed file with 39 additions and 18 deletions.
57 changes: 39 additions & 18 deletions apstra/resource_datacenter_property_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ func (o *resourceDatacenterPropertySet) Create(ctx context.Context, req resource
return
}

if len(keysToImport) != 0 {
// fetch available keys from the property set to be re-imported from the global catalog
availableKeys := globalCatalogKeys(ctx, apstra.ObjectId(plan.Id.ValueString()), o.client, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}

// ensure that keys configured to be imported actually exist in the Global
// Catalog's copy of the Property Set
missingRequiredKeys, _ := utils.DiffSliceSets(availableKeys, keysToImport)
if len(missingRequiredKeys) != 0 {
resp.Diagnostics.AddAttributeError(
path.Root("keys"),
fmt.Sprintf("Property Set %s does not contain all required Keys", plan.Id),
fmt.Sprintf("the following keys are configured for import, but are not "+
"available for import from the Global Catalog: %v", missingRequiredKeys),
)
return
}
}

// create a blueprint client
bpClient, err := o.client.NewTwoStageL3ClosClient(ctx, apstra.ObjectId(plan.BlueprintId.ValueString()))
if err != nil {
Expand Down Expand Up @@ -202,26 +223,26 @@ func (o *resourceDatacenterPropertySet) Update(ctx context.Context, req resource
if resp.Diagnostics.HasError() {
return
}
if len(keysToImport) != 0 {
// fetch available keys from the property set to be re-imported from the global catalog
availableKeys := globalCatalogKeys(ctx, apstra.ObjectId(plan.Id.ValueString()), o.client, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}

// fetch available keys from the property set to be re-imported from the global catalog
availableKeys := globalCatalogKeys(ctx, apstra.ObjectId(plan.Id.ValueString()), o.client, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}

// ensure that keys configured to be imported actually exist in the Global
// Catalog's copy of the Property Set
missingRequiredKeys, _ := utils.DiffSliceSets(availableKeys, keysToImport)
if len(missingRequiredKeys) != 0 {
resp.Diagnostics.AddAttributeError(
path.Root("keys"),
fmt.Sprintf("Property Set %s does not contain all required Keys", plan.Id),
fmt.Sprintf("the following keys are configured for import, but are not "+
"available for import from the Global Catalog: %v", missingRequiredKeys),
)
return
// ensure that keys configured to be imported actually exist in the Global
// Catalog's copy of the Property Set
missingRequiredKeys, _ := utils.DiffSliceSets(availableKeys, keysToImport)
if len(missingRequiredKeys) != 0 {
resp.Diagnostics.AddAttributeError(
path.Root("keys"),
fmt.Sprintf("Property Set %s does not contain all required Keys", plan.Id),
fmt.Sprintf("the following keys are configured for import, but are not "+
"available for import from the Global Catalog: %v", missingRequiredKeys),
)
return
}
}

// create a blueprint client
bpClient, err := o.client.NewTwoStageL3ClosClient(ctx, apstra.ObjectId(plan.BlueprintId.ValueString()))
if err != nil {
Expand Down

0 comments on commit 394e742

Please sign in to comment.