From 596283ccf674b16cf679230618e54801263835fc Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Mon, 23 Mar 2020 22:09:39 -0700 Subject: [PATCH 1/5] Custom Resource Provider --- azurerm/internal/clients/client.go | 3 + .../provider/required_resource_providers.go | 1 + azurerm/internal/provider/services.go | 2 + .../services/customproviders/client/client.go | 19 + .../parse/custom_resource_provider.go | 33 + .../parse/custom_resource_provider_test.go | 73 ++ .../services/customproviders/registration.go | 31 + .../resource_arm_custom_resource_provider.go | 403 ++++++++ ...ource_arm_custom_resource_provider_test.go | 251 +++++ .../customproviders/associations.go | 385 +++++++ .../customproviders/client.go | 52 + .../customproviders/customresourceprovider.go | 603 +++++++++++ .../customproviders/models.go | 946 ++++++++++++++++++ .../customproviders/operations.go | 147 +++ .../customproviders/version.go | 30 + vendor/modules.txt | 1 + website/allowed-subcategories | 1 + website/azurerm.erb | 9 + .../r/custom_resource_provider.html.markdown | 94 ++ 19 files changed, 3084 insertions(+) create mode 100644 azurerm/internal/services/customproviders/client/client.go create mode 100644 azurerm/internal/services/customproviders/parse/custom_resource_provider.go create mode 100644 azurerm/internal/services/customproviders/parse/custom_resource_provider_test.go create mode 100644 azurerm/internal/services/customproviders/registration.go create mode 100644 azurerm/internal/services/customproviders/resource_arm_custom_resource_provider.go create mode 100644 azurerm/internal/services/customproviders/tests/resource_arm_custom_resource_provider_test.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/associations.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/client.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/customresourceprovider.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/models.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/operations.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/version.go create mode 100644 website/docs/r/custom_resource_provider.html.markdown diff --git a/azurerm/internal/clients/client.go b/azurerm/internal/clients/client.go index 035ba1388f4d..e430ed07db03 100644 --- a/azurerm/internal/clients/client.go +++ b/azurerm/internal/clients/client.go @@ -20,6 +20,7 @@ import ( containerServices "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers/client" cosmosdb "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cosmos/client" costmanagement "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/costmanagement/client" + customproviders "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/customproviders/client" datamigration "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databasemigration/client" databricks "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databricks/client" datafactory "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/client" @@ -93,6 +94,7 @@ type Client struct { Containers *containerServices.Client Cosmos *cosmosdb.Client CostManagement *costmanagement.Client + CustomProviders *customproviders.Client DatabaseMigration *datamigration.Client DataBricks *databricks.Client DataFactory *datafactory.Client @@ -167,6 +169,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error client.Containers = containerServices.NewClient(o) client.Cosmos = cosmosdb.NewClient(o) client.CostManagement = costmanagement.NewClient(o) + client.CustomProviders = customproviders.NewClient(o) client.DatabaseMigration = datamigration.NewClient(o) client.DataBricks = databricks.NewClient(o) client.DataFactory = datafactory.NewClient(o) diff --git a/azurerm/internal/provider/required_resource_providers.go b/azurerm/internal/provider/required_resource_providers.go index 585c983663fb..47f2eb261f60 100644 --- a/azurerm/internal/provider/required_resource_providers.go +++ b/azurerm/internal/provider/required_resource_providers.go @@ -28,6 +28,7 @@ func RequiredResourceProviders() map[string]struct{} { "Microsoft.ContainerRegistry": {}, "Microsoft.ContainerService": {}, "Microsoft.CostManagement": {}, + "Microsoft.CustomProviders": {}, "Microsoft.Databricks": {}, "Microsoft.DataLakeAnalytics": {}, "Microsoft.DataLakeStore": {}, diff --git a/azurerm/internal/provider/services.go b/azurerm/internal/provider/services.go index cf855e88dc2c..d93e0450cad9 100644 --- a/azurerm/internal/provider/services.go +++ b/azurerm/internal/provider/services.go @@ -16,6 +16,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cosmos" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/costmanagement" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/customproviders" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databasemigration" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databricks" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory" @@ -86,6 +87,7 @@ func SupportedServices() []common.ServiceRegistration { containers.Registration{}, cosmos.Registration{}, costmanagement.Registration{}, + customproviders.Registration{}, databricks.Registration{}, datafactory.Registration{}, datalake.Registration{}, diff --git a/azurerm/internal/services/customproviders/client/client.go b/azurerm/internal/services/customproviders/client/client.go new file mode 100644 index 000000000000..35a0dc15eaa8 --- /dev/null +++ b/azurerm/internal/services/customproviders/client/client.go @@ -0,0 +1,19 @@ +package client + +import ( + "github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common" +) + +type Client struct { + CustomResourceProviderClient *customproviders.CustomResourceProviderClient +} + +func NewClient(o *common.ClientOptions) *Client { + CustomResourceProviderClient := customproviders.NewCustomResourceProviderClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + o.ConfigureClient(&CustomResourceProviderClient.Client, o.ResourceManagerAuthorizer) + + return &Client{ + CustomResourceProviderClient: &CustomResourceProviderClient, + } +} diff --git a/azurerm/internal/services/customproviders/parse/custom_resource_provider.go b/azurerm/internal/services/customproviders/parse/custom_resource_provider.go new file mode 100644 index 000000000000..a44b44163ed8 --- /dev/null +++ b/azurerm/internal/services/customproviders/parse/custom_resource_provider.go @@ -0,0 +1,33 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type CustomResourceProviderId struct { + ResourceGroup string + Name string +} + +func CustomResourceProviderID(input string) (*CustomResourceProviderId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse Custom Resource Provider ID %q: %+v", input, err) + } + + service := CustomResourceProviderId{ + ResourceGroup: id.ResourceGroup, + } + + if service.Name, err = id.PopSegment("resourceproviders"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &service, nil +} diff --git a/azurerm/internal/services/customproviders/parse/custom_resource_provider_test.go b/azurerm/internal/services/customproviders/parse/custom_resource_provider_test.go new file mode 100644 index 000000000000..e9905caca01a --- /dev/null +++ b/azurerm/internal/services/customproviders/parse/custom_resource_provider_test.go @@ -0,0 +1,73 @@ +package parse + +import ( + "testing" +) + +func TestCustomResourceProviderId(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *CustomResourceProviderId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing Search Services Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.CustomProviders/resourceproviders/", + Expected: nil, + }, + { + Name: "Search Service ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.CustomProviders/resourceproviders/Provider1", + Expected: &CustomResourceProviderId{ + Name: "Provider1", + ResourceGroup: "resGroup1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.CustomProviders/ResourceProviders/Service1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := CustomResourceProviderID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/customproviders/registration.go b/azurerm/internal/services/customproviders/registration.go new file mode 100644 index 000000000000..d484dcd05582 --- /dev/null +++ b/azurerm/internal/services/customproviders/registration.go @@ -0,0 +1,31 @@ +package customproviders + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +type Registration struct{} + +// Name is the name of this Service +func (r Registration) Name() string { + return "Custom Providers" +} + +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Custom Providers", + } +} + +// SupportedDataSources returns the supported Data Sources supported by this Service +func (r Registration) SupportedDataSources() map[string]*schema.Resource { + return map[string]*schema.Resource{} +} + +// SupportedResources returns the supported Resources supported by this Service +func (r Registration) SupportedResources() map[string]*schema.Resource { + return map[string]*schema.Resource{ + "azurerm_custom_resource_provider": resourceArmCustomResourceProvider(), + } +} diff --git a/azurerm/internal/services/customproviders/resource_arm_custom_resource_provider.go b/azurerm/internal/services/customproviders/resource_arm_custom_resource_provider.go new file mode 100644 index 000000000000..4c3badb0f766 --- /dev/null +++ b/azurerm/internal/services/customproviders/resource_arm_custom_resource_provider.go @@ -0,0 +1,403 @@ +package customproviders + +import ( + "fmt" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azuread/azuread/helpers/validate" + "regexp" + "time" + + "github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders" + "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" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/customproviders/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmCustomResourceProvider() *schema.Resource { + return &schema.Resource{ + Create: resourceArmCustomResourceProviderCreateUpdate, + Read: resourceArmCustomResourceProviderRead, + Update: resourceArmCustomResourceProviderCreateUpdate, + Delete: resourceArmCustomResourceProviderDelete, + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.CustomResourceProviderID(id) + return err + }), + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateCustomResourceProviderName, + }, + + "location": azure.SchemaLocation(), + + "resource_group_name": azure.SchemaResourceGroupName(), + + "resource_type": { + Type: schema.TypeList, + Optional: true, + AtLeastOneOf: []string{"resource_type", "action"}, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.NoEmptyStrings, + }, + "endpoint": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.URLIsHTTPS, + }, + "routing_type": { + Type: schema.TypeString, + Optional: true, + Default: string(customproviders.ResourceTypeRoutingProxy), + ValidateFunc: validation.StringInSlice([]string{ + string(customproviders.ResourceTypeRoutingProxy), + string(customproviders.ResourceTypeRoutingProxyCache), + }, false), + }, + }, + }, + }, + + "action": { + Type: schema.TypeList, + Optional: true, + AtLeastOneOf: []string{"resource_type", "action"}, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.NoEmptyStrings, + }, + "endpoint": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.URLIsHTTPS, + }, + "routing_type": { + Type: schema.TypeString, + Optional: true, + Default: string(customproviders.ResourceTypeRoutingProxy), + ValidateFunc: validation.StringInSlice([]string{ + string(customproviders.ResourceTypeRoutingProxy), + }, false), + }, + }, + }, + }, + + "validation": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "specification": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.NoZeroValues, + }, + "type": { + Type: schema.TypeString, + Optional: true, + Default: string(customproviders.Swagger), + ValidateFunc: validation.StringInSlice([]string{ + string(customproviders.Swagger), + }, false), + }, + }, + }, + }, + + "tags": tags.ForceNewSchema(), + }, + } +} + +func resourceArmCustomResourceProviderCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).CustomProviders.CustomResourceProviderClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + name := d.Get("name").(string) + location := azure.NormalizeLocation(d.Get("location").(string)) + resourceGroup := d.Get("resource_group_name").(string) + t := d.Get("tags").(map[string]interface{}) + + /* + if features.ShouldResourcesBeImported() && d.IsNewResource() { + existing, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("checking for presence of existing Custom Resource Provider %q (Resource Group %q): %s", name, resourceGroup, err) + } + } + + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_custom_resource_provider", *existing.ID) + } + }*/ + + provider := customproviders.CustomRPManifest{ + CustomRPManifestProperties: &customproviders.CustomRPManifestProperties{ + ResourceTypes: expandCustomResourceProviderResourceType(d.Get("resource_type").([]interface{})), + Actions: expandCustomResourceProviderAction(d.Get("action").([]interface{})), + Validations: expandCustomResourceProviderValidation(d.Get("validation").([]interface{})), + }, + Location: &location, + Tags: tags.Expand(t), + } + + future, err := client.CreateOrUpdate(ctx, resourceGroup, name, provider) + if err != nil { + return fmt.Errorf("creating/updating Custom Resource Provider %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("waiting for completion of Custom Resource Provider %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + return fmt.Errorf("retrieving Custom Resource Provider %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + if resp.ID == nil { + return fmt.Errorf("cannot read Custom Resource Provider %q (Resource Group %q) ID", name, resourceGroup) + } + + d.SetId(*resp.ID) + return resourceArmCustomResourceProviderRead(d, meta) +} + +func resourceArmCustomResourceProviderRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).CustomProviders.CustomResourceProviderClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.CustomResourceProviderID(d.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + d.SetId("") + return nil + } + + return fmt.Errorf("retrieving Custom Resource Provider %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", id.ResourceGroup) + if location := resp.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + + if err := d.Set("resource_type", flattenCustomProviderResourceType(resp.ResourceTypes)); err != nil { + return fmt.Errorf("setting `resource_type`: %+v", err) + } + + if err := d.Set("action", flattenCustomProviderAction(resp.Actions)); err != nil { + return fmt.Errorf("setting `action`: %+v", err) + } + + if err := d.Set("validation", flattenCustomProviderValidation(resp.Validations)); err != nil { + return fmt.Errorf("setting `validation`: %+v", err) + } + + return tags.FlattenAndSet(d, resp.Tags) +} +func resourceArmCustomResourceProviderDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).CustomProviders.CustomResourceProviderClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.CustomResourceProviderID(d.Id()) + if err != nil { + return err + } + + future, err := client.Delete(ctx, id.ResourceGroup, id.Name) + if err != nil { + return fmt.Errorf("deleting Custom Resource Provider %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("waiting for deletion of Custom Resource Provider %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + } + + return nil +} + +func expandCustomResourceProviderResourceType(input []interface{}) *[]customproviders.CustomRPResourceTypeRouteDefinition { + if len(input) == 0 { + return nil + } + definitions := make([]customproviders.CustomRPResourceTypeRouteDefinition, 0) + + for _, v := range input { + if v == nil { + continue + } + + attrs := v.(map[string]interface{}) + definitions = append(definitions, customproviders.CustomRPResourceTypeRouteDefinition{ + RoutingType: customproviders.ResourceTypeRouting(attrs["routing_type"].(string)), + Name: utils.String(attrs["name"].(string)), + Endpoint: utils.String(attrs["endpoint"].(string)), + }) + } + + return &definitions +} + +func flattenCustomProviderResourceType(input *[]customproviders.CustomRPResourceTypeRouteDefinition) []interface{} { + if input == nil { + return []interface{}{} + } + + definitions := make([]interface{}, 0) + for _, v := range *input { + definition := make(map[string]interface{}, 0) + + definition["routing_type"] = string(v.RoutingType) + + if v.Name != nil { + definition["name"] = *v.Name + } + + if v.Endpoint != nil { + definition["endpoint"] = *v.Endpoint + } + + definitions = append(definitions, definition) + } + return definitions +} + +func expandCustomResourceProviderAction(input []interface{}) *[]customproviders.CustomRPActionRouteDefinition { + if len(input) == 0 { + return nil + } + definitions := make([]customproviders.CustomRPActionRouteDefinition, 0) + + for _, v := range input { + if v == nil { + continue + } + + attrs := v.(map[string]interface{}) + definitions = append(definitions, customproviders.CustomRPActionRouteDefinition{ + RoutingType: customproviders.ActionRouting(attrs["routing_type"].(string)), + Name: utils.String(attrs["name"].(string)), + Endpoint: utils.String(attrs["endpoint"].(string)), + }) + } + + return &definitions +} + +func flattenCustomProviderAction(input *[]customproviders.CustomRPActionRouteDefinition) []interface{} { + if input == nil { + return []interface{}{} + } + + definitions := make([]interface{}, 0) + for _, v := range *input { + definition := make(map[string]interface{}, 0) + + definition["routing_type"] = string(v.RoutingType) + + if v.Name != nil { + definition["name"] = *v.Name + } + + if v.Endpoint != nil { + definition["endpoint"] = *v.Endpoint + } + + definitions = append(definitions, definition) + } + return definitions +} + +func expandCustomResourceProviderValidation(input []interface{}) *[]customproviders.CustomRPValidations { + if len(input) == 0 { + return nil + } + + validations := make([]customproviders.CustomRPValidations, 0) + + for _, v := range input { + if v == nil { + continue + } + + attrs := v.(map[string]interface{}) + validations = append(validations, customproviders.CustomRPValidations{ + ValidationType: customproviders.ValidationType(attrs["type"].(string)), + Specification: utils.String(attrs["specification"].(string)), + }) + } + + return &validations +} + +func flattenCustomProviderValidation(input *[]customproviders.CustomRPValidations) []interface{} { + if input == nil { + return []interface{}{} + } + + validations := make([]interface{}, 0) + for _, v := range *input { + validation := make(map[string]interface{}, 0) + + validation["type"] = string(v.ValidationType) + + if v.Specification != nil { + validation["specification"] = *v.Specification + } + + validations = append(validations, validation) + } + return validations +} + +func validateCustomResourceProviderName(v interface{}, k string) (warnings []string, errors []error) { + name := v.(string) + + if regexp.MustCompile(`^[\s]+$`).MatchString(name) { + errors = append(errors, fmt.Errorf("%q must not consist of whitespace", k)) + } + + if !regexp.MustCompile(`^[a-zA-Z0-9_]+$`).MatchString(name) { + errors = append(errors, fmt.Errorf("%q may only contain letters and digits: %q", k, name)) + } + + if len(name) < 3 || len(name) > 63 { + errors = append(errors, fmt.Errorf("%q must be (inclusive) between 3 and 63 characters long but is %d", k, len(name))) + } + + return warnings, errors +} diff --git a/azurerm/internal/services/customproviders/tests/resource_arm_custom_resource_provider_test.go b/azurerm/internal/services/customproviders/tests/resource_arm_custom_resource_provider_test.go new file mode 100644 index 000000000000..2f3f05de8006 --- /dev/null +++ b/azurerm/internal/services/customproviders/tests/resource_arm_custom_resource_provider_test.go @@ -0,0 +1,251 @@ +package tests + +import ( + "fmt" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/customproviders/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" + "net/http" + "testing" +) + +func TestAccAzureRMCustomResourceProvider_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_custom_resource_provider", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCustomResourceProviderDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCustomResourceProvider_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMCustomResourceProviderExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCustomResourceProvider_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_custom_resource_provider", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCustomResourceProviderDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCustomResourceProvider_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMCustomResourceProviderExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMCustomResourceProvider_complete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMCustomResourceProviderExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMCustomResourceProvider_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMCustomResourceProviderExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCustomResourceProvider_action(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_custom_resource_provider", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCustomResourceProviderDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCustomResourceProvider_action(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMCustomResourceProviderExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMCustomResourceProvider_actionUpdate(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMCustomResourceProviderExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMCustomResourceProvider_action(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMCustomResourceProviderExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func testCheckAzureRMCustomResourceProviderExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).CustomProviders.CustomResourceProviderClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + id, err := parse.CustomResourceProviderID(rs.Primary.ID) + if err != nil { + return err + } + + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) + if err != nil { + return fmt.Errorf("Bad: Get on CustomResourceProviderClient: %+v", err) + } + + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Custom Resource Provider %q (resource group: %q) does not exist", id.Name, id.ResourceGroup) + } + + return nil + } +} + +func testCheckAzureRMCustomResourceProviderDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).CustomProviders.CustomResourceProviderClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_custom_resource_provider" { + continue + } + + id, err := parse.CustomResourceProviderID(rs.Primary.ID) + if err != nil { + return err + } + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) + + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Custom Resource Provider still exists: %q", id.Name) + } + } + + return nil +} + +func testAccAzureRMCustomResourceProvider_basic(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} +resource "azurerm_resource_group" "test" { + name = "acctestRG-cr-%d" + location = "%s" +} +resource "azurerm_custom_resource_provider" "test" { + name = "accTEst_saa%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + resource_type { + name = "dEf1" + endpoint = "https://testendpoint.com/" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func testAccAzureRMCustomResourceProvider_complete(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} +resource "azurerm_resource_group" "test" { + name = "acctestRG-mr-%d" + location = "%s" +} +resource "azurerm_custom_resource_provider" "test" { + name = "accTEst_saa%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + resource_type { + name = "dEf1" + endpoint = "https://testendpoint.com/" + } + + action { + name = "dEf2" + endpoint = "https://example.com/" + } + + validation { + specification = "https://raw.githubusercontent.com/Azure/azure-custom-providers/master/CustomRPWithSwagger/Artifacts/Swagger/pingaction.json" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func testAccAzureRMCustomResourceProvider_action(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} +resource "azurerm_resource_group" "test" { + name = "acctestRG-cr-%d" + location = "%s" +} +resource "azurerm_custom_resource_provider" "test" { + name = "accTEst_saa%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + action { + name = "dEf1" + endpoint = "https://testendpoint.com/" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func testAccAzureRMCustomResourceProvider_actionUpdate(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} +resource "azurerm_resource_group" "test" { + name = "acctestRG-cr-%d" + location = "%s" +} +resource "azurerm_custom_resource_provider" "test" { + name = "accTEst_saa%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + action { + name = "dEf2" + endpoint = "https://example.com/" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/associations.go b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/associations.go new file mode 100644 index 000000000000..0e03c8e72b78 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/associations.go @@ -0,0 +1,385 @@ +package customproviders + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// AssociationsClient is the allows extension of ARM control plane with custom resource providers. +type AssociationsClient struct { + BaseClient +} + +// NewAssociationsClient creates an instance of the AssociationsClient client. +func NewAssociationsClient(subscriptionID string) AssociationsClient { + return NewAssociationsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewAssociationsClientWithBaseURI creates an instance of the AssociationsClient client using a custom endpoint. Use +// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewAssociationsClientWithBaseURI(baseURI string, subscriptionID string) AssociationsClient { + return AssociationsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate create or update an association. +// Parameters: +// scope - the scope of the association. The scope can be any valid REST resource instance. For example, use +// '/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.Compute/virtualMachines/{vm-name}' +// for a virtual machine resource. +// associationName - the name of the association. +// association - the parameters required to create or update an association. +func (client AssociationsClient) CreateOrUpdate(ctx context.Context, scope string, associationName string, association Association) (result AssociationsCreateOrUpdateFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssociationsClient.CreateOrUpdate") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.CreateOrUpdatePreparer(ctx, scope, associationName, association) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = client.CreateOrUpdateSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "CreateOrUpdate", result.Response(), "Failure sending request") + return + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client AssociationsClient) CreateOrUpdatePreparer(ctx context.Context, scope string, associationName string, association Association) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "associationName": autorest.Encode("path", associationName), + "scope": scope, + } + + const APIVersion = "2018-09-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + association.ID = nil + association.Name = nil + association.Type = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{scope}/providers/Microsoft.CustomProviders/associations/{associationName}", pathParameters), + autorest.WithJSON(association), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client AssociationsClient) CreateOrUpdateSender(req *http.Request) (future AssociationsCreateOrUpdateFuture, err error) { + var resp *http.Response + resp, err = client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if err != nil { + return + } + future.Future, err = azure.NewFutureFromResponse(resp) + return +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client AssociationsClient) CreateOrUpdateResponder(resp *http.Response) (result Association, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete delete an association. +// Parameters: +// scope - the scope of the association. +// associationName - the name of the association. +func (client AssociationsClient) Delete(ctx context.Context, scope string, associationName string) (result AssociationsDeleteFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssociationsClient.Delete") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.DeletePreparer(ctx, scope, associationName) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = client.DeleteSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "Delete", result.Response(), "Failure sending request") + return + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client AssociationsClient) DeletePreparer(ctx context.Context, scope string, associationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "associationName": autorest.Encode("path", associationName), + "scope": scope, + } + + const APIVersion = "2018-09-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{scope}/providers/Microsoft.CustomProviders/associations/{associationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client AssociationsClient) DeleteSender(req *http.Request) (future AssociationsDeleteFuture, err error) { + var resp *http.Response + resp, err = client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if err != nil { + return + } + future.Future, err = azure.NewFutureFromResponse(resp) + return +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client AssociationsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get get an association. +// Parameters: +// scope - the scope of the association. +// associationName - the name of the association. +func (client AssociationsClient) Get(ctx context.Context, scope string, associationName string) (result Association, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssociationsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, scope, associationName) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client AssociationsClient) GetPreparer(ctx context.Context, scope string, associationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "associationName": autorest.Encode("path", associationName), + "scope": scope, + } + + const APIVersion = "2018-09-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{scope}/providers/Microsoft.CustomProviders/associations/{associationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client AssociationsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client AssociationsClient) GetResponder(resp *http.Response) (result Association, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListAll gets all association for the given scope. +// Parameters: +// scope - the scope of the association. +func (client AssociationsClient) ListAll(ctx context.Context, scope string) (result AssociationsListPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssociationsClient.ListAll") + defer func() { + sc := -1 + if result.al.Response.Response != nil { + sc = result.al.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listAllNextResults + req, err := client.ListAllPreparer(ctx, scope) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "ListAll", nil, "Failure preparing request") + return + } + + resp, err := client.ListAllSender(req) + if err != nil { + result.al.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "ListAll", resp, "Failure sending request") + return + } + + result.al, err = client.ListAllResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "ListAll", resp, "Failure responding to request") + } + + return +} + +// ListAllPreparer prepares the ListAll request. +func (client AssociationsClient) ListAllPreparer(ctx context.Context, scope string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "scope": scope, + } + + const APIVersion = "2018-09-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{scope}/providers/Microsoft.CustomProviders/associations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListAllSender sends the ListAll request. The method will close the +// http.Response Body if it receives an error. +func (client AssociationsClient) ListAllSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListAllResponder handles the response to the ListAll request. The method always +// closes the http.Response Body. +func (client AssociationsClient) ListAllResponder(resp *http.Response) (result AssociationsList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listAllNextResults retrieves the next set of results, if any. +func (client AssociationsClient) listAllNextResults(ctx context.Context, lastResults AssociationsList) (result AssociationsList, err error) { + req, err := lastResults.associationsListPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "listAllNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListAllSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "listAllNextResults", resp, "Failure sending next results request") + } + result, err = client.ListAllResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsClient", "listAllNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListAllComplete enumerates all values, automatically crossing page boundaries as required. +func (client AssociationsClient) ListAllComplete(ctx context.Context, scope string) (result AssociationsListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssociationsClient.ListAll") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListAll(ctx, scope) + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/client.go b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/client.go new file mode 100644 index 000000000000..777132e13257 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/client.go @@ -0,0 +1,52 @@ +// Package customproviders implements the Azure ARM Customproviders service API version 2018-09-01-preview. +// +// Allows extension of ARM control plane with custom resource providers. +package customproviders + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" +) + +const ( + // DefaultBaseURI is the default URI used for the service Customproviders + DefaultBaseURI = "https://management.azure.com" +) + +// BaseClient is the base client for Customproviders. +type BaseClient struct { + autorest.Client + BaseURI string + SubscriptionID string +} + +// New creates an instance of the BaseClient client. +func New(subscriptionID string) BaseClient { + return NewWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint. Use this when interacting with +// an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { + return BaseClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + BaseURI: baseURI, + SubscriptionID: subscriptionID, + } +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/customresourceprovider.go b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/customresourceprovider.go new file mode 100644 index 000000000000..017c281c71a7 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/customresourceprovider.go @@ -0,0 +1,603 @@ +package customproviders + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// CustomResourceProviderClient is the allows extension of ARM control plane with custom resource providers. +type CustomResourceProviderClient struct { + BaseClient +} + +// NewCustomResourceProviderClient creates an instance of the CustomResourceProviderClient client. +func NewCustomResourceProviderClient(subscriptionID string) CustomResourceProviderClient { + return NewCustomResourceProviderClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewCustomResourceProviderClientWithBaseURI creates an instance of the CustomResourceProviderClient client using a +// custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, +// Azure stack). +func NewCustomResourceProviderClientWithBaseURI(baseURI string, subscriptionID string) CustomResourceProviderClient { + return CustomResourceProviderClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate creates or updates the custom resource provider. +// Parameters: +// resourceGroupName - the name of the resource group. +// resourceProviderName - the name of the resource provider. +// resourceProvider - the parameters required to create or update a custom resource provider definition. +func (client CustomResourceProviderClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, resourceProviderName string, resourceProvider CustomRPManifest) (result CustomResourceProviderCreateOrUpdateFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/CustomResourceProviderClient.CreateOrUpdate") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceProviderName, + Constraints: []validation.Constraint{{Target: "resourceProviderName", Name: validation.MaxLength, Rule: 64, Chain: nil}, + {Target: "resourceProviderName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil { + return result, validation.NewError("customproviders.CustomResourceProviderClient", "CreateOrUpdate", err.Error()) + } + + req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, resourceProviderName, resourceProvider) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = client.CreateOrUpdateSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "CreateOrUpdate", result.Response(), "Failure sending request") + return + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client CustomResourceProviderClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, resourceProviderName string, resourceProvider CustomRPManifest) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceProviderName": autorest.Encode("path", resourceProviderName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2018-09-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}", pathParameters), + autorest.WithJSON(resourceProvider), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client CustomResourceProviderClient) CreateOrUpdateSender(req *http.Request) (future CustomResourceProviderCreateOrUpdateFuture, err error) { + var resp *http.Response + resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) + if err != nil { + return + } + future.Future, err = azure.NewFutureFromResponse(resp) + return +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client CustomResourceProviderClient) CreateOrUpdateResponder(resp *http.Response) (result CustomRPManifest, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete deletes the custom resource provider. +// Parameters: +// resourceGroupName - the name of the resource group. +// resourceProviderName - the name of the resource provider. +func (client CustomResourceProviderClient) Delete(ctx context.Context, resourceGroupName string, resourceProviderName string) (result CustomResourceProviderDeleteFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/CustomResourceProviderClient.Delete") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceProviderName, + Constraints: []validation.Constraint{{Target: "resourceProviderName", Name: validation.MaxLength, Rule: 64, Chain: nil}, + {Target: "resourceProviderName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil { + return result, validation.NewError("customproviders.CustomResourceProviderClient", "Delete", err.Error()) + } + + req, err := client.DeletePreparer(ctx, resourceGroupName, resourceProviderName) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = client.DeleteSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "Delete", result.Response(), "Failure sending request") + return + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client CustomResourceProviderClient) DeletePreparer(ctx context.Context, resourceGroupName string, resourceProviderName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceProviderName": autorest.Encode("path", resourceProviderName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2018-09-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client CustomResourceProviderClient) DeleteSender(req *http.Request) (future CustomResourceProviderDeleteFuture, err error) { + var resp *http.Response + resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) + if err != nil { + return + } + future.Future, err = azure.NewFutureFromResponse(resp) + return +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client CustomResourceProviderClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get gets the custom resource provider manifest. +// Parameters: +// resourceGroupName - the name of the resource group. +// resourceProviderName - the name of the resource provider. +func (client CustomResourceProviderClient) Get(ctx context.Context, resourceGroupName string, resourceProviderName string) (result CustomRPManifest, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/CustomResourceProviderClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceProviderName, + Constraints: []validation.Constraint{{Target: "resourceProviderName", Name: validation.MaxLength, Rule: 64, Chain: nil}, + {Target: "resourceProviderName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil { + return result, validation.NewError("customproviders.CustomResourceProviderClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, resourceGroupName, resourceProviderName) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client CustomResourceProviderClient) GetPreparer(ctx context.Context, resourceGroupName string, resourceProviderName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceProviderName": autorest.Encode("path", resourceProviderName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2018-09-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client CustomResourceProviderClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client CustomResourceProviderClient) GetResponder(resp *http.Response) (result CustomRPManifest, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByResourceGroup gets all the custom resource providers within a resource group. +// Parameters: +// resourceGroupName - the name of the resource group. +func (client CustomResourceProviderClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result ListByCustomRPManifestPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/CustomResourceProviderClient.ListByResourceGroup") + defer func() { + sc := -1 + if result.lbcrm.Response.Response != nil { + sc = result.lbcrm.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listByResourceGroupNextResults + req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.lbcrm.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "ListByResourceGroup", resp, "Failure sending request") + return + } + + result.lbcrm, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "ListByResourceGroup", resp, "Failure responding to request") + } + + return +} + +// ListByResourceGroupPreparer prepares the ListByResourceGroup request. +func (client CustomResourceProviderClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2018-09-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client CustomResourceProviderClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (client CustomResourceProviderClient) ListByResourceGroupResponder(resp *http.Response) (result ListByCustomRPManifest, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listByResourceGroupNextResults retrieves the next set of results, if any. +func (client CustomResourceProviderClient) listByResourceGroupNextResults(ctx context.Context, lastResults ListByCustomRPManifest) (result ListByCustomRPManifest, err error) { + req, err := lastResults.listByCustomRPManifestPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "listByResourceGroupNextResults", resp, "Failure sending next results request") + } + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. +func (client CustomResourceProviderClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result ListByCustomRPManifestIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/CustomResourceProviderClient.ListByResourceGroup") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListByResourceGroup(ctx, resourceGroupName) + return +} + +// ListBySubscription gets all the custom resource providers within a subscription. +func (client CustomResourceProviderClient) ListBySubscription(ctx context.Context) (result ListByCustomRPManifestPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/CustomResourceProviderClient.ListBySubscription") + defer func() { + sc := -1 + if result.lbcrm.Response.Response != nil { + sc = result.lbcrm.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listBySubscriptionNextResults + req, err := client.ListBySubscriptionPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp, err := client.ListBySubscriptionSender(req) + if err != nil { + result.lbcrm.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "ListBySubscription", resp, "Failure sending request") + return + } + + result.lbcrm, err = client.ListBySubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "ListBySubscription", resp, "Failure responding to request") + } + + return +} + +// ListBySubscriptionPreparer prepares the ListBySubscription request. +func (client CustomResourceProviderClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2018-09-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.CustomProviders/resourceProviders", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListBySubscriptionSender sends the ListBySubscription request. The method will close the +// http.Response Body if it receives an error. +func (client CustomResourceProviderClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (client CustomResourceProviderClient) ListBySubscriptionResponder(resp *http.Response) (result ListByCustomRPManifest, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listBySubscriptionNextResults retrieves the next set of results, if any. +func (client CustomResourceProviderClient) listBySubscriptionNextResults(ctx context.Context, lastResults ListByCustomRPManifest) (result ListByCustomRPManifest, err error) { + req, err := lastResults.listByCustomRPManifestPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "listBySubscriptionNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListBySubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "listBySubscriptionNextResults", resp, "Failure sending next results request") + } + result, err = client.ListBySubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "listBySubscriptionNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListBySubscriptionComplete enumerates all values, automatically crossing page boundaries as required. +func (client CustomResourceProviderClient) ListBySubscriptionComplete(ctx context.Context) (result ListByCustomRPManifestIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/CustomResourceProviderClient.ListBySubscription") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListBySubscription(ctx) + return +} + +// Update updates an existing custom resource provider. The only value that can be updated via PATCH currently is the +// tags. +// Parameters: +// resourceGroupName - the name of the resource group. +// resourceProviderName - the name of the resource provider. +// patchableResource - the updatable fields of a custom resource provider. +func (client CustomResourceProviderClient) Update(ctx context.Context, resourceGroupName string, resourceProviderName string, patchableResource ResourceProvidersUpdate) (result CustomRPManifest, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/CustomResourceProviderClient.Update") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceProviderName, + Constraints: []validation.Constraint{{Target: "resourceProviderName", Name: validation.MaxLength, Rule: 64, Chain: nil}, + {Target: "resourceProviderName", Name: validation.MinLength, Rule: 3, Chain: nil}}}}); err != nil { + return result, validation.NewError("customproviders.CustomResourceProviderClient", "Update", err.Error()) + } + + req, err := client.UpdatePreparer(ctx, resourceGroupName, resourceProviderName, patchableResource) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderClient", "Update", resp, "Failure responding to request") + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client CustomResourceProviderClient) UpdatePreparer(ctx context.Context, resourceGroupName string, resourceProviderName string, patchableResource ResourceProvidersUpdate) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceProviderName": autorest.Encode("path", resourceProviderName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2018-09-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}", pathParameters), + autorest.WithJSON(patchableResource), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client CustomResourceProviderClient) UpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client CustomResourceProviderClient) UpdateResponder(resp *http.Response) (result CustomRPManifest, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/models.go b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/models.go new file mode 100644 index 000000000000..b29e63aaef12 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/models.go @@ -0,0 +1,946 @@ +package customproviders + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "encoding/json" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/to" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// The package's fully qualified name. +const fqdn = "github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders" + +// ActionRouting enumerates the values for action routing. +type ActionRouting string + +const ( + // Proxy ... + Proxy ActionRouting = "Proxy" +) + +// PossibleActionRoutingValues returns an array of possible values for the ActionRouting const type. +func PossibleActionRoutingValues() []ActionRouting { + return []ActionRouting{Proxy} +} + +// ProvisioningState enumerates the values for provisioning state. +type ProvisioningState string + +const ( + // Accepted ... + Accepted ProvisioningState = "Accepted" + // Deleting ... + Deleting ProvisioningState = "Deleting" + // Failed ... + Failed ProvisioningState = "Failed" + // Running ... + Running ProvisioningState = "Running" + // Succeeded ... + Succeeded ProvisioningState = "Succeeded" +) + +// PossibleProvisioningStateValues returns an array of possible values for the ProvisioningState const type. +func PossibleProvisioningStateValues() []ProvisioningState { + return []ProvisioningState{Accepted, Deleting, Failed, Running, Succeeded} +} + +// ResourceTypeRouting enumerates the values for resource type routing. +type ResourceTypeRouting string + +const ( + // ResourceTypeRoutingProxy ... + ResourceTypeRoutingProxy ResourceTypeRouting = "Proxy" + // ResourceTypeRoutingProxyCache ... + ResourceTypeRoutingProxyCache ResourceTypeRouting = "Proxy,Cache" +) + +// PossibleResourceTypeRoutingValues returns an array of possible values for the ResourceTypeRouting const type. +func PossibleResourceTypeRoutingValues() []ResourceTypeRouting { + return []ResourceTypeRouting{ResourceTypeRoutingProxy, ResourceTypeRoutingProxyCache} +} + +// ValidationType enumerates the values for validation type. +type ValidationType string + +const ( + // Swagger ... + Swagger ValidationType = "Swagger" +) + +// PossibleValidationTypeValues returns an array of possible values for the ValidationType const type. +func PossibleValidationTypeValues() []ValidationType { + return []ValidationType{Swagger} +} + +// Association the resource definition of this association. +type Association struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; The association id. + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The association name. + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The association type. + Type *string `json:"type,omitempty"` + // AssociationProperties - The properties of the association. + *AssociationProperties `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for Association. +func (a Association) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if a.AssociationProperties != nil { + objectMap["properties"] = a.AssociationProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for Association struct. +func (a *Association) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + a.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + a.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + a.Type = &typeVar + } + case "properties": + if v != nil { + var associationProperties AssociationProperties + err = json.Unmarshal(*v, &associationProperties) + if err != nil { + return err + } + a.AssociationProperties = &associationProperties + } + } + } + + return nil +} + +// AssociationProperties the properties of the association. +type AssociationProperties struct { + // TargetResourceID - The REST resource instance of the target resource for this association. + TargetResourceID *string `json:"targetResourceId,omitempty"` + // ProvisioningState - READ-ONLY; The provisioning state of the association. Possible values include: 'Accepted', 'Deleting', 'Running', 'Succeeded', 'Failed' + ProvisioningState ProvisioningState `json:"provisioningState,omitempty"` +} + +// AssociationsCreateOrUpdateFuture an abstraction for monitoring and retrieving the results of a +// long-running operation. +type AssociationsCreateOrUpdateFuture struct { + azure.Future +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future *AssociationsCreateOrUpdateFuture) Result(client AssociationsClient) (a Association, err error) { + var done bool + done, err = future.DoneWithContext(context.Background(), client) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsCreateOrUpdateFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("customproviders.AssociationsCreateOrUpdateFuture") + return + } + sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if a.Response.Response, err = future.GetResult(sender); err == nil && a.Response.Response.StatusCode != http.StatusNoContent { + a, err = client.CreateOrUpdateResponder(a.Response.Response) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsCreateOrUpdateFuture", "Result", a.Response.Response, "Failure responding to request") + } + } + return +} + +// AssociationsDeleteFuture an abstraction for monitoring and retrieving the results of a long-running +// operation. +type AssociationsDeleteFuture struct { + azure.Future +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future *AssociationsDeleteFuture) Result(client AssociationsClient) (ar autorest.Response, err error) { + var done bool + done, err = future.DoneWithContext(context.Background(), client) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.AssociationsDeleteFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("customproviders.AssociationsDeleteFuture") + return + } + ar.Response = future.Response() + return +} + +// AssociationsList list of associations. +type AssociationsList struct { + autorest.Response `json:"-"` + // Value - The array of associations. + Value *[]Association `json:"value,omitempty"` + // NextLink - The URL to use for getting the next set of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// AssociationsListIterator provides access to a complete listing of Association values. +type AssociationsListIterator struct { + i int + page AssociationsListPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *AssociationsListIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssociationsListIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *AssociationsListIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter AssociationsListIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter AssociationsListIterator) Response() AssociationsList { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter AssociationsListIterator) Value() Association { + if !iter.page.NotDone() { + return Association{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the AssociationsListIterator type. +func NewAssociationsListIterator(page AssociationsListPage) AssociationsListIterator { + return AssociationsListIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (al AssociationsList) IsEmpty() bool { + return al.Value == nil || len(*al.Value) == 0 +} + +// associationsListPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (al AssociationsList) associationsListPreparer(ctx context.Context) (*http.Request, error) { + if al.NextLink == nil || len(to.String(al.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(al.NextLink))) +} + +// AssociationsListPage contains a page of Association values. +type AssociationsListPage struct { + fn func(context.Context, AssociationsList) (AssociationsList, error) + al AssociationsList +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *AssociationsListPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssociationsListPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + next, err := page.fn(ctx, page.al) + if err != nil { + return err + } + page.al = next + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *AssociationsListPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page AssociationsListPage) NotDone() bool { + return !page.al.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page AssociationsListPage) Response() AssociationsList { + return page.al +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page AssociationsListPage) Values() []Association { + if page.al.IsEmpty() { + return nil + } + return *page.al.Value +} + +// Creates a new instance of the AssociationsListPage type. +func NewAssociationsListPage(getNextPage func(context.Context, AssociationsList) (AssociationsList, error)) AssociationsListPage { + return AssociationsListPage{fn: getNextPage} +} + +// CustomResourceProviderCreateOrUpdateFuture an abstraction for monitoring and retrieving the results of a +// long-running operation. +type CustomResourceProviderCreateOrUpdateFuture struct { + azure.Future +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future *CustomResourceProviderCreateOrUpdateFuture) Result(client CustomResourceProviderClient) (crm CustomRPManifest, err error) { + var done bool + done, err = future.DoneWithContext(context.Background(), client) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderCreateOrUpdateFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("customproviders.CustomResourceProviderCreateOrUpdateFuture") + return + } + sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if crm.Response.Response, err = future.GetResult(sender); err == nil && crm.Response.Response.StatusCode != http.StatusNoContent { + crm, err = client.CreateOrUpdateResponder(crm.Response.Response) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderCreateOrUpdateFuture", "Result", crm.Response.Response, "Failure responding to request") + } + } + return +} + +// CustomResourceProviderDeleteFuture an abstraction for monitoring and retrieving the results of a +// long-running operation. +type CustomResourceProviderDeleteFuture struct { + azure.Future +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future *CustomResourceProviderDeleteFuture) Result(client CustomResourceProviderClient) (ar autorest.Response, err error) { + var done bool + done, err = future.DoneWithContext(context.Background(), client) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.CustomResourceProviderDeleteFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("customproviders.CustomResourceProviderDeleteFuture") + return + } + ar.Response = future.Response() + return +} + +// CustomRPActionRouteDefinition the route definition for an action implemented by the custom resource +// provider. +type CustomRPActionRouteDefinition struct { + // RoutingType - The routing types that are supported for action requests. Possible values include: 'Proxy' + RoutingType ActionRouting `json:"routingType,omitempty"` + // Name - The name of the route definition. This becomes the name for the ARM extension (e.g. '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/{name}') + Name *string `json:"name,omitempty"` + // Endpoint - The route definition endpoint URI that the custom resource provider will proxy requests to. This can be in the form of a flat URI (e.g. 'https://testendpoint/') or can specify to route via a path (e.g. 'https://testendpoint/{requestPath}') + Endpoint *string `json:"endpoint,omitempty"` +} + +// CustomRPManifest a manifest file that defines the custom resource provider resources. +type CustomRPManifest struct { + autorest.Response `json:"-"` + // CustomRPManifestProperties - The manifest for the custom resource provider + *CustomRPManifestProperties `json:"properties,omitempty"` + // ID - READ-ONLY; Resource Id + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; Resource name + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; Resource type + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Tags - Resource tags + Tags map[string]*string `json:"tags"` +} + +// MarshalJSON is the custom marshaler for CustomRPManifest. +func (crm CustomRPManifest) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if crm.CustomRPManifestProperties != nil { + objectMap["properties"] = crm.CustomRPManifestProperties + } + if crm.Location != nil { + objectMap["location"] = crm.Location + } + if crm.Tags != nil { + objectMap["tags"] = crm.Tags + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for CustomRPManifest struct. +func (crm *CustomRPManifest) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var customRPManifestProperties CustomRPManifestProperties + err = json.Unmarshal(*v, &customRPManifestProperties) + if err != nil { + return err + } + crm.CustomRPManifestProperties = &customRPManifestProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + crm.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + crm.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + crm.Type = &typeVar + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + crm.Location = &location + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + crm.Tags = tags + } + } + } + + return nil +} + +// CustomRPManifestProperties the manifest for the custom resource provider +type CustomRPManifestProperties struct { + // Actions - A list of actions that the custom resource provider implements. + Actions *[]CustomRPActionRouteDefinition `json:"actions,omitempty"` + // ResourceTypes - A list of resource types that the custom resource provider implements. + ResourceTypes *[]CustomRPResourceTypeRouteDefinition `json:"resourceTypes,omitempty"` + // Validations - A list of validations to run on the custom resource provider's requests. + Validations *[]CustomRPValidations `json:"validations,omitempty"` + // ProvisioningState - READ-ONLY; The provisioning state of the resource provider. Possible values include: 'Accepted', 'Deleting', 'Running', 'Succeeded', 'Failed' + ProvisioningState ProvisioningState `json:"provisioningState,omitempty"` +} + +// CustomRPResourceTypeRouteDefinition the route definition for a resource implemented by the custom +// resource provider. +type CustomRPResourceTypeRouteDefinition struct { + // RoutingType - The routing types that are supported for resource requests. Possible values include: 'ResourceTypeRoutingProxy', 'ResourceTypeRoutingProxyCache' + RoutingType ResourceTypeRouting `json:"routingType,omitempty"` + // Name - The name of the route definition. This becomes the name for the ARM extension (e.g. '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/{name}') + Name *string `json:"name,omitempty"` + // Endpoint - The route definition endpoint URI that the custom resource provider will proxy requests to. This can be in the form of a flat URI (e.g. 'https://testendpoint/') or can specify to route via a path (e.g. 'https://testendpoint/{requestPath}') + Endpoint *string `json:"endpoint,omitempty"` +} + +// CustomRPRouteDefinition a route definition that defines an action or resource that can be interacted +// with through the custom resource provider. +type CustomRPRouteDefinition struct { + // Name - The name of the route definition. This becomes the name for the ARM extension (e.g. '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/{name}') + Name *string `json:"name,omitempty"` + // Endpoint - The route definition endpoint URI that the custom resource provider will proxy requests to. This can be in the form of a flat URI (e.g. 'https://testendpoint/') or can specify to route via a path (e.g. 'https://testendpoint/{requestPath}') + Endpoint *string `json:"endpoint,omitempty"` +} + +// CustomRPValidations a validation to apply on custom resource provider requests. +type CustomRPValidations struct { + // ValidationType - The type of validation to run against a matching request. Possible values include: 'Swagger' + ValidationType ValidationType `json:"validationType,omitempty"` + // Specification - A link to the validation specification. The specification must be hosted on raw.githubusercontent.com. + Specification *string `json:"specification,omitempty"` +} + +// ErrorDefinition error definition. +type ErrorDefinition struct { + // Code - READ-ONLY; Service specific error code which serves as the substatus for the HTTP error code. + Code *string `json:"code,omitempty"` + // Message - READ-ONLY; Description of the error. + Message *string `json:"message,omitempty"` + // Details - READ-ONLY; Internal error details. + Details *[]ErrorDefinition `json:"details,omitempty"` +} + +// ErrorResponse error response. +type ErrorResponse struct { + // Error - The error details. + Error *ErrorDefinition `json:"error,omitempty"` +} + +// ListByCustomRPManifest list of custom resource providers. +type ListByCustomRPManifest struct { + autorest.Response `json:"-"` + // Value - The array of custom resource provider manifests. + Value *[]CustomRPManifest `json:"value,omitempty"` + // NextLink - The URL to use for getting the next set of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// ListByCustomRPManifestIterator provides access to a complete listing of CustomRPManifest values. +type ListByCustomRPManifestIterator struct { + i int + page ListByCustomRPManifestPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *ListByCustomRPManifestIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ListByCustomRPManifestIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *ListByCustomRPManifestIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter ListByCustomRPManifestIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter ListByCustomRPManifestIterator) Response() ListByCustomRPManifest { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter ListByCustomRPManifestIterator) Value() CustomRPManifest { + if !iter.page.NotDone() { + return CustomRPManifest{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the ListByCustomRPManifestIterator type. +func NewListByCustomRPManifestIterator(page ListByCustomRPManifestPage) ListByCustomRPManifestIterator { + return ListByCustomRPManifestIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (lbcrm ListByCustomRPManifest) IsEmpty() bool { + return lbcrm.Value == nil || len(*lbcrm.Value) == 0 +} + +// listByCustomRPManifestPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (lbcrm ListByCustomRPManifest) listByCustomRPManifestPreparer(ctx context.Context) (*http.Request, error) { + if lbcrm.NextLink == nil || len(to.String(lbcrm.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(lbcrm.NextLink))) +} + +// ListByCustomRPManifestPage contains a page of CustomRPManifest values. +type ListByCustomRPManifestPage struct { + fn func(context.Context, ListByCustomRPManifest) (ListByCustomRPManifest, error) + lbcrm ListByCustomRPManifest +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *ListByCustomRPManifestPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ListByCustomRPManifestPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + next, err := page.fn(ctx, page.lbcrm) + if err != nil { + return err + } + page.lbcrm = next + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *ListByCustomRPManifestPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page ListByCustomRPManifestPage) NotDone() bool { + return !page.lbcrm.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page ListByCustomRPManifestPage) Response() ListByCustomRPManifest { + return page.lbcrm +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page ListByCustomRPManifestPage) Values() []CustomRPManifest { + if page.lbcrm.IsEmpty() { + return nil + } + return *page.lbcrm.Value +} + +// Creates a new instance of the ListByCustomRPManifestPage type. +func NewListByCustomRPManifestPage(getNextPage func(context.Context, ListByCustomRPManifest) (ListByCustomRPManifest, error)) ListByCustomRPManifestPage { + return ListByCustomRPManifestPage{fn: getNextPage} +} + +// Resource the resource definition. +type Resource struct { + // ID - READ-ONLY; Resource Id + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; Resource name + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; Resource type + Type *string `json:"type,omitempty"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Tags - Resource tags + Tags map[string]*string `json:"tags"` +} + +// MarshalJSON is the custom marshaler for Resource. +func (r Resource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if r.Location != nil { + objectMap["location"] = r.Location + } + if r.Tags != nil { + objectMap["tags"] = r.Tags + } + return json.Marshal(objectMap) +} + +// ResourceProviderOperation supported operations of this resource provider. +type ResourceProviderOperation struct { + // Name - Operation name, in format of {provider}/{resource}/{operation} + Name *string `json:"name,omitempty"` + // Display - Display metadata associated with the operation. + Display *ResourceProviderOperationDisplay `json:"display,omitempty"` +} + +// ResourceProviderOperationDisplay display metadata associated with the operation. +type ResourceProviderOperationDisplay struct { + // Provider - Resource provider: Microsoft Custom Providers. + Provider *string `json:"provider,omitempty"` + // Resource - Resource on which the operation is performed. + Resource *string `json:"resource,omitempty"` + // Operation - Type of operation: get, read, delete, etc. + Operation *string `json:"operation,omitempty"` + // Description - Description of this operation. + Description *string `json:"description,omitempty"` +} + +// ResourceProviderOperationList results of the request to list operations. +type ResourceProviderOperationList struct { + autorest.Response `json:"-"` + // Value - List of operations supported by this resource provider. + Value *[]ResourceProviderOperation `json:"value,omitempty"` + // NextLink - The URL to use for getting the next set of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// ResourceProviderOperationListIterator provides access to a complete listing of ResourceProviderOperation +// values. +type ResourceProviderOperationListIterator struct { + i int + page ResourceProviderOperationListPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *ResourceProviderOperationListIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ResourceProviderOperationListIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *ResourceProviderOperationListIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter ResourceProviderOperationListIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter ResourceProviderOperationListIterator) Response() ResourceProviderOperationList { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter ResourceProviderOperationListIterator) Value() ResourceProviderOperation { + if !iter.page.NotDone() { + return ResourceProviderOperation{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the ResourceProviderOperationListIterator type. +func NewResourceProviderOperationListIterator(page ResourceProviderOperationListPage) ResourceProviderOperationListIterator { + return ResourceProviderOperationListIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (rpol ResourceProviderOperationList) IsEmpty() bool { + return rpol.Value == nil || len(*rpol.Value) == 0 +} + +// resourceProviderOperationListPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (rpol ResourceProviderOperationList) resourceProviderOperationListPreparer(ctx context.Context) (*http.Request, error) { + if rpol.NextLink == nil || len(to.String(rpol.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(rpol.NextLink))) +} + +// ResourceProviderOperationListPage contains a page of ResourceProviderOperation values. +type ResourceProviderOperationListPage struct { + fn func(context.Context, ResourceProviderOperationList) (ResourceProviderOperationList, error) + rpol ResourceProviderOperationList +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *ResourceProviderOperationListPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ResourceProviderOperationListPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + next, err := page.fn(ctx, page.rpol) + if err != nil { + return err + } + page.rpol = next + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *ResourceProviderOperationListPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page ResourceProviderOperationListPage) NotDone() bool { + return !page.rpol.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page ResourceProviderOperationListPage) Response() ResourceProviderOperationList { + return page.rpol +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page ResourceProviderOperationListPage) Values() []ResourceProviderOperation { + if page.rpol.IsEmpty() { + return nil + } + return *page.rpol.Value +} + +// Creates a new instance of the ResourceProviderOperationListPage type. +func NewResourceProviderOperationListPage(getNextPage func(context.Context, ResourceProviderOperationList) (ResourceProviderOperationList, error)) ResourceProviderOperationListPage { + return ResourceProviderOperationListPage{fn: getNextPage} +} + +// ResourceProvidersUpdate custom resource provider update information. +type ResourceProvidersUpdate struct { + // Tags - Resource tags + Tags map[string]*string `json:"tags"` +} + +// MarshalJSON is the custom marshaler for ResourceProvidersUpdate. +func (rpu ResourceProvidersUpdate) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if rpu.Tags != nil { + objectMap["tags"] = rpu.Tags + } + return json.Marshal(objectMap) +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/operations.go b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/operations.go new file mode 100644 index 000000000000..733cf813a9f8 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/operations.go @@ -0,0 +1,147 @@ +package customproviders + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// OperationsClient is the allows extension of ARM control plane with custom resource providers. +type OperationsClient struct { + BaseClient +} + +// NewOperationsClient creates an instance of the OperationsClient client. +func NewOperationsClient(subscriptionID string) OperationsClient { + return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewOperationsClientWithBaseURI creates an instance of the OperationsClient client using a custom endpoint. Use this +// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string) OperationsClient { + return OperationsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List the list of operations provided by Microsoft CustomProviders. +func (client OperationsClient) List(ctx context.Context) (result ResourceProviderOperationListPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List") + defer func() { + sc := -1 + if result.rpol.Response.Response != nil { + sc = result.rpol.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.OperationsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.rpol.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "customproviders.OperationsClient", "List", resp, "Failure sending request") + return + } + + result.rpol, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.OperationsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) { + const APIVersion = "2018-09-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/Microsoft.CustomProviders/operations"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client OperationsClient) ListResponder(resp *http.Response) (result ResourceProviderOperationList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client OperationsClient) listNextResults(ctx context.Context, lastResults ResourceProviderOperationList) (result ResourceProviderOperationList, err error) { + req, err := lastResults.resourceProviderOperationListPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "customproviders.OperationsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "customproviders.OperationsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "customproviders.OperationsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client OperationsClient) ListComplete(ctx context.Context) (result ResourceProviderOperationListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx) + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/version.go b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/version.go new file mode 100644 index 000000000000..f979d7f225c8 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders/version.go @@ -0,0 +1,30 @@ +package customproviders + +import "github.com/Azure/azure-sdk-for-go/version" + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// UserAgent returns the UserAgent string to use when sending http.Requests. +func UserAgent() string { + return "Azure-SDK-For-Go/" + version.Number + " customproviders/2018-09-01-preview" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return version.Number +} diff --git a/vendor/modules.txt b/vendor/modules.txt index a7eccb4bf87c..613ef860b7af 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -52,6 +52,7 @@ github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql github.com/Azure/azure-sdk-for-go/services/powerbidedicated/mgmt/2017-10-01/powerbidedicated github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-09-01-preview/authorization github.com/Azure/azure-sdk-for-go/services/preview/botservice/mgmt/2018-07-12/botservice +github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders github.com/Azure/azure-sdk-for-go/services/preview/eventgrid/mgmt/2018-09-15-preview/eventgrid github.com/Azure/azure-sdk-for-go/services/preview/hdinsight/mgmt/2018-06-01-preview/hdinsight github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2018-12-01-preview/devices diff --git a/website/allowed-subcategories b/website/allowed-subcategories index 418442e424b7..79eeb675da4e 100644 --- a/website/allowed-subcategories +++ b/website/allowed-subcategories @@ -14,6 +14,7 @@ Compute Container CosmosDB (DocumentDB) Cost Management +Custom Provider DNS Data Explorer Data Factory diff --git a/website/azurerm.erb b/website/azurerm.erb index 27f3d8582b5d..eb11d0ab2831 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -1098,6 +1098,15 @@ +
  • + Custom Providers + +
  • +
  • Database Resources