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

New Data Source: azurerm_app_service #1071

Merged
merged 4 commits into from
Apr 5, 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
291 changes: 291 additions & 0 deletions azurerm/data_source_app_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
package azurerm

import (
"fmt"
"log"

"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmAppService() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmAppServiceRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"resource_group_name": resourceGroupNameDiffSuppressSchema(),

"location": locationForDataSourceSchema(),

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

"site_config": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"always_on": {
Type: schema.TypeBool,
Computed: true,
},

"default_documents": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

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

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

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

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

"local_mysql_enabled": {
Type: schema.TypeBool,
Computed: true,
},

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

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

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

"remote_debugging_enabled": {
Type: schema.TypeBool,
Computed: true,
},

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

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

"use_32_bit_worker_process": {
Type: schema.TypeBool,
Computed: true,
},

"websockets_enabled": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},

"client_affinity_enabled": {
Type: schema.TypeBool,
Computed: true,
},

"enabled": {
Type: schema.TypeBool,
Computed: true,
},

"app_settings": {
Type: schema.TypeMap,
Computed: true,
},

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

"tags": tagsForDataSourceSchema(),

"site_credential": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"username": {
Type: schema.TypeString,
Computed: true,
},
"password": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
},
},
},

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

"outbound_ip_addresses": {
Type: schema.TypeString,
Computed: true,
},
"source_control": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"repo_url": {
Type: schema.TypeString,
Computed: true,
},
"branch": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}
func dataSourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appServicesClient

resourceGroup := d.Get("resource_group_name").(string)
name := d.Get("name").(string)

ctx := meta.(*ArmClient).StopContext
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
log.Printf("[DEBUG] App Service %q (resource group %q) was not found - removing from state", name, resourceGroup)
d.SetId("")
return nil
}
return fmt.Errorf("Error making Read request on AzureRM App Service %q: %+v", name, err)
}

configResp, err := client.GetConfiguration(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error making Read request on AzureRM App Service Configuration %q: %+v", name, err)
}

appSettingsResp, err := client.ListApplicationSettings(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error making Read request on AzureRM App Service AppSettings %q: %+v", name, err)
}

connectionStringsResp, err := client.ListConnectionStrings(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error making Read request on AzureRM App Service ConnectionStrings %q: %+v", name, err)
}

scmResp, err := client.GetSourceControl(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("Error making Read request on AzureRM App Service Source Control %q: %+v", name, err)
}

siteCredFuture, err := client.ListPublishingCredentials(ctx, resourceGroup, 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.SetId(*resp.ID)

d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
if location := resp.Location; location != nil {
d.Set("location", azureRMNormalizeLocation(*location))
}

if props := resp.SiteProperties; props != nil {
d.Set("app_service_plan_id", props.ServerFarmID)
d.Set("client_affinity_enabled", props.ClientAffinityEnabled)
d.Set("enabled", props.Enabled)
d.Set("default_site_hostname", props.DefaultHostName)
d.Set("outbound_ip_addresses", props.OutboundIPAddresses)
}

if err := d.Set("app_settings", flattenAppServiceAppSettings(appSettingsResp.Properties)); err != nil {
return err
}
if err := d.Set("connection_string", flattenAppServiceConnectionStrings(connectionStringsResp.Properties)); err != nil {
return err
}

siteConfig := flattenAppServiceSiteConfig(configResp.SiteConfig)
if err := d.Set("site_config", siteConfig); err != nil {
return err
}

scm := flattenAppServiceSourceControl(scmResp.SiteSourceControlProperties)
if err := d.Set("source_control", scm); err != nil {
return err
}

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

flattenAndSetTags(d, resp.Tags)

return nil
}
Loading