Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data.function_app - export the identity block #8389

Merged
merged 3 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions azurerm/internal/services/web/data_source_function_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,29 @@ func dataSourceArmFunctionApp() *schema.Resource {

"source_control": schemaDataSourceAppServiceSiteSourceControl(),

"identity": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Computed: true,
},

"principal_id": {
Type: schema.TypeString,
Computed: true,
},

"tenant_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"tags": tags.Schema(),
},
}
Expand Down Expand Up @@ -204,6 +227,10 @@ func dataSourceArmFunctionAppRead(d *schema.ResourceData, meta interface{}) erro
return err
}

if err := d.Set("identity", flattenFunctionAppIdentity(resp.Identity)); err != nil {
return fmt.Errorf("setting `identity`: %+v", err)
}

siteCred := flattenFunctionAppSiteCredential(siteCredResp.UserProperties)
if err = d.Set("site_credential", siteCred); err != nil {
return err
Expand Down
24 changes: 24 additions & 0 deletions azurerm/internal/services/web/function_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,27 @@ func flattenFunctionAppSiteCredential(input *web.UserProperties) []interface{} {

return append(results, result)
}

func flattenFunctionAppIdentity(input *web.ManagedServiceIdentity) []interface{} {
if input == nil {
return []interface{}{}
}

principalID := ""
if input.PrincipalID != nil {
principalID = *input.PrincipalID
}

tenantID := ""
if input.TenantID != nil {
tenantID = *input.TenantID
}

return []interface{}{
map[string]interface{}{
"type": string(input.Type),
"principal_id": principalID,
"tenant_id": tenantID,
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func TestAccAzureRMFunctionApp_basic(t *testing.T) {
resource.TestCheckResourceAttr(data.ResourceName, "version", "~1"),
resource.TestCheckResourceAttrSet(data.ResourceName, "outbound_ip_addresses"),
resource.TestCheckResourceAttrSet(data.ResourceName, "possible_outbound_ip_addresses"),
resource.TestCheckResourceAttr(data.ResourceName, "identity.#", "1"),
resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"),
resource.TestCheckResourceAttrSet(data.ResourceName, "identity.0.principal_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "identity.0.tenant_id"),
),
},
data.ImportStep(),
Expand Down
11 changes: 11 additions & 0 deletions website/docs/d/function_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ The following attributes are exported:

* `enabled` - Is the Function App enabled?

* `identity` - A `identity` block as defined below.

* `site_credential` - A `site_credential` block as defined below, which contains the site-level credentials used to publish to this App Service.

* `os_type` - A string indicating the Operating System type for this function app.
Expand Down Expand Up @@ -142,6 +144,15 @@ A `source_control` block exports the following:

* `use_mercurial` - Uses Mercurial if `true`, otherwise uses Git.

---

An `identity` block exports the following:

* `principal_id` - The ID of the System Managed Service Principal assigned to the function app.

* `tenant_id` - The ID of the Tenant of the System Managed Service Principal assigned to the function app.

* `type` - The identity type of the Managed Identity assigned to the function app.

## Timeouts

Expand Down