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

resource/function_app: Add support for outputting site_credentials #1567

Merged
merged 1 commit into from
Jul 15, 2018
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
57 changes: 57 additions & 0 deletions azurerm/resource_arm_function_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,25 @@ func resourceArmFunctionApp() *schema.Resource {
},
},
},

"site_credential": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"username": {
Type: schema.TypeString,
Computed: true,
},
"password": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -381,6 +400,19 @@ func resourceArmFunctionAppRead(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("Error making Read request on AzureRM Function App ConnectionStrings %q: %+v", name, err)
}

siteCredFuture, err := client.ListPublishingCredentials(ctx, resGroup, name)
if err != nil {
return err
}
err = siteCredFuture.WaitForCompletion(ctx, client.Client)
if err != nil {
return err
}
siteCredResp, err := siteCredFuture.Result(client)
if err != nil {
return fmt.Errorf("Error making Read request on AzureRM App Service Site Credential %q: %+v", name, err)
}

d.Set("name", name)
d.Set("resource_group_name", resGroup)
if location := resp.Location; location != nil {
Expand Down Expand Up @@ -428,6 +460,11 @@ func resourceArmFunctionAppRead(d *schema.ResourceData, meta interface{}) error
return err
}

siteCred := flattenFunctionAppSiteCredential(siteCredResp.UserProperties)
if err := d.Set("site_credential", siteCred); err != nil {
return err
}

flattenAndSetTags(d, resp.Tags)

return nil
Expand Down Expand Up @@ -590,3 +627,23 @@ func flattenFunctionAppIdentity(identity *web.ManagedServiceIdentity) interface{

return []interface{}{result}
}

func flattenFunctionAppSiteCredential(input *web.UserProperties) []interface{} {
results := make([]interface{}, 0)
result := make(map[string]interface{}, 0)

if input == nil {
log.Printf("[DEBUG] UserProperties is nil")
return results
}

if input.PublishingUserName != nil {
result["username"] = *input.PublishingUserName
}

if input.PublishingPassword != nil {
result["password"] = *input.PublishingPassword
}

return append(results, result)
}
1 change: 1 addition & 0 deletions azurerm/resource_arm_function_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func TestAccAzureRMFunctionApp_appSettings(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMFunctionAppExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "app_settings.%", "0"),
resource.TestCheckResourceAttr(resourceName, "site_credential.#", "1"),
),
},
{
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/function_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ The following attributes are exported:

* `identity` - An `identity` block as defined below, which contains the Managed Service Identity information for this App Service.

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

---

`identity` exports the following:
Expand All @@ -162,6 +164,12 @@ The following attributes are exported:
* `tenant_id` - The Tenant ID for the Service Principal associated with the Managed Service Identity of this App Service.


`site_credential` exports the following:

* `username` - The username which can be used to publish to this App Service
* `password` - The password associated with the username, which can be used to publish to this App Service.


## Import

Function Apps can be imported using the `resource id`, e.g.
Expand Down