Skip to content

Commit

Permalink
fix: use identifier_uri instead of identifier_uris for lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasBak committed May 13, 2024
1 parent cc07f66 commit 11e677b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/data-sources/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ The following arguments are supported:
* `client_id` - (Optional) Specifies the Client ID of the application.
* `display_name` - (Optional) Specifies the display name of the application.
* `object_id` - (Optional) Specifies the Object ID of the application.
* `identifier_uris` - (Optional) Specifies a list containing one identifying URI of the application.
* `identifier_uri` - (Optional) Specifies a identifying URI of the application. This should only be used for lookups, `identifier_uris` should be used to read identifier URIs.

~> One of `client_id`, `display_name`, `object_id`, or `identifier_uris` must be specified.
~> One of `client_id`, `display_name`, `object_id`, or `identifier_uri` must be specified.

## Attributes Reference

Expand Down
28 changes: 16 additions & 12 deletions internal/services/applications/application_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func applicationDataSource() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ExactlyOneOf: []string{"application_id", "client_id", "display_name", "object_id", "identifier_uris"},
ExactlyOneOf: []string{"application_id", "client_id", "display_name", "object_id", "identifier_uri"},
ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID),
},

Expand All @@ -43,7 +43,7 @@ func applicationDataSource() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ExactlyOneOf: []string{"application_id", "client_id", "display_name", "object_id", "identifier_uris"},
ExactlyOneOf: []string{"application_id", "client_id", "display_name", "object_id", "identifier_uri"},
ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID),
Deprecated: "The `application_id` property has been replaced with the `client_id` property and will be removed in version 3.0 of the AzureAD provider",
},
Expand All @@ -53,10 +53,19 @@ func applicationDataSource() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ExactlyOneOf: []string{"application_id", "client_id", "display_name", "object_id", "identifier_uris"},
ExactlyOneOf: []string{"application_id", "client_id", "display_name", "object_id", "identifier_uri"},
ValidateDiagFunc: validation.ValidateDiag(validation.IsUUID),
},

"identifier_uri": {
Description: "One of the application's identifier URIs",
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ExactlyOneOf: []string{"application_id", "client_id", "display_name", "object_id", "identifier_uri"},
ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty),
},

"disabled_by_microsoft": {
Description: "Whether Microsoft has disabled the registered application",
Type: pluginsdk.TypeString,
Expand All @@ -68,7 +77,7 @@ func applicationDataSource() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ExactlyOneOf: []string{"application_id", "client_id", "display_name", "object_id", "identifier_uris"},
ExactlyOneOf: []string{"application_id", "client_id", "display_name", "object_id", "identifier_uri"},
ValidateDiagFunc: validation.ValidateDiag(validation.StringIsNotEmpty),
},

Expand Down Expand Up @@ -279,12 +288,10 @@ func applicationDataSource() *pluginsdk.Resource {
"identifier_uris": {
Description: "A list of user-defined URI(s) that uniquely identify a Web application within it's Azure AD tenant, or within a verified custom domain if the application is multi-tenant",
Type: pluginsdk.TypeList,
Optional: true,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
ExactlyOneOf: []string{"application_id", "client_id", "display_name", "object_id", "identifier_uris"},
},

"logo_url": {
Expand Down Expand Up @@ -537,15 +544,12 @@ func applicationDataSourceRead(ctx context.Context, d *pluginsdk.ResourceData, m
} else if displayName, ok := d.Get("display_name").(string); ok && displayName != "" {
fieldName = "displayName"
fieldValue = displayName
} else if identifier_uris, ok := d.Get("identifier_uris").([]interface{}); ok && len(identifier_uris) > 0 {
if len(identifier_uris) != 1 {
return tf.ErrorDiagF(nil, "When specifying `identifier_uris` in data source, exactly one uri should be provided")
}
} else if identifierUri, ok := d.Get("identifier_uri").(string); ok {
fieldName = "IdentifierUris"
fieldValue = identifier_uris[0].(string)
fieldValue = identifierUri
filterOp = "%s/any(uri:uri eq '%s')"
} else {
return tf.ErrorDiagF(nil, "One of `object_id`, `application_id`, `client_id`, `displayName`, or `identifier_uris` must be specified")
return tf.ErrorDiagF(nil, "One of `object_id`, `application_id`, `client_id`, `displayName`, or `identifier_uri` must be specified")
}

filter := fmt.Sprintf(filterOp, fieldName, fieldValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ func TestAccApplicationDataSource_byDisplayName(t *testing.T) {
})
}

func TestAccApplicationDataSource_byIdentifierUris(t *testing.T) {
func TestAccApplicationDataSource_byIdentifierUri(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azuread_application", "test")
r := ApplicationDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: r.identifierUris(data),
Config: r.identifierUri(data),
Check: r.testCheck(data),
},
})
Expand Down Expand Up @@ -143,12 +143,12 @@ data "azuread_application" "test" {
`, ApplicationResource{}.complete(data))
}

func (ApplicationDataSource) identifierUris(data acceptance.TestData) string {
func (ApplicationDataSource) identifierUri(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
data "azuread_application" "test" {
identifier_uris = [tolist(azuread_application.test.identifier_uris)[0]]
identifier_uri = tolist(azuread_application.test.identifier_uris)[0]
}
`, ApplicationResource{}.complete(data))
}

0 comments on commit 11e677b

Please sign in to comment.