Skip to content

Commit

Permalink
fix: handling of default azure tenant_type
Browse files Browse the repository at this point in the history
fix: handling of default azure tenant_type
  • Loading branch information
stebenz authored Sep 6, 2023
2 parents 28d61ea + 51fd727 commit 1f6c5a8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
14 changes: 12 additions & 2 deletions zitadel/idp_azure_ad/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagn
cfg := respIdp.GetConfig()
specificCfg := cfg.GetAzureAd()
generalCfg := cfg.GetOptions()
tenantID := specificCfg.GetTenant().GetTenantId()
set := map[string]interface{}{
idp_utils.NameVar: respIdp.GetName(),
idp_utils.ClientIDVar: specificCfg.GetClientId(),
Expand All @@ -102,9 +103,15 @@ func read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagn
idp_utils.IsAutoCreationVar: generalCfg.GetIsAutoCreation(),
idp_utils.IsAutoUpdateVar: generalCfg.GetIsAutoUpdate(),
EmailVerifiedVar: specificCfg.GetEmailVerified(),
TenantTypeVar: idp.AzureADTenantType_name[int32(specificCfg.GetTenant().GetTenantType())],
TenantIDVar: specificCfg.GetTenant().GetTenantId(),
TenantIDVar: tenantID,
}

if tenantID == "" {
set[TenantTypeVar] = idp.AzureADTenantType_name[int32(specificCfg.GetTenant().GetTenantType())]
} else {
set[TenantTypeVar] = ""
}

for k, v := range set {
if err := d.Set(k, v); err != nil {
return diag.Errorf("failed to set %s of oidc idp: %v", k, err)
Expand All @@ -118,6 +125,9 @@ func ConstructTenant(d *schema.ResourceData) (*idp.AzureADTenant, error) {
tenant := &idp.AzureADTenant{}
tenantId := idp_utils.StringValue(d, TenantIDVar)
tenantType := idp_utils.StringValue(d, TenantTypeVar)
if tenantId == "" && tenantType == "" {
return nil, fmt.Errorf("tenant_id or tenant_type are required, but both were empty")
}
if tenantId != "" && tenantType != "" {
return nil, fmt.Errorf("tenant_id and tenant_type are mutually exclusive, but got id %s and type %s", tenantId, tenantType)
}
Expand Down
1 change: 0 additions & 1 deletion zitadel/idp_azure_ad/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var (
TenantTypeResourceField = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: idp.AzureADTenantType_name[0],
Description: "the azure ad tenant type",
ValidateDiagFunc: func(value interface{}, path cty.Path) diag.Diagnostics {
return helper.EnumValueValidation(TenantTypeVar, value, idp.AzureADTenantType_value)
Expand Down
10 changes: 8 additions & 2 deletions zitadel/org_idp_azure_ad/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagn
cfg := respIdp.GetConfig()
specificCfg := cfg.GetAzureAd()
generalCfg := cfg.GetOptions()
tenantID := specificCfg.GetTenant().GetTenantId()
set := map[string]interface{}{
helper.OrgIDVar: respIdp.GetDetails().GetResourceOwner(),
idp_utils.NameVar: respIdp.GetName(),
Expand All @@ -103,8 +104,13 @@ func read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagn
idp_utils.IsAutoCreationVar: generalCfg.GetIsAutoCreation(),
idp_utils.IsAutoUpdateVar: generalCfg.GetIsAutoUpdate(),
idp_azure_ad.EmailVerifiedVar: specificCfg.GetEmailVerified(),
idp_azure_ad.TenantTypeVar: idp.AzureADTenantType_name[int32(specificCfg.GetTenant().GetTenantType())],
idp_azure_ad.TenantIDVar: specificCfg.GetTenant().GetTenantId(),
idp_azure_ad.TenantIDVar: tenantID,
}

if tenantID == "" {
set[idp_azure_ad.TenantTypeVar] = idp.AzureADTenantType_name[int32(specificCfg.GetTenant().GetTenantType())]
} else {
set[idp_azure_ad.TenantTypeVar] = ""
}
for k, v := range set {
if err := d.Set(k, v); err != nil {
Expand Down

0 comments on commit 1f6c5a8

Please sign in to comment.