in internal/services/azapi_resource_data_source.go [181:212]
func (r *AzapiResourceDataSource) ValidateConfig(ctx context.Context, request datasource.ValidateConfigRequest, response *datasource.ValidateConfigResponse) {
var config *AzapiResourceDataSourceModel
if response.Diagnostics.Append(request.Config.Get(ctx, &config)...); response.Diagnostics.HasError() {
return
}
if config == nil {
return
}
if config.Name.IsNull() && !config.ParentID.IsNull() {
response.Diagnostics.AddError("Invalid configuration", `The argument "name" is required when the argument "parent_id" is set`)
}
if !config.Name.IsNull() && config.ParentID.IsNull() {
resourceType := config.Type.ValueString()
azureResourceType, _, _ := utils.GetAzureResourceTypeApiVersion(resourceType)
// If the resource type is not a resource group, then the parent_id is required
if !strings.EqualFold(azureResourceType, arm.ResourceGroupResourceType.String()) {
response.Diagnostics.AddError("Invalid configuration", `The argument "parent_id" is required when the argument "name" is set`)
}
}
if config.Name.IsNull() && config.ResourceID.IsNull() {
resourceType := config.Type.ValueString()
azureResourceType, _, _ := utils.GetAzureResourceTypeApiVersion(resourceType)
// If the resource type is not a subscription, then at least one of the name or resource_id must be set
if !strings.EqualFold(azureResourceType, arm.SubscriptionResourceType.String()) {
response.Diagnostics.AddError("Invalid configuration", `One of the arguments "name" or "resource_id" must be set`)
}
}
if !config.Name.IsNull() && !config.ResourceID.IsNull() {
response.Diagnostics.AddError("Invalid configuration", `Exactly one of the arguments "name" or "resource_id" can be set`)
}
}