diff --git a/internal/services/apimanagement/api_management_global_schema_resource.go b/internal/services/apimanagement/api_management_global_schema_resource.go new file mode 100644 index 000000000000..df3087d11a9c --- /dev/null +++ b/internal/services/apimanagement/api_management_global_schema_resource.go @@ -0,0 +1,180 @@ +package apimanagement + +import ( + "encoding/json" + "fmt" + "log" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/response" + globalSchema "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema" + "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/schemaz" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" + "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +func resourceApiManagementGlobalSchema() *pluginsdk.Resource { + return &pluginsdk.Resource{ + Create: resourceApiManagementGlobalSchemaCreateUpdate, + Read: resourceApiManagementGlobalSchemaRead, + Update: resourceApiManagementGlobalSchemaCreateUpdate, + Delete: resourceApiManagementGlobalSchemaDelete, + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { + _, err := globalSchema.ParseSchemaID(id) + return err + }), + + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(30 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(30 * time.Minute), + Delete: pluginsdk.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*pluginsdk.Schema{ + "schema_id": schemaz.SchemaApiManagementChildName(), + + "api_management_name": schemaz.SchemaApiManagementName(), + + "resource_group_name": azure.SchemaResourceGroupName(), + + "type": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(globalSchema.SchemaTypeJson), + string(globalSchema.SchemaTypeXml)}, false), + }, + + "value": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + DiffSuppressFunc: pluginsdk.SuppressJsonDiff, + }, + + "description": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + } +} + +func resourceApiManagementGlobalSchemaCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).ApiManagement.GlobalSchemaClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + id := globalSchema.NewSchemaID(subscriptionId, d.Get("resource_group_name").(string), d.Get("api_management_name").(string), d.Get("schema_id").(string)) + + if d.IsNewResource() { + existing, err := client.GlobalSchemaGet(ctx, id) + if err != nil { + if !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for presence of existing %s: %s", id, err) + } + } + + if !response.WasNotFound(existing.HttpResponse) { + return tf.ImportAsExistsError("azurerm_api_management_global_schema", id.ID()) + } + } + parameters := globalSchema.GlobalSchemaContract{ + Properties: &globalSchema.GlobalSchemaContractProperties{ + Description: utils.String(d.Get("description").(string)), + SchemaType: globalSchema.SchemaType(d.Get("type").(string)), + }, + } + + // value for type=xml, document for type=json + value := d.Get("value") + if d.Get("type").(string) == string(globalSchema.SchemaTypeXml) { + parameters.Properties.Value = &value + } else { + var document interface{} + if err := json.Unmarshal([]byte(value.(string)), &document); err != nil { + return fmt.Errorf(" error preparing value data to send %s: %s", id, err) + } + parameters.Properties.Document = &document + } + + future, err := client.GlobalSchemaCreateOrUpdate(ctx, id, parameters, globalSchema.DefaultGlobalSchemaCreateOrUpdateOperationOptions()) + if err != nil { + return fmt.Errorf("creating/updating %s: %s", id, err) + } + if err := future.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("waiting for creation/update of %q: %+v", id, err) + } + + d.SetId(id.ID()) + return resourceApiManagementGlobalSchemaRead(d, meta) +} + +func resourceApiManagementGlobalSchemaRead(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).ApiManagement.GlobalSchemaClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := globalSchema.ParseSchemaID(d.Id()) + if err != nil { + return err + } + + resp, err := client.GlobalSchemaGet(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + log.Printf("[DEBUG] %s was not found - removing from state!", *id) + d.SetId("") + return nil + } + + return fmt.Errorf("making Read request for %s: %s", *id, err) + } + + d.Set("schema_id", id.SchemaId) + d.Set("api_management_name", id.ServiceName) + d.Set("resource_group_name", id.ResourceGroupName) + d.Set("type", resp.Model.Properties.SchemaType) + d.Set("description", resp.Model.Properties.Description) + + if resp.Model != nil { + if resp.Model.Properties.SchemaType == globalSchema.SchemaTypeXml { + d.Set("value", resp.Model.Properties.Value) + } else { + var document []byte + if document, err = json.Marshal(resp.Model.Properties.Document); err != nil { + return fmt.Errorf(" reading the schema document %s: %s", *id, err) + } + d.Set("value", string(document)) + } + } + + return nil +} + +func resourceApiManagementGlobalSchemaDelete(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).ApiManagement.GlobalSchemaClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := globalSchema.ParseSchemaID(d.Id()) + if err != nil { + return err + } + + if resp, err := client.GlobalSchemaDelete(ctx, *id, globalSchema.DefaultGlobalSchemaDeleteOperationOptions()); err != nil { + if !response.WasNotFound(resp.HttpResponse) { + return fmt.Errorf("deleting %s: %s", *id, err) + } + } + + return nil +} diff --git a/internal/services/apimanagement/api_management_global_schema_resource_test.go b/internal/services/apimanagement/api_management_global_schema_resource_test.go new file mode 100644 index 000000000000..5dc3cdd58c19 --- /dev/null +++ b/internal/services/apimanagement/api_management_global_schema_resource_test.go @@ -0,0 +1,263 @@ +package apimanagement_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type ApiManagementGlobalSchemaResource struct{} + +func TestAccApiManagementGlobalSchema_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management_global_schema", "test") + r := ApiManagementGlobalSchemaResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccApiManagementGlobalSchema_jsonSchema(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management_global_schema", "test") + r := ApiManagementGlobalSchemaResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.jsonSchema(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccApiManagementGlobalSchema_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management_global_schema", "test") + r := ApiManagementGlobalSchemaResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.update(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccApiManagementGlobalSchema_requireImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management_global_schema", "test") + r := ApiManagementGlobalSchemaResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func (ApiManagementGlobalSchemaResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := schema.ParseSchemaID(state.ID) + if err != nil { + return nil, err + } + + resp, err := clients.ApiManagement.GlobalSchemaClient.GlobalSchemaGet(ctx, *id) + if err != nil { + return nil, fmt.Errorf("reading ApiManagement Global Schema (%s): %+v", id, err) + } + + return utils.Bool(resp.Model.Id != nil), nil +} + +func (r ApiManagementGlobalSchemaResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%[1]d" + location = "%[2]s" +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + publisher_name = "pub1" + publisher_email = "pub1@email.com" + sku_name = "Consumption_0" +} + +resource "azurerm_api_management_global_schema" "test" { + schema_id = "accetestSchema-%[1]d" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name + type = "xml" + value = < + + + + + + + + + + + + + + + + + + + +XML +} +`, data.RandomInteger, data.Locations.Primary) +} + +func (r ApiManagementGlobalSchemaResource) jsonSchema(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%[1]d" + location = "%[2]s" +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + publisher_name = "pub1" + publisher_email = "pub1@email.com" + sku_name = "Consumption_0" +} + +resource "azurerm_api_management_global_schema" "test" { + schema_id = "accetestSchema-%[1]d" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name + type = "json" + value = < + + + + + + + + + + + + + + + + + +XML +} +`, data.RandomInteger, data.Locations.Primary) +} + +func (r ApiManagementGlobalSchemaResource) requiresImport(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_api_management_global_schema" "import" { + schema_id = azurerm_api_management_global_schema.test.schema_id + api_management_name = azurerm_api_management_global_schema.test.api_management_name + resource_group_name = azurerm_api_management_global_schema.test.resource_group_name + type = azurerm_api_management_global_schema.test.type + value = azurerm_api_management_global_schema.test.value +} +`, r.basic(data)) +} diff --git a/internal/services/apimanagement/client/client.go b/internal/services/apimanagement/client/client.go index 3bbfab689b7c..15b2d7af455b 100644 --- a/internal/services/apimanagement/client/client.go +++ b/internal/services/apimanagement/client/client.go @@ -2,6 +2,7 @@ package client import ( "github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2021-08-01/apimanagement" + pandoraAPIMGlobalSchema "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema" "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) @@ -25,6 +26,7 @@ type Client struct { GatewayCertificateAuthorityClient *apimanagement.GatewayCertificateAuthorityClient GatewayApisClient *apimanagement.GatewayAPIClient GatewayHostNameConfigurationClient *apimanagement.GatewayHostnameConfigurationClient + GlobalSchemaClient *pandoraAPIMGlobalSchema.SchemaClient GroupClient *apimanagement.GroupClient GroupUsersClient *apimanagement.GroupUserClient IdentityProviderClient *apimanagement.IdentityProviderClient @@ -105,6 +107,9 @@ func NewClient(o *common.ClientOptions) *Client { gatewayHostNameConfigurationClient := apimanagement.NewGatewayHostnameConfigurationClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&gatewayHostNameConfigurationClient.Client, o.ResourceManagerAuthorizer) + globalSchemaClient := pandoraAPIMGlobalSchema.NewSchemaClientWithBaseURI(o.ResourceManagerEndpoint) + o.ConfigureClient(&globalSchemaClient.Client, o.ResourceManagerAuthorizer) + groupClient := apimanagement.NewGroupClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&groupClient.Client, o.ResourceManagerAuthorizer) @@ -185,6 +190,7 @@ func NewClient(o *common.ClientOptions) *Client { GatewayCertificateAuthorityClient: &gatewayCertificateAuthorityClient, GatewayApisClient: &gatewayApisClient, GatewayHostNameConfigurationClient: &gatewayHostNameConfigurationClient, + GlobalSchemaClient: &globalSchemaClient, GroupClient: &groupClient, GroupUsersClient: &groupUsersClient, IdentityProviderClient: &identityProviderClient, diff --git a/internal/services/apimanagement/registration.go b/internal/services/apimanagement/registration.go index 424b0db42e1b..512145362ced 100644 --- a/internal/services/apimanagement/registration.go +++ b/internal/services/apimanagement/registration.go @@ -81,6 +81,7 @@ func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { "azurerm_api_management_product_policy": resourceApiManagementProductPolicy(), "azurerm_api_management_redis_cache": resourceApiManagementRedisCache(), "azurerm_api_management_subscription": resourceApiManagementSubscription(), + "azurerm_api_management_global_schema": resourceApiManagementGlobalSchema(), "azurerm_api_management_tag": resourceApiManagementTag(), "azurerm_api_management_user": resourceApiManagementUser(), } diff --git a/internal/services/apimanagement/resourceids.go b/internal/services/apimanagement/resourceids.go index 589e87c8e66c..97413f289e84 100644 --- a/internal/services/apimanagement/resourceids.go +++ b/internal/services/apimanagement/resourceids.go @@ -17,6 +17,7 @@ package apimanagement //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=EmailTemplate -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/templates/template1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Gateway -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/gateways/gateway1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=GatewayApi -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/gateways/gateway1/apis/api1 +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=GlobalSchema -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/schemas/schema1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Group -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/groups/group1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=GroupUser -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/groups/group1/users/user1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=IdentityProvider -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/identityProviders/identityProvider1 diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/README.md new file mode 100644 index 000000000000..6def2c4ddd6e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/README.md @@ -0,0 +1,102 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema` Documentation + +The `schema` SDK allows for interaction with the Azure Resource Manager Service `apimanagement` (API Version `2021-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema" +``` + + +### Client Initialization + +```go +client := schema.NewSchemaClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SchemaClient.GlobalSchemaCreateOrUpdate` + +```go +ctx := context.TODO() +id := schema.NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "schemaIdValue") + +payload := schema.GlobalSchemaContract{ + // ... +} + + +if err := client.GlobalSchemaCreateOrUpdateThenPoll(ctx, id, payload, schema.DefaultGlobalSchemaCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `SchemaClient.GlobalSchemaDelete` + +```go +ctx := context.TODO() +id := schema.NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "schemaIdValue") + +read, err := client.GlobalSchemaDelete(ctx, id, schema.DefaultGlobalSchemaDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SchemaClient.GlobalSchemaGet` + +```go +ctx := context.TODO() +id := schema.NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "schemaIdValue") + +read, err := client.GlobalSchemaGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SchemaClient.GlobalSchemaGetEntityTag` + +```go +ctx := context.TODO() +id := schema.NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue", "schemaIdValue") + +read, err := client.GlobalSchemaGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SchemaClient.GlobalSchemaListByService` + +```go +ctx := context.TODO() +id := schema.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceValue") + +// alternatively `client.GlobalSchemaListByService(ctx, id, schema.DefaultGlobalSchemaListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.GlobalSchemaListByServiceComplete(ctx, id, schema.DefaultGlobalSchemaListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/client.go new file mode 100644 index 000000000000..8905f2ce375a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/client.go @@ -0,0 +1,18 @@ +package schema + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SchemaClient struct { + Client autorest.Client + baseUri string +} + +func NewSchemaClientWithBaseURI(endpoint string) SchemaClient { + return SchemaClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/constants.go new file mode 100644 index 000000000000..ab4513e2c374 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/constants.go @@ -0,0 +1,34 @@ +package schema + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SchemaType string + +const ( + SchemaTypeJson SchemaType = "json" + SchemaTypeXml SchemaType = "xml" +) + +func PossibleValuesForSchemaType() []string { + return []string{ + string(SchemaTypeJson), + string(SchemaTypeXml), + } +} + +func parseSchemaType(input string) (*SchemaType, error) { + vals := map[string]SchemaType{ + "json": SchemaTypeJson, + "xml": SchemaTypeXml, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SchemaType(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/id_schema.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/id_schema.go new file mode 100644 index 000000000000..bdc9795bb26f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/id_schema.go @@ -0,0 +1,137 @@ +package schema + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = SchemaId{} + +// SchemaId is a struct representing the Resource ID for a Schema +type SchemaId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + SchemaId string +} + +// NewSchemaID returns a new SchemaId struct +func NewSchemaID(subscriptionId string, resourceGroupName string, serviceName string, schemaId string) SchemaId { + return SchemaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + SchemaId: schemaId, + } +} + +// ParseSchemaID parses 'input' into a SchemaId +func ParseSchemaID(input string) (*SchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(SchemaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SchemaId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServiceName, ok = parsed.Parsed["serviceName"]; !ok { + return nil, fmt.Errorf("the segment 'serviceName' was not found in the resource id %q", input) + } + + if id.SchemaId, ok = parsed.Parsed["schemaId"]; !ok { + return nil, fmt.Errorf("the segment 'schemaId' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseSchemaIDInsensitively parses 'input' case-insensitively into a SchemaId +// note: this method should only be used for API response data and not user input +func ParseSchemaIDInsensitively(input string) (*SchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(SchemaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := SchemaId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServiceName, ok = parsed.Parsed["serviceName"]; !ok { + return nil, fmt.Errorf("the segment 'serviceName' was not found in the resource id %q", input) + } + + if id.SchemaId, ok = parsed.Parsed["schemaId"]; !ok { + return nil, fmt.Errorf("the segment 'schemaId' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateSchemaID checks that 'input' can be parsed as a Schema ID +func ValidateSchemaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSchemaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Schema ID +func (id SchemaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/schemas/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.SchemaId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Schema ID +func (id SchemaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaId", "schemaIdValue"), + } +} + +// String returns a human-readable description of this Schema ID +func (id SchemaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Schema: %q", id.SchemaId), + } + return fmt.Sprintf("Schema (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/id_service.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/id_service.go new file mode 100644 index 000000000000..50cf5a8eda0b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/id_service.go @@ -0,0 +1,124 @@ +package schema + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServiceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServiceName, ok = parsed.Parsed["serviceName"]; !ok { + return nil, fmt.Errorf("the segment 'serviceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ServiceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ServiceName, ok = parsed.Parsed["serviceName"]; !ok { + return nil, fmt.Errorf("the segment 'serviceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceValue"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/method_globalschemacreateorupdate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/method_globalschemacreateorupdate_autorest.go new file mode 100644 index 000000000000..169dc63374e3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/method_globalschemacreateorupdate_autorest.go @@ -0,0 +1,108 @@ +package schema + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GlobalSchemaCreateOrUpdateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +type GlobalSchemaCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultGlobalSchemaCreateOrUpdateOperationOptions() GlobalSchemaCreateOrUpdateOperationOptions { + return GlobalSchemaCreateOrUpdateOperationOptions{} +} + +func (o GlobalSchemaCreateOrUpdateOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + if o.IfMatch != nil { + out["If-Match"] = *o.IfMatch + } + + return out +} + +func (o GlobalSchemaCreateOrUpdateOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +// GlobalSchemaCreateOrUpdate ... +func (c SchemaClient) GlobalSchemaCreateOrUpdate(ctx context.Context, id SchemaId, input GlobalSchemaContract, options GlobalSchemaCreateOrUpdateOperationOptions) (result GlobalSchemaCreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForGlobalSchemaCreateOrUpdate(ctx, id, input, options) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaCreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForGlobalSchemaCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaCreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// GlobalSchemaCreateOrUpdateThenPoll performs GlobalSchemaCreateOrUpdate then polls until it's completed +func (c SchemaClient) GlobalSchemaCreateOrUpdateThenPoll(ctx context.Context, id SchemaId, input GlobalSchemaContract, options GlobalSchemaCreateOrUpdateOperationOptions) error { + result, err := c.GlobalSchemaCreateOrUpdate(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing GlobalSchemaCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after GlobalSchemaCreateOrUpdate: %+v", err) + } + + return nil +} + +// preparerForGlobalSchemaCreateOrUpdate prepares the GlobalSchemaCreateOrUpdate request. +func (c SchemaClient) preparerForGlobalSchemaCreateOrUpdate(ctx context.Context, id SchemaId, input GlobalSchemaContract, options GlobalSchemaCreateOrUpdateOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForGlobalSchemaCreateOrUpdate sends the GlobalSchemaCreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c SchemaClient) senderForGlobalSchemaCreateOrUpdate(ctx context.Context, req *http.Request) (future GlobalSchemaCreateOrUpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/method_globalschemadelete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/method_globalschemadelete_autorest.go new file mode 100644 index 000000000000..ec3f0417e404 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/method_globalschemadelete_autorest.go @@ -0,0 +1,95 @@ +package schema + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GlobalSchemaDeleteOperationResponse struct { + HttpResponse *http.Response +} + +type GlobalSchemaDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultGlobalSchemaDeleteOperationOptions() GlobalSchemaDeleteOperationOptions { + return GlobalSchemaDeleteOperationOptions{} +} + +func (o GlobalSchemaDeleteOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + if o.IfMatch != nil { + out["If-Match"] = *o.IfMatch + } + + return out +} + +func (o GlobalSchemaDeleteOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +// GlobalSchemaDelete ... +func (c SchemaClient) GlobalSchemaDelete(ctx context.Context, id SchemaId, options GlobalSchemaDeleteOperationOptions) (result GlobalSchemaDeleteOperationResponse, err error) { + req, err := c.preparerForGlobalSchemaDelete(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaDelete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaDelete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGlobalSchemaDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaDelete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGlobalSchemaDelete prepares the GlobalSchemaDelete request. +func (c SchemaClient) preparerForGlobalSchemaDelete(ctx context.Context, id SchemaId, options GlobalSchemaDeleteOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGlobalSchemaDelete handles the response to the GlobalSchemaDelete request. The method always +// closes the http.Response Body. +func (c SchemaClient) responderForGlobalSchemaDelete(resp *http.Response) (result GlobalSchemaDeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/method_globalschemaget_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/method_globalschemaget_autorest.go new file mode 100644 index 000000000000..d87e67a9d308 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/method_globalschemaget_autorest.go @@ -0,0 +1,68 @@ +package schema + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GlobalSchemaGetOperationResponse struct { + HttpResponse *http.Response + Model *GlobalSchemaContract +} + +// GlobalSchemaGet ... +func (c SchemaClient) GlobalSchemaGet(ctx context.Context, id SchemaId) (result GlobalSchemaGetOperationResponse, err error) { + req, err := c.preparerForGlobalSchemaGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaGet", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaGet", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGlobalSchemaGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaGet", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGlobalSchemaGet prepares the GlobalSchemaGet request. +func (c SchemaClient) preparerForGlobalSchemaGet(ctx context.Context, id SchemaId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGlobalSchemaGet handles the response to the GlobalSchemaGet request. The method always +// closes the http.Response Body. +func (c SchemaClient) responderForGlobalSchemaGet(resp *http.Response) (result GlobalSchemaGetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/method_globalschemagetentitytag_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/method_globalschemagetentitytag_autorest.go new file mode 100644 index 000000000000..a02a95a3402c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/method_globalschemagetentitytag_autorest.go @@ -0,0 +1,66 @@ +package schema + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GlobalSchemaGetEntityTagOperationResponse struct { + HttpResponse *http.Response +} + +// GlobalSchemaGetEntityTag ... +func (c SchemaClient) GlobalSchemaGetEntityTag(ctx context.Context, id SchemaId) (result GlobalSchemaGetEntityTagOperationResponse, err error) { + req, err := c.preparerForGlobalSchemaGetEntityTag(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaGetEntityTag", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaGetEntityTag", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGlobalSchemaGetEntityTag(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaGetEntityTag", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGlobalSchemaGetEntityTag prepares the GlobalSchemaGetEntityTag request. +func (c SchemaClient) preparerForGlobalSchemaGetEntityTag(ctx context.Context, id SchemaId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsHead(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGlobalSchemaGetEntityTag handles the response to the GlobalSchemaGetEntityTag request. The method always +// closes the http.Response Body. +func (c SchemaClient) responderForGlobalSchemaGetEntityTag(resp *http.Response) (result GlobalSchemaGetEntityTagOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/method_globalschemalistbyservice_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/method_globalschemalistbyservice_autorest.go new file mode 100644 index 000000000000..f69bb14a594d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/method_globalschemalistbyservice_autorest.go @@ -0,0 +1,225 @@ +package schema + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GlobalSchemaListByServiceOperationResponse struct { + HttpResponse *http.Response + Model *[]GlobalSchemaContract + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (GlobalSchemaListByServiceOperationResponse, error) +} + +type GlobalSchemaListByServiceCompleteResult struct { + Items []GlobalSchemaContract +} + +func (r GlobalSchemaListByServiceOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r GlobalSchemaListByServiceOperationResponse) LoadMore(ctx context.Context) (resp GlobalSchemaListByServiceOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type GlobalSchemaListByServiceOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultGlobalSchemaListByServiceOperationOptions() GlobalSchemaListByServiceOperationOptions { + return GlobalSchemaListByServiceOperationOptions{} +} + +func (o GlobalSchemaListByServiceOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o GlobalSchemaListByServiceOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + if o.Skip != nil { + out["$skip"] = *o.Skip + } + + if o.Top != nil { + out["$top"] = *o.Top + } + + return out +} + +// GlobalSchemaListByService ... +func (c SchemaClient) GlobalSchemaListByService(ctx context.Context, id ServiceId, options GlobalSchemaListByServiceOperationOptions) (resp GlobalSchemaListByServiceOperationResponse, err error) { + req, err := c.preparerForGlobalSchemaListByService(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaListByService", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaListByService", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForGlobalSchemaListByService(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaListByService", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForGlobalSchemaListByService prepares the GlobalSchemaListByService request. +func (c SchemaClient) preparerForGlobalSchemaListByService(ctx context.Context, id ServiceId, options GlobalSchemaListByServiceOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/schemas", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForGlobalSchemaListByServiceWithNextLink prepares the GlobalSchemaListByService request with the given nextLink token. +func (c SchemaClient) preparerForGlobalSchemaListByServiceWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGlobalSchemaListByService handles the response to the GlobalSchemaListByService request. The method always +// closes the http.Response Body. +func (c SchemaClient) responderForGlobalSchemaListByService(resp *http.Response) (result GlobalSchemaListByServiceOperationResponse, err error) { + type page struct { + Values []GlobalSchemaContract `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result GlobalSchemaListByServiceOperationResponse, err error) { + req, err := c.preparerForGlobalSchemaListByServiceWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaListByService", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaListByService", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGlobalSchemaListByService(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "schema.SchemaClient", "GlobalSchemaListByService", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// GlobalSchemaListByServiceComplete retrieves all of the results into a single object +func (c SchemaClient) GlobalSchemaListByServiceComplete(ctx context.Context, id ServiceId, options GlobalSchemaListByServiceOperationOptions) (GlobalSchemaListByServiceCompleteResult, error) { + return c.GlobalSchemaListByServiceCompleteMatchingPredicate(ctx, id, options, GlobalSchemaContractOperationPredicate{}) +} + +// GlobalSchemaListByServiceCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c SchemaClient) GlobalSchemaListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options GlobalSchemaListByServiceOperationOptions, predicate GlobalSchemaContractOperationPredicate) (resp GlobalSchemaListByServiceCompleteResult, err error) { + items := make([]GlobalSchemaContract, 0) + + page, err := c.GlobalSchemaListByService(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := GlobalSchemaListByServiceCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/model_globalschemacontract.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/model_globalschemacontract.go new file mode 100644 index 000000000000..4d72a7e9bf8f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/model_globalschemacontract.go @@ -0,0 +1,11 @@ +package schema + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GlobalSchemaContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GlobalSchemaContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/model_globalschemacontractproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/model_globalschemacontractproperties.go new file mode 100644 index 000000000000..416785819ada --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/model_globalschemacontractproperties.go @@ -0,0 +1,11 @@ +package schema + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GlobalSchemaContractProperties struct { + Description *string `json:"description,omitempty"` + Document *interface{} `json:"document,omitempty"` + SchemaType SchemaType `json:"schemaType"` + Value *interface{} `json:"value,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/predicates.go new file mode 100644 index 000000000000..4896cd564906 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/predicates.go @@ -0,0 +1,24 @@ +package schema + +type GlobalSchemaContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GlobalSchemaContractOperationPredicate) Matches(input GlobalSchemaContract) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/version.go new file mode 100644 index 000000000000..03a764024d2f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema/version.go @@ -0,0 +1,12 @@ +package schema + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-08-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/schema/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 0e32f8f68674..c08a1121e92d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -188,6 +188,7 @@ github.com/hashicorp/go-azure-helpers/storage github.com/hashicorp/go-azure-sdk/resource-manager/aad/2021-05-01/domainservices github.com/hashicorp/go-azure-sdk/resource-manager/aadb2c/2021-04-01-preview/tenants github.com/hashicorp/go-azure-sdk/resource-manager/analysisservices/2017-08-01/servers +github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2021-08-01/schema github.com/hashicorp/go-azure-sdk/resource-manager/appconfiguration/2022-05-01/configurationstores github.com/hashicorp/go-azure-sdk/resource-manager/applicationinsights/2020-11-20/workbooktemplatesapis github.com/hashicorp/go-azure-sdk/resource-manager/applicationinsights/2022-04-01/workbooksapis diff --git a/website/docs/r/api_management_schema.html.markdown b/website/docs/r/api_management_schema.html.markdown new file mode 100644 index 000000000000..06b6827bef7d --- /dev/null +++ b/website/docs/r/api_management_schema.html.markdown @@ -0,0 +1,83 @@ +--- +subcategory: "API Management" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_api_management_global_schema" +description: |- + Manages a Global Schema within an API Management Service. +--- + +# azurerm_api_management_global_schema + +Manages a Global Schema within an API Management Service. + +## Example Usage + +```hcl +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "example" { + name = "example-rg" + location = "West Europe" +} + +resource "azurerm_api_management" "example" { + name = "example-apim" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + publisher_name = "pub1" + publisher_email = "pub1@email.com" + sku_name = "Consumption_0" +} + +resource "azurerm_api_management_global_schema" "example" { + schema_id = "example-schema1" + api_management_name = azurerm_api_management.example.name + resource_group_name = azurerm_resource_group.example.name + type = "xml" + value = file("api_management_api_schema.xml") +} +``` + +## Argument Reference + +The following arguments are supported: + +* `schema_id` - (Required) A unique identifier for this Schema. Changing this forces a new resource to be created. + +* `api_management_name` - (Required) The Name of the API Management Service where the API exists. Changing this forces a + new resource to be created. + +* `resource_group_name` - (Required) The Name of the Resource Group in which the API Management Service exists. Changing + this forces a new resource to be created. + +* `type` - (Required) The content type of the Schema. Possible values are `xml` and `json`. + +* `value` - (Required) The string defining the document representing the Schema. + +* `description` - (Optional) The description of the schema. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The ID of the API Management API Schema. + +## Timeouts + +The `timeouts` block allows you to +specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the API Management API Schema. +* `update` - (Defaults to 30 minutes) Used when updating the API Management API Schema. +* `read` - (Defaults to 5 minutes) Used when retrieving the API Management API Schema. +* `delete` - (Defaults to 30 minutes) Used when deleting the API Management API Schema. + +## Import + +API Management API Schema's can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_api_management_global_schema.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.ApiManagement/service/instance1/schemas/schema1 +```