forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'api-management' into api-management-api
* api-management: Updating to include hashicorp#1565 resource/servicebus_subscription_rule: Fix the correlation_filter optional values (hashicorp#1565) Updating to include hashicorp#1563 resouce/app_insights: Allow different application_type deployments (hashicorp#1563) VMSS: changed sku property from a set to list Update CHANGELOG.md to include hashicorp#1552 Renamed azurerm_azuread_application.html.markdown to azuread_application.html.markdown New Data Source: `azurerm_azuread_application` VMSS: Updating the code samples to be valid. Fixes hashicorp#1539 (hashicorp#1549) Creation Data -> Creation Date (hashicorp#1548) Updating to include hashicorp#1546 Workaround upstream issue in creating azureEndpoints in traffic manager (hashicorp#1546) Cleanup after v1.9.0 release v1.9.0 Updating to include hashicorp#1269 New Resource: `azurerm_azuread_application` (hashicorp#1269) Remove tags validate in preConfig of TestAccAzureRMKeyVault_update (hashicorp#1534) Updating to include hashicorp#1535 `azurerm_key_vault_key` - handling the parent Key Vault being deleted (hashicorp#1535)
- Loading branch information
Showing
27 changed files
with
1,383 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceArmAzureADApplication() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmAzureADApplicationRead, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
// TODO: customizeDiff for validation of either name or object_id. | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"object_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ConflictsWith: []string{"name"}, | ||
}, | ||
|
||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ConflictsWith: []string{"object_id"}, | ||
}, | ||
|
||
"homepage": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"identifier_uris": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
|
||
"reply_urls": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
|
||
"available_to_other_tenants": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
|
||
"oauth2_allow_implicit_flow": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
|
||
"application_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmAzureADApplicationRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).applicationsClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
var application graphrbac.Application | ||
|
||
if oId, ok := d.GetOk("object_id"); ok { | ||
objectId := oId.(string) | ||
resp, err := client.Get(ctx, objectId) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Error: AzureAD Application with ID %q was not found", objectId) | ||
} | ||
|
||
return fmt.Errorf("Error making Read request on AzureAD Application with ID %q: %+v", objectId, err) | ||
} | ||
|
||
application = resp | ||
} else { | ||
resp, err := client.ListComplete(ctx, "") | ||
if err != nil { | ||
return fmt.Errorf("Error listing Azure AD Applications: %+v", err) | ||
} | ||
|
||
name := d.Get("name").(string) | ||
|
||
var app *graphrbac.Application | ||
for _, v := range *resp.Response().Value { | ||
if v.DisplayName != nil { | ||
if *v.DisplayName == name { | ||
app = &v | ||
break | ||
} | ||
} | ||
} | ||
|
||
if app == nil { | ||
return fmt.Errorf("Couldn't locate an Azure AD Application with a name of %q", name) | ||
} | ||
|
||
application = *app | ||
} | ||
|
||
d.SetId(*application.ObjectID) | ||
|
||
d.Set("object_id", application.ObjectID) | ||
d.Set("name", application.DisplayName) | ||
d.Set("application_id", application.AppID) | ||
d.Set("homepage", application.Homepage) | ||
d.Set("available_to_other_tenants", application.AvailableToOtherTenants) | ||
d.Set("oauth2_allow_implicit_flow", application.Oauth2AllowImplicitFlow) | ||
|
||
identifierUris := flattenAzureADDataSourceApplicationIdentifierUris(application.IdentifierUris) | ||
if err := d.Set("identifier_uris", identifierUris); err != nil { | ||
return fmt.Errorf("Error setting `identifier_uris`: %+v", err) | ||
} | ||
|
||
replyUrls := flattenAzureADDataSourceApplicationReplyUrls(application.ReplyUrls) | ||
if err := d.Set("reply_urls", replyUrls); err != nil { | ||
return fmt.Errorf("Error setting `reply_urls`: %+v", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func flattenAzureADDataSourceApplicationIdentifierUris(input *[]string) []string { | ||
output := make([]string, 0) | ||
|
||
if input != nil { | ||
for _, v := range *input { | ||
output = append(output, v) | ||
} | ||
} | ||
|
||
return output | ||
} | ||
|
||
func flattenAzureADDataSourceApplicationReplyUrls(input *[]string) []string { | ||
output := make([]string, 0) | ||
|
||
if input != nil { | ||
for _, v := range *input { | ||
output = append(output, v) | ||
} | ||
} | ||
|
||
return output | ||
} |
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,123 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAzureRMAzureADApplication_byObjectId(t *testing.T) { | ||
dataSourceName := "data.azurerm_azuread_application.test" | ||
id := uuid.New().String() | ||
config := testAccDataSourceAzureRMAzureADApplication_objectId(id) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMActiveDirectoryApplicationDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMActiveDirectoryApplicationExists(dataSourceName), | ||
resource.TestCheckResourceAttr(dataSourceName, "name", fmt.Sprintf("acctest%s", id)), | ||
resource.TestCheckResourceAttr(dataSourceName, "homepage", fmt.Sprintf("http://acctest%s", id)), | ||
resource.TestCheckResourceAttr(dataSourceName, "identifier_uris.#", "0"), | ||
resource.TestCheckResourceAttr(dataSourceName, "reply_urls.#", "0"), | ||
resource.TestCheckResourceAttr(dataSourceName, "oauth2_allow_implicit_flow", "false"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "application_id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceAzureRMAzureADApplication_byObjectIdComplete(t *testing.T) { | ||
dataSourceName := "data.azurerm_azuread_application.test" | ||
id := uuid.New().String() | ||
config := testAccDataSourceAzureRMAzureADApplication_objectIdComplete(id) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMActiveDirectoryApplicationDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMActiveDirectoryApplicationExists(dataSourceName), | ||
resource.TestCheckResourceAttr(dataSourceName, "name", fmt.Sprintf("acctest%s", id)), | ||
resource.TestCheckResourceAttr(dataSourceName, "homepage", fmt.Sprintf("http://homepage-%s", id)), | ||
resource.TestCheckResourceAttr(dataSourceName, "identifier_uris.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "reply_urls.#", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "oauth2_allow_implicit_flow", "true"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "application_id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceAzureRMAzureADApplication_byName(t *testing.T) { | ||
dataSourceName := "data.azurerm_azuread_application.test" | ||
id := uuid.New().String() | ||
config := testAccDataSourceAzureRMAzureADApplication_name(id) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMActiveDirectoryApplicationDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAzureRMActiveDirectoryApplication_basic(id), | ||
}, | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMActiveDirectoryApplicationExists(dataSourceName), | ||
resource.TestCheckResourceAttr(dataSourceName, "name", fmt.Sprintf("acctest%s", id)), | ||
resource.TestCheckResourceAttr(dataSourceName, "homepage", fmt.Sprintf("http://acctest%s", id)), | ||
resource.TestCheckResourceAttr(dataSourceName, "identifier_uris.#", "0"), | ||
resource.TestCheckResourceAttr(dataSourceName, "reply_urls.#", "0"), | ||
resource.TestCheckResourceAttr(dataSourceName, "oauth2_allow_implicit_flow", "false"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "application_id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAzureRMAzureADApplication_objectId(id string) string { | ||
template := testAccAzureRMActiveDirectoryApplication_basic(id) | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_azuread_application" "test" { | ||
object_id = "${azurerm_azuread_application.test.id}" | ||
} | ||
`, template) | ||
} | ||
|
||
func testAccDataSourceAzureRMAzureADApplication_objectIdComplete(id string) string { | ||
template := testAccAzureRMActiveDirectoryApplication_complete(id) | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_azuread_application" "test" { | ||
object_id = "${azurerm_azuread_application.test.id}" | ||
} | ||
`, template) | ||
} | ||
|
||
func testAccDataSourceAzureRMAzureADApplication_name(id string) string { | ||
template := testAccAzureRMActiveDirectoryApplication_basic(id) | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_azuread_application" "test" { | ||
name = "${azurerm_azuread_application.test.name}" | ||
} | ||
`, template) | ||
} |
Oops, something went wrong.