-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Data Source:
azurerm_app_service
(#1071)
* New Data Source: `azurerm_app_service` ``` $ acctests azurerm TestAccDataSourceAzureRMAppService_ === RUN TestAccDataSourceAzureRMAppService_basic --- PASS: TestAccDataSourceAzureRMAppService_basic (253.82s) === RUN TestAccDataSourceAzureRMAppService_tags --- PASS: TestAccDataSourceAzureRMAppService_tags (111.16s) === RUN TestAccDataSourceAzureRMAppService_clientAppAffinityDisabled --- PASS: TestAccDataSourceAzureRMAppService_clientAppAffinityDisabled (103.34s) === RUN TestAccDataSourceAzureRMAppService_siteConfig --- PASS: TestAccDataSourceAzureRMAppService_siteConfig (107.17s) === RUN TestAccDataSourceAzureRMAppService_appSettings --- PASS: TestAccDataSourceAzureRMAppService_appSettings (143.14s) === RUN TestAccDataSourceAzureRMAppService_connectionString --- PASS: TestAccDataSourceAzureRMAppService_connectionString (125.71s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 844.388s ``` * Sorting the app service fields by name * Updating the tone of language to match a data source * Updating the Data Source test to match the name of the Resource test
- Loading branch information
1 parent
0b5f3b3
commit 657679c
Showing
8 changed files
with
603 additions
and
13 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
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 | ||
} |
Oops, something went wrong.