-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New resource and data source: azurerm_aadb2c_directory
- Loading branch information
1 parent
4d6aa89
commit f6e6a3d
Showing
40 changed files
with
2,865 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
internal/services/aadb2c/aadb2c_directory_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
package aadb2c | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/services/aadb2c/sdk/2021-04-01-preview/tenants" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/services/aadb2c/validate" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tags" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" | ||
) | ||
|
||
type AadB2cDirectoryDataSourceModel struct { | ||
BillingType string `tfschema:"billing_type"` | ||
DataResidencyLocation string `tfschema:"data_residency_location"` | ||
DomainName string `tfschema:"domain_name"` | ||
EffectiveStartDate string `tfschema:"effective_start_date"` | ||
ResourceGroup string `tfschema:"resource_group_name"` | ||
Sku string `tfschema:"sku_name"` | ||
Tags map[string]string `tfschema:"tags"` | ||
TenantId string `tfschema:"tenant_id"` | ||
} | ||
|
||
type AadB2cDirectoryDataSource struct{} | ||
|
||
var _ sdk.DataSource = AadB2cDirectoryDataSource{} | ||
|
||
func (r AadB2cDirectoryDataSource) ResourceType() string { | ||
return "azurerm_aadb2c_directory" | ||
} | ||
|
||
func (r AadB2cDirectoryDataSource) ModelObject() interface{} { | ||
return &AadB2cDirectoryModel{} | ||
} | ||
|
||
func (r AadB2cDirectoryDataSource) IDValidationFunc() pluginsdk.SchemaValidateFunc { | ||
return validate.B2CDirectoryID | ||
} | ||
|
||
func (r AadB2cDirectoryDataSource) Arguments() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"domain_name": { | ||
Description: "Domain name of the B2C tenant, including onmicrosoft.com suffix.", | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(), | ||
} | ||
} | ||
|
||
func (r AadB2cDirectoryDataSource) Attributes() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"billing_type": { | ||
Description: "The type of billing for the B2C tenant. Possible values include: `MAU` or `Auths`.", | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"data_residency_location": { | ||
Description: "Location in which the B2C tenant is hosted and data resides.", | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"effective_start_date": { | ||
Description: "The date from which the billing type took effect. May not be populated until after the first billing cycle.", | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"tenant_id": { | ||
Description: "The Tenant ID for the B2C tenant.", | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"sku_name": { | ||
Description: "Billing SKU for the B2C tenant.", | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"tags": tags.SchemaDataSource(), | ||
} | ||
} | ||
|
||
func (r AadB2cDirectoryDataSource) Read() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{ | ||
Timeout: 5 * time.Minute, | ||
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
client := metadata.Client.AadB2c.TenantsClient | ||
subscriptionId := metadata.Client.Account.SubscriptionId | ||
|
||
var state AadB2cDirectoryDataSourceModel | ||
if err := metadata.Decode(&state); err != nil { | ||
return fmt.Errorf("decoding: %+v", err) | ||
} | ||
|
||
id := tenants.NewB2CDirectoryID(subscriptionId, state.ResourceGroup, state.DomainName) | ||
|
||
metadata.Logger.Infof("Reading %s", id) | ||
resp, err := client.Get(ctx, id) | ||
if err != nil { | ||
if resp.HttpResponse.StatusCode == http.StatusNotFound { | ||
return metadata.MarkAsGone(id) | ||
} | ||
return fmt.Errorf("retrieving %s: %v", id, err) | ||
} | ||
|
||
model := resp.Model | ||
if model == nil { | ||
return fmt.Errorf("retrieving %s: model was nil", id) | ||
} | ||
|
||
state.DomainName = id.DirectoryName | ||
state.ResourceGroup = id.ResourceGroup | ||
|
||
if model.Location != nil { | ||
state.DataResidencyLocation = string(*model.Location) | ||
} | ||
|
||
if model.Sku != nil { | ||
state.Sku = string(model.Sku.Name) | ||
} | ||
|
||
if model.Tags != nil { | ||
state.Tags = *model.Tags | ||
} | ||
|
||
if properties := model.Properties; properties != nil { | ||
if billingConfig := properties.BillingConfig; billingConfig != nil { | ||
if billingConfig.BillingType != nil { | ||
state.BillingType = string(*billingConfig.BillingType) | ||
} | ||
if billingConfig.EffectiveStartDateUtc != nil { | ||
state.EffectiveStartDate = *billingConfig.EffectiveStartDateUtc | ||
} | ||
} | ||
|
||
if properties.TenantId != nil { | ||
state.TenantId = *properties.TenantId | ||
} | ||
} | ||
|
||
metadata.SetID(id) | ||
|
||
return metadata.Encode(&state) | ||
}, | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
internal/services/aadb2c/aadb2c_directory_data_source_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package aadb2c_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" | ||
) | ||
|
||
type AadB2cDirectoryDataSource struct{} | ||
|
||
func TestAccAadB2cDirectoryDataSource_basic(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "data.azurerm_aadb2c_directory", "test") | ||
d := AadB2cDirectoryDataSource{} | ||
|
||
data.DataSourceTest(t, []acceptance.TestStep{ | ||
{ | ||
Config: d.basic(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).Key("data_residency_location").HasValue("United States"), | ||
check.That(data.ResourceName).Key("sku_name").HasValue("PremiumP1"), | ||
), | ||
}, | ||
}) | ||
} | ||
|
||
func (d AadB2cDirectoryDataSource) basic(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
data "azurerm_aadb2c_directory" "test" { | ||
domain_name = azurerm_aadb2c_directory.test.domain_name | ||
resource_group_name = azurerm_aadb2c_directory.test.resource_group_name | ||
} | ||
`, AadB2cDirectoryResource{}.basic(data)) | ||
} |
Oops, something went wrong.