diff --git a/tools/importer-msgraph-metadata/components/workarounds/workaround_administrativeunits.go b/tools/importer-msgraph-metadata/components/workarounds/workaround_administrativeunits.go new file mode 100644 index 00000000000..d21f423fab4 --- /dev/null +++ b/tools/importer-msgraph-metadata/components/workarounds/workaround_administrativeunits.go @@ -0,0 +1,44 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package workarounds + +import ( + "strings" + + "github.com/hashicorp/pandora/tools/importer-msgraph-metadata/components/parser" + "github.com/hashicorp/pandora/tools/importer-msgraph-metadata/components/versions" +) + +var _ serviceWorkaround = workaroundAdministrativeUnits{} + +// workaroundAdministrativeUnits removes nonexistent `AdministrativeUnit` resources from the `Directory` service in +// the beta API, as these resources exist in the `administrativeUnits` service for this API version. +type workaroundAdministrativeUnits struct{} + +func (workaroundAdministrativeUnits) Name() string { + return "Administrative Units / remove nonexistent resources" +} + +func (workaroundAdministrativeUnits) Process(apiVersion, serviceName string, resources parser.Resources, resourceIds parser.ResourceIds) error { + if apiVersion != versions.ApiVersionBeta { + return nil + } + + if serviceName != "directory" { + return nil + } + + resourcesToDelete := make([]string, 0) + for resourceName := range resources { + if strings.HasPrefix(resourceName, "DirectoryAdministrativeUnit") { + resourcesToDelete = append(resourcesToDelete, resourceName) + } + } + + for _, resourceName := range resourcesToDelete { + delete(resources, resourceName) + } + + return nil +} diff --git a/tools/importer-msgraph-metadata/components/workarounds/workarounds.go b/tools/importer-msgraph-metadata/components/workarounds/workarounds.go index 83a67821a4d..c1d7dd61929 100644 --- a/tools/importer-msgraph-metadata/components/workarounds/workarounds.go +++ b/tools/importer-msgraph-metadata/components/workarounds/workarounds.go @@ -32,6 +32,7 @@ var serviceWorkarounds = []serviceWorkaround{ workaroundBlacklist{}, // Service-specific workarounds + workaroundAdministrativeUnits{}, workaroundApplicationTemplates{}, workaroundEntitlementManagementAccessPackageAccessPackageResourceRoleScope{}, workaroundEntitlementManagementRoleAssignment{},