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 Resource: azurerm_api_management #1516

Merged
merged 48 commits into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
720687a
Azure SDK for API Management added
torresdal Jun 30, 2018
7858bd2
Registered API Management Service Client
torresdal Jun 30, 2018
dd97381
Added data source for API Management
torresdal Jun 30, 2018
db5aba3
Added azurerm_api_management_service as data source provider
torresdal Jun 30, 2018
5974b07
Added resource for Azure API Management
torresdal Jul 7, 2018
02a015e
Added refs to API Management in sidebar
torresdal Jul 7, 2018
3f08c53
Made bash script for creating certs more generic
torresdal Jul 8, 2018
267d6c6
Basic integration test for API Management data source
torresdal Jul 8, 2018
44fc602
Documented Azure bug related to destroying azurerm_api_management
torresdal Jul 8, 2018
27baaa6
Removed support for Virtual Networks awaiting fix in azure-sdk-for-go…
torresdal Jul 9, 2018
7f2d8b6
removed sku option from additional_location and reuse sku from root
torresdal Jul 9, 2018
be2b58e
Removed docs for certificate export, since it was removed
torresdal Jul 9, 2018
f7b6963
Updated azure-sdk-for-go and apimanagement with govendor
torresdal Jul 9, 2018
d5bb060
* removed sku from additional_location schema
torresdal Jul 14, 2018
8b4077a
* Set sku to optional and default to Developer
torresdal Jul 14, 2018
5bbf158
Fixing the vendoring
tombuildsstuff Jul 30, 2018
2a6e186
Fixed issues pointed out in review
torresdal Aug 23, 2018
f4e3137
Removed creaded date from docs
torresdal Aug 23, 2018
6d37aff
Removed sku from additional_location, since sku will be inherited fro…
torresdal Aug 23, 2018
f806c5b
Changed config from custom_properties to security with option to disa…
torresdal Aug 24, 2018
0f0b567
Updated docs for the new security block
torresdal Aug 24, 2018
1e4120c
replaced custom_properties section with security section
torresdal Aug 25, 2018
e3e8e40
Use CofigureClient instead of setting values directly
torresdal Sep 13, 2018
c3b05f2
changes from review by @katbyte
torresdal Sep 14, 2018
d8dba18
refactored and fixed issue related to how custom props are set on API…
torresdal Sep 15, 2018
44c15c5
Added apimanagement 2018-06-01-preview using govendor
torresdal Sep 15, 2018
33b34f3
Use 2018-06-01-preview of Azure API Management API. Ignore sensitive …
torresdal Sep 17, 2018
6035517
Removed old apimanagement package
torresdal Sep 17, 2018
98d6639
Fixed issues related to handling secrets not returned by API
torresdal Sep 21, 2018
e8b1b1e
Added support for Managed Service Identity
torresdal Sep 21, 2018
524b947
Support ref certs using key_vault_id
torresdal Sep 21, 2018
2157d98
Fixed issue where default ssl binding was set for other hotname types…
torresdal Sep 21, 2018
e8ebdb3
Updated docs for API Management to reflect recent changes. Code cleanup
torresdal Sep 22, 2018
93ecec6
Cleaned up data source for api-management
torresdal Sep 24, 2018
d9811ea
Fixed API Management example to reflect recent changes
torresdal Sep 26, 2018
5ea1c27
d/api_management: refactoring
tombuildsstuff Sep 27, 2018
4b94092
r/api_management: refactoring to remove the customizeDiff
tombuildsstuff Sep 27, 2018
1bc76f5
Refactoring the API Management Resource:
tombuildsstuff Sep 28, 2018
537ff5b
More refactoring:
tombuildsstuff Sep 28, 2018
d893782
Fixing the sidebar highlight
tombuildsstuff Sep 28, 2018
a7f2dfb
Fixing the broken tests
tombuildsstuff Sep 28, 2018
05db8ab
Running tests against different regions to get around the concurrency…
tombuildsstuff Sep 28, 2018
1029ee0
Removed duplicate section spacing
torresdal Sep 28, 2018
29d4360
Changed static_ips to public_ip_addresses
torresdal Sep 28, 2018
9e3bbf9
Fixing an incorrect assignment bug
tombuildsstuff Sep 28, 2018
c69342b
Updating to v21.1.0 of the Azure SDK
tombuildsstuff Oct 1, 2018
6c35627
Resolving PR comments
tombuildsstuff Oct 1, 2018
24d1f14
Ensuring that different resource groups are provisioned
tombuildsstuff Oct 1, 2018
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
11 changes: 11 additions & 0 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-04-01/network"
"github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs"
"github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql"
"github.com/Azure/azure-sdk-for-go/services/preview/apimanagement/mgmt/2018-06-01-preview/apimanagement"
"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-01-01-preview/authorization"
"github.com/Azure/azure-sdk-for-go/services/preview/dns/mgmt/2018-03-01-preview/dns"
"github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2018-03-01/insights"
Expand Down Expand Up @@ -106,6 +107,9 @@ type ArmClient struct {
redisFirewallClient redis.FirewallRulesClient
redisPatchSchedulesClient redis.PatchSchedulesClient

// API Management
apiManagementServiceClient apimanagement.ServiceClient

// Application Insights
appInsightsClient appinsights.ComponentsClient

Expand Down Expand Up @@ -448,6 +452,7 @@ func getArmClient(c *authentication.Config) (*ArmClient, error) {
return keyVaultSpt, nil
})

client.registerApiManagementServiceClients(endpoint, c.SubscriptionID, auth, sender)
client.registerAppInsightsClients(endpoint, c.SubscriptionID, auth, sender)
client.registerAutomationClients(endpoint, c.SubscriptionID, auth, sender)
client.registerAuthentication(endpoint, graphEndpoint, c.SubscriptionID, c.TenantID, auth, graphAuth, sender)
Expand Down Expand Up @@ -487,6 +492,12 @@ func getArmClient(c *authentication.Config) (*ArmClient, error) {
return &client, nil
}

func (c *ArmClient) registerApiManagementServiceClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
ams := apimanagement.NewServiceClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&ams.Client, auth)
c.apiManagementServiceClient = ams
}

func (c *ArmClient) registerAppInsightsClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
ai := appinsights.NewComponentsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&ai.Client, auth)
Expand Down
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,
},
torresdal marked this conversation as resolved.
Show resolved Hide resolved

"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