Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into automationresources
Browse files Browse the repository at this point in the history
  • Loading branch information
katbyte committed Oct 17, 2018
2 parents 10bd951 + 6d20786 commit 71503c8
Show file tree
Hide file tree
Showing 446 changed files with 96,515 additions and 1,734 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ website/vendor
!command/test-fixtures/**/.terraform/

.env.sh

# goenv version file
.go-version
664 changes: 650 additions & 14 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test: fmtcheck
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4

testacc: fmtcheck
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 180m
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"

debugacc: fmtcheck
TF_ACC=1 dlv test $(TEST) --headless --listen=:2345 --api-version=2 -- -test.v $(TESTARGS)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ resource "azurerm_resource_group" "main" {
location = "West US"
}
# Create a virtual network in the web_servers resource group
# Create a virtual network in the production-resources resource group
resource "azurerm_virtual_network" "network" {
name = "production-network"
resource_group_name = "${azurerm_resource_group.main.name}"
Expand Down
197 changes: 170 additions & 27 deletions azurerm/config.go

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions azurerm/config_test.go
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")
}
}
336 changes: 336 additions & 0 deletions azurerm/data_source_api_management.go
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
}
Loading

0 comments on commit 71503c8

Please sign in to comment.