Skip to content

Commit

Permalink
provider: upgrade API Management to 2019-12-01 (#6479)
Browse files Browse the repository at this point in the history
unblocks #2613 #5769
  • Loading branch information
katbyte authored Apr 22, 2020
1 parent febf90c commit 7253b6e
Show file tree
Hide file tree
Showing 123 changed files with 10,185 additions and 5,074 deletions.
2 changes: 1 addition & 1 deletion azurerm/helpers/azure/api_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

"github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2018-01-01/apimanagement"
"github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2019-12-01/apimanagement"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
Expand Down
12 changes: 6 additions & 6 deletions azurerm/internal/services/apimanagement/client/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2018-01-01/apimanagement"
"github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2019-12-01/apimanagement"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

Expand All @@ -20,13 +20,13 @@ type Client struct {
GroupUsersClient *apimanagement.GroupUserClient
IdentityProviderClient *apimanagement.IdentityProviderClient
LoggerClient *apimanagement.LoggerClient
NamedValueClient *apimanagement.NamedValueClient
OpenIdConnectClient *apimanagement.OpenIDConnectProviderClient
PolicyClient *apimanagement.PolicyClient
ProductsClient *apimanagement.ProductClient
ProductApisClient *apimanagement.ProductAPIClient
ProductGroupsClient *apimanagement.ProductGroupClient
ProductPoliciesClient *apimanagement.ProductPolicyClient
PropertyClient *apimanagement.PropertyClient
ServiceClient *apimanagement.ServiceClient
SignInClient *apimanagement.SignInSettingsClient
SignUpClient *apimanagement.SignUpSettingsClient
Expand Down Expand Up @@ -74,6 +74,9 @@ func NewClient(o *common.ClientOptions) *Client {
identityProviderClient := apimanagement.NewIdentityProviderClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&identityProviderClient.Client, o.ResourceManagerAuthorizer)

namedValueClient := apimanagement.NewNamedValueClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&namedValueClient.Client, o.ResourceManagerAuthorizer)

loggerClient := apimanagement.NewLoggerClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&loggerClient.Client, o.ResourceManagerAuthorizer)

Expand All @@ -95,9 +98,6 @@ func NewClient(o *common.ClientOptions) *Client {
productPoliciesClient := apimanagement.NewProductPolicyClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&productPoliciesClient.Client, o.ResourceManagerAuthorizer)

propertyClient := apimanagement.NewPropertyClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&propertyClient.Client, o.ResourceManagerAuthorizer)

serviceClient := apimanagement.NewServiceClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&serviceClient.Client, o.ResourceManagerAuthorizer)

Expand Down Expand Up @@ -128,13 +128,13 @@ func NewClient(o *common.ClientOptions) *Client {
GroupUsersClient: &groupUsersClient,
IdentityProviderClient: &identityProviderClient,
LoggerClient: &loggerClient,
NamedValueClient: &namedValueClient,
OpenIdConnectClient: &openIdConnectClient,
PolicyClient: &policyClient,
ProductsClient: &productsClient,
ProductApisClient: &productApisClient,
ProductGroupsClient: &productGroupsClient,
ProductPoliciesClient: &productPoliciesClient,
PropertyClient: &propertyClient,
ServiceClient: &serviceClient,
SignInClient: &signInClient,
SignUpClient: &signUpClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2018-01-01/apimanagement"
"github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2019-12-01/apimanagement"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
Expand Down Expand Up @@ -161,7 +161,7 @@ func dataSourceApiManagementRead(d *schema.ResourceData, meta interface{}) error
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)
return fmt.Errorf("retrieving API Management Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}

d.SetId(*resp.ID)
Expand All @@ -185,11 +185,11 @@ func dataSourceApiManagementRead(d *schema.ResourceData, meta interface{}) error
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)
return fmt.Errorf("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)
return fmt.Errorf("setting `additional_location`: %+v", err)
}
}

Expand Down Expand Up @@ -225,20 +225,20 @@ func flattenDataSourceApiManagementHostnameConfigurations(input *[]apimanagement
}

switch strings.ToLower(string(config.Type)) {
case strings.ToLower(string(apimanagement.Proxy)):
case strings.ToLower(string(apimanagement.HostnameTypeProxy)):
// only set SSL binding for proxy types
if config.DefaultSslBinding != nil {
output["default_ssl_binding"] = *config.DefaultSslBinding
}
proxyResults = append(proxyResults, output)

case strings.ToLower(string(apimanagement.Management)):
case strings.ToLower(string(apimanagement.HostnameTypeManagement)):
managementResults = append(managementResults, output)

case strings.ToLower(string(apimanagement.Portal)):
case strings.ToLower(string(apimanagement.HostnameTypePortal)):
portalResults = append(portalResults, output)

case strings.ToLower(string(apimanagement.Scm)):
case strings.ToLower(string(apimanagement.HostnameTypeScm)):
scmResults = append(scmResults, output)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2018-01-01/apimanagement"
"github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2019-12-01/apimanagement"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down Expand Up @@ -129,7 +129,7 @@ func dataSourceApiManagementApiRead(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("API %q Revision %q (API Management Service %q / Resource Group %q) does not exist!", name, revision, serviceName, resourceGroup)
}

return fmt.Errorf("Error retrieving API %q / Revision %q (API Management Service %q / Resource Group %q): %+v", name, revision, serviceName, resourceGroup, err)
return fmt.Errorf("retrieving API %q / Revision %q (API Management Service %q / Resource Group %q): %+v", name, revision, serviceName, resourceGroup, err)
}

d.SetId(*resp.ID)
Expand All @@ -151,11 +151,11 @@ func dataSourceApiManagementApiRead(d *schema.ResourceData, meta interface{}) er
d.Set("version_set_id", props.APIVersionSetID)

if err := d.Set("protocols", flattenApiManagementApiDataSourceProtocols(props.Protocols)); err != nil {
return fmt.Errorf("Error setting `protocols`: %s", err)
return fmt.Errorf("setting `protocols`: %s", err)
}

if err := d.Set("subscription_key_parameter_names", flattenApiManagementApiDataSourceSubscriptionKeyParamNames(props.SubscriptionKeyParameterNames)); err != nil {
return fmt.Errorf("Error setting `subscription_key_parameter_names`: %+v", err)
return fmt.Errorf("setting `subscription_key_parameter_names`: %+v", err)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ func dataSourceApiManagementApiVersionSetRead(d *schema.ResourceData, meta inter
resp, err := client.Get(ctx, resourceGroup, serviceName, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: API Version Set %q (API Management Service %q / Resource Group %q) does not exist!", name, serviceName, resourceGroup)
return fmt.Errorf(": API Version Set %q (API Management Service %q / Resource Group %q) does not exist!", name, serviceName, resourceGroup)
}

return fmt.Errorf("Error reading API Version Set %q (API Management Service %q / Resource Group %q): %+v", name, serviceName, resourceGroup, err)
return fmt.Errorf("reading API Version Set %q (API Management Service %q / Resource Group %q): %+v", name, serviceName, resourceGroup, err)
}

if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("Error retrieving API Version Set %q (API Management Service %q /Resource Group %q): ID was nil or empty", name, serviceName, resourceGroup)
return fmt.Errorf("retrieving API Version Set %q (API Management Service %q /Resource Group %q): ID was nil or empty", name, serviceName, resourceGroup)
}

d.SetId(*resp.ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func dataSourceApiManagementGroupRead(d *schema.ResourceData, meta interface{})
return nil
}

return fmt.Errorf("Error making Read request for Group %q (Resource Group %q / API Management Service %q): %+v", name, resourceGroup, serviceName, err)
return fmt.Errorf("making Read request for Group %q (Resource Group %q / API Management Service %q): %+v", name, resourceGroup, serviceName, err)
}

d.SetId(*resp.ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2018-01-01/apimanagement"
"github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2019-12-01/apimanagement"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
Expand Down Expand Up @@ -79,7 +79,7 @@ func dataSourceApiManagementProductRead(d *schema.ResourceData, meta interface{}
return fmt.Errorf("Product %q was not found in API Management Service %q / Resource Group %q", productId, serviceName, resourceGroup)
}

return fmt.Errorf("Error making Read request on Product %q (API Management Service %q / Resource Group %q): %+v", productId, serviceName, resourceGroup, err)
return fmt.Errorf("making Read request on Product %q (API Management Service %q / Resource Group %q): %+v", productId, serviceName, resourceGroup, err)
}

d.SetId(*resp.ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func dataSourceArmApiManagementUserRead(d *schema.ResourceData, meta interface{}
return fmt.Errorf("User %q was not found in API Management Service %q / Resource Group %q", userId, serviceName, resourceGroup)
}

return fmt.Errorf("Error making Read request on User %q (API Management Service %q / Resource Group %q): %+v", userId, serviceName, resourceGroup, err)
return fmt.Errorf("making Read request on User %q (API Management Service %q / Resource Group %q): %+v", userId, serviceName, resourceGroup, err)
}

d.SetId(*resp.ID)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package migration

import (
"log"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

func APIManagementApiPropertyUpgradeV0Schema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": azure.SchemaApiManagementChildName(),

"resource_group_name": azure.SchemaResourceGroupName(),

"api_management_name": azure.SchemaApiManagementName(),

"display_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"value": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"secret": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"tags": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}

func APIManagementApiPropertyUpgradeV0ToV1(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
oldId := rawState["id"].(string)
newId := strings.Replace(rawState["id"].(string), "/properties/", "/namedValues/", 1)

log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId)

rawState["id"] = newId

return rawState, nil
}
1 change: 1 addition & 0 deletions azurerm/internal/services/apimanagement/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (r Registration) SupportedResources() map[string]*schema.Resource {
"azurerm_api_management_identity_provider_microsoft": resourceArmApiManagementIdentityProviderMicrosoft(),
"azurerm_api_management_identity_provider_twitter": resourceArmApiManagementIdentityProviderTwitter(),
"azurerm_api_management_logger": resourceArmApiManagementLogger(),
"azurerm_api_management_named_value": resourceArmApiManagementNamedValue(),
"azurerm_api_management_openid_connect_provider": resourceArmApiManagementOpenIDConnectProvider(),
"azurerm_api_management_product": resourceArmApiManagementProduct(),
"azurerm_api_management_product_api": resourceArmApiManagementProductApi(),
Expand Down
Loading

0 comments on commit 7253b6e

Please sign in to comment.