-
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.
Merge remote-tracking branch 'origin/master' into automationresources
- Loading branch information
Showing
446 changed files
with
96,512 additions
and
1,734 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 |
---|---|---|
|
@@ -33,3 +33,6 @@ website/vendor | |
!command/test-fixtures/**/.terraform/ | ||
|
||
.env.sh | ||
|
||
# goenv version file | ||
.go-version |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,16 @@ | ||
package azurerm | ||
|
||
import "testing" | ||
|
||
func TestClientRequestID(t *testing.T) { | ||
first := clientRequestID() | ||
|
||
if first == "" { | ||
t.Fatal("no client request ID generated") | ||
} | ||
|
||
second := clientRequestID() | ||
if first != second { | ||
t.Fatal("subsequent request ID not the same as the first") | ||
} | ||
} |
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,336 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/preview/apimanagement/mgmt/2018-06-01-preview/apimanagement" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceApiManagementService() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceApiManagementRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validate.ApiManagementServiceName, | ||
}, | ||
|
||
"resource_group_name": resourceGroupNameForDataSourceSchema(), | ||
|
||
"location": locationForDataSourceSchema(), | ||
|
||
"publisher_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"publisher_email": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"sku": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"capacity": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"notification_sender_email": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"gateway_url": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"gateway_regional_url": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"portal_url": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"management_api_url": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"scm_url": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"additional_location": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"location": locationForDataSourceSchema(), | ||
|
||
"gateway_regional_url": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"public_ip_addresses": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"hostname_configuration": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"management": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: apiManagementDataSourceHostnameSchema(), | ||
}, | ||
}, | ||
"portal": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: apiManagementDataSourceHostnameSchema(), | ||
}, | ||
}, | ||
"proxy": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: apiManagementDataSourceHostnameProxySchema(), | ||
}, | ||
}, | ||
"scm": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: apiManagementDataSourceHostnameSchema(), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"tags": tagsForDataSourceSchema(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceApiManagementRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).apiManagementServiceClient | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
ctx := meta.(*ArmClient).StopContext | ||
resp, err := client.Get(ctx, resourceGroup, name) | ||
|
||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("API Management Service %q (Resource Group %q) was not found", name, resourceGroup) | ||
} | ||
|
||
return fmt.Errorf("Error retrieving API Management Service %q (Resource Group %q): %+v", name, resourceGroup, 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.ServiceProperties; props != nil { | ||
d.Set("publisher_email", props.PublisherEmail) | ||
d.Set("publisher_name", props.PublisherName) | ||
|
||
d.Set("notification_sender_email", props.NotificationSenderEmail) | ||
d.Set("gateway_url", props.GatewayURL) | ||
d.Set("gateway_regional_url", props.GatewayRegionalURL) | ||
d.Set("portal_url", props.PortalURL) | ||
d.Set("management_api_url", props.ManagementAPIURL) | ||
d.Set("scm_url", props.ScmURL) | ||
d.Set("public_ip_addresses", props.PublicIPAddresses) | ||
|
||
if err := d.Set("hostname_configuration", flattenDataSourceApiManagementHostnameConfigurations(props.HostnameConfigurations)); err != nil { | ||
return fmt.Errorf("Error setting `hostname_configuration`: %+v", err) | ||
} | ||
|
||
if err := d.Set("additional_location", flattenDataSourceApiManagementAdditionalLocations(props.AdditionalLocations)); err != nil { | ||
return fmt.Errorf("Error setting `additional_location`: %+v", err) | ||
} | ||
} | ||
|
||
if err := d.Set("sku", flattenDataSourceApiManagementServiceSku(resp.Sku)); err != nil { | ||
return fmt.Errorf("Error flattening `sku`: %+v", err) | ||
} | ||
|
||
flattenAndSetTags(d, resp.Tags) | ||
|
||
return nil | ||
} | ||
|
||
func flattenDataSourceApiManagementHostnameConfigurations(input *[]apimanagement.HostnameConfiguration) []interface{} { | ||
if input == nil { | ||
return []interface{}{} | ||
} | ||
|
||
// management, portal, proxy, scm | ||
managementResults := make([]interface{}, 0) | ||
proxyResults := make([]interface{}, 0) | ||
portalResults := make([]interface{}, 0) | ||
scmResults := make([]interface{}, 0) | ||
|
||
for _, config := range *input { | ||
output := make(map[string]interface{}, 0) | ||
|
||
if config.HostName != nil { | ||
output["host_name"] = *config.HostName | ||
} | ||
|
||
if config.NegotiateClientCertificate != nil { | ||
output["negotiate_client_certificate"] = *config.NegotiateClientCertificate | ||
} | ||
|
||
if config.KeyVaultID != nil { | ||
output["key_vault_id"] = *config.KeyVaultID | ||
} | ||
|
||
switch strings.ToLower(string(config.Type)) { | ||
case strings.ToLower(string(apimanagement.Proxy)): | ||
// only set SSL binding for proxy types | ||
if config.DefaultSslBinding != nil { | ||
output["default_ssl_binding"] = *config.DefaultSslBinding | ||
} | ||
proxyResults = append(proxyResults, output) | ||
break | ||
|
||
case strings.ToLower(string(apimanagement.Management)): | ||
managementResults = append(managementResults, output) | ||
break | ||
|
||
case strings.ToLower(string(apimanagement.Portal)): | ||
portalResults = append(portalResults, output) | ||
break | ||
|
||
case strings.ToLower(string(apimanagement.Scm)): | ||
scmResults = append(scmResults, output) | ||
break | ||
} | ||
} | ||
|
||
return []interface{}{ | ||
map[string]interface{}{ | ||
"management": managementResults, | ||
"portal": proxyResults, | ||
"proxy": portalResults, | ||
"scm": scmResults, | ||
}, | ||
} | ||
} | ||
|
||
func flattenDataSourceApiManagementAdditionalLocations(input *[]apimanagement.AdditionalLocation) []interface{} { | ||
results := make([]interface{}, 0) | ||
if input == nil { | ||
return results | ||
} | ||
|
||
for _, prop := range *input { | ||
output := make(map[string]interface{}, 0) | ||
|
||
if prop.Location != nil { | ||
output["location"] = azureRMNormalizeLocation(*prop.Location) | ||
} | ||
|
||
if prop.PublicIPAddresses != nil { | ||
output["public_ip_addresses"] = *prop.PublicIPAddresses | ||
} | ||
|
||
if prop.GatewayRegionalURL != nil { | ||
output["gateway_regional_url"] = *prop.GatewayRegionalURL | ||
} | ||
|
||
results = append(results, output) | ||
} | ||
|
||
return results | ||
} | ||
|
||
func flattenDataSourceApiManagementServiceSku(profile *apimanagement.ServiceSkuProperties) []interface{} { | ||
if profile == nil { | ||
return []interface{}{} | ||
} | ||
|
||
sku := make(map[string]interface{}, 0) | ||
|
||
sku["name"] = string(profile.Name) | ||
|
||
if profile.Capacity != nil { | ||
sku["capacity"] = *profile.Capacity | ||
} | ||
|
||
return []interface{}{sku} | ||
} | ||
|
||
func apiManagementDataSourceHostnameSchema() map[string]*schema.Schema { | ||
return map[string]*schema.Schema{ | ||
"host_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"key_vault_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"negotiate_client_certificate": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
} | ||
} | ||
|
||
func apiManagementDataSourceHostnameProxySchema() map[string]*schema.Schema { | ||
hostnameSchema := apiManagementDataSourceHostnameSchema() | ||
|
||
hostnameSchema["default_ssl_binding"] = &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
} | ||
|
||
return hostnameSchema | ||
} |
Oops, something went wrong.