From 90d470a6777de0897a0f66243c434c3bfd3a38c4 Mon Sep 17 00:00:00 2001 From: Aris van Ommeren Date: Mon, 17 Oct 2022 21:04:13 +0200 Subject: [PATCH 1/8] `azurerm_subscription` - Replace Track1 with Pandora SDK --- .../services/subscription/client/client.go | 9 +- .../subscription/subscription_import.go | 10 +- .../subscription/subscription_resource.go | 117 ++++----- .../subscription_resource_test.go | 11 +- .../2021-10-01/subscriptions/README.md | 240 ++++++++++++++++++ .../2021-10-01/subscriptions/client.go | 18 ++ .../2021-10-01/subscriptions/constants.go | 127 +++++++++ .../2021-10-01/subscriptions/id_alias.go | 98 +++++++ .../subscriptions/id_billingaccount.go | 98 +++++++ .../subscriptions/id_providersubscription.go | 98 +++++++ .../method_aliascreate_autorest.go | 79 ++++++ .../method_aliasdelete_autorest.go | 66 +++++ .../subscriptions/method_aliasget_autorest.go | 68 +++++ .../method_aliaslist_autorest.go | 68 +++++ ...method_billingaccountgetpolicy_autorest.go | 69 +++++ ...od_subscriptionacceptownership_autorest.go | 79 ++++++ ...scriptionacceptownershipstatus_autorest.go | 69 +++++ .../method_subscriptioncancel_autorest.go | 70 +++++ .../method_subscriptionenable_autorest.go | 70 +++++ ...policyaddupdatepolicyfortenant_autorest.go | 69 +++++ ...iptionpolicygetpolicyfortenant_autorest.go | 68 +++++ ...ptionpolicylistpolicyfortenant_autorest.go | 186 ++++++++++++++ .../method_subscriptionrename_autorest.go | 71 ++++++ .../model_acceptownershiprequest.go | 8 + .../model_acceptownershiprequestproperties.go | 10 + .../model_acceptownershipstatusresponse.go | 14 + .../model_billingaccountpoliciesresponse.go | 16 ++ ...illingaccountpoliciesresponseproperties.go | 9 + .../model_canceledsubscriptionid.go | 8 + .../model_enabledsubscriptionid.go | 8 + .../model_gettenantpolicyresponse.go | 16 ++ .../subscriptions/model_putaliasrequest.go | 8 + ...del_putaliasrequestadditionalproperties.go | 11 + .../model_putaliasrequestproperties.go | 13 + .../model_puttenantpolicyrequestproperties.go | 10 + .../model_renamedsubscriptionid.go | 8 + .../model_servicetenantresponse.go | 9 + .../model_subscriptionaliaslistresult.go | 9 + .../model_subscriptionaliasresponse.go | 16 ++ ...del_subscriptionaliasresponseproperties.go | 19 ++ .../subscriptions/model_subscriptionname.go | 8 + .../subscriptions/model_tenantpolicy.go | 11 + .../2021-10-01/subscriptions/predicates.go | 24 ++ .../2021-10-01/subscriptions/version.go | 12 + vendor/modules.txt | 1 + 45 files changed, 2035 insertions(+), 71 deletions(-) create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/constants.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_alias.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_billingaccount.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_providersubscription.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_aliascreate_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_aliasdelete_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_aliasget_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_aliaslist_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_billingaccountgetpolicy_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionacceptownership_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionacceptownershipstatus_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptioncancel_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionenable_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionpolicyaddupdatepolicyfortenant_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionpolicygetpolicyfortenant_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionpolicylistpolicyfortenant_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionrename_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_acceptownershiprequest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_acceptownershiprequestproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_acceptownershipstatusresponse.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_billingaccountpoliciesresponse.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_billingaccountpoliciesresponseproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_canceledsubscriptionid.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_enabledsubscriptionid.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_gettenantpolicyresponse.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_putaliasrequest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_putaliasrequestadditionalproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_putaliasrequestproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_puttenantpolicyrequestproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_renamedsubscriptionid.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_servicetenantresponse.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_subscriptionaliaslistresult.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_subscriptionaliasresponse.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_subscriptionaliasresponseproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_subscriptionname.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_tenantpolicy.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/version.go diff --git a/internal/services/subscription/client/client.go b/internal/services/subscription/client/client.go index 2f88f1e19198..7feacb30f061 100644 --- a/internal/services/subscription/client/client.go +++ b/internal/services/subscription/client/client.go @@ -1,14 +1,15 @@ package client import ( - "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2021-01-01/subscriptions" // nolint: staticcheck - subscriptionAlias "github.com/Azure/azure-sdk-for-go/services/subscription/mgmt/2020-09-01/subscription" // nolint: staticcheck + "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2021-01-01/subscriptions" // nolint: staticcheck + subscriptionAlias "github.com/Azure/azure-sdk-for-go/services/subscription/mgmt/2020-09-01/subscription" // nolint: staticcheck + subscriptionAliasPandora "github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions" // nolint: staticcheck "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) type Client struct { Client *subscriptions.Client - AliasClient *subscriptionAlias.AliasClient + AliasClient *subscriptionAliasPandora.SubscriptionsClient SubscriptionClient *subscriptionAlias.Client } @@ -16,7 +17,7 @@ func NewClient(o *common.ClientOptions) *Client { client := subscriptions.NewClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&client.Client, o.ResourceManagerAuthorizer) - aliasClient := subscriptionAlias.NewAliasClientWithBaseURI(o.ResourceManagerEndpoint) + aliasClient := subscriptionAliasPandora.NewSubscriptionsClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&aliasClient.Client, o.ResourceManagerAuthorizer) subscriptionClient := subscriptionAlias.NewClientWithBaseURI(o.ResourceManagerEndpoint) diff --git a/internal/services/subscription/subscription_import.go b/internal/services/subscription/subscription_import.go index 1121660de789..a07d8b182b15 100644 --- a/internal/services/subscription/subscription_import.go +++ b/internal/services/subscription/subscription_import.go @@ -5,8 +5,8 @@ import ( "fmt" "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2021-01-01/subscriptions" // nolint: staticcheck + subscriptionAliasPandora "github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/subscription/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" ) @@ -14,18 +14,18 @@ func importSubscriptionByAlias() pluginsdk.ImporterFunc { return func(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) (data []*pluginsdk.ResourceData, err error) { aliasClient := meta.(*clients.Client).Subscription.AliasClient client := meta.(*clients.Client).Subscription.Client - aliasId, err := parse.SubscriptionAliasID(d.Id()) + aliasId, err := subscriptionAliasPandora.ParseAliasID(d.Id()) if err != nil { return []*pluginsdk.ResourceData{}, fmt.Errorf("failed parsing Subscription Alias ID for import") } - alias, err := aliasClient.Get(ctx, aliasId.Name) + alias, err := aliasClient.AliasGet(ctx, *aliasId) if err != nil { return []*pluginsdk.ResourceData{}, fmt.Errorf("failed reading Subscription Alias: %+v", err) } - if alias.Properties == nil || alias.Properties.SubscriptionID == nil { + if alias.Model == nil || alias.Model.Properties == nil || alias.Model.Properties.SubscriptionId == nil { return []*pluginsdk.ResourceData{}, fmt.Errorf("failed reading Subscription Alias Properties, empty response or missing Subscription ID") } - subscription, err := client.Get(ctx, *alias.Properties.SubscriptionID) + subscription, err := client.Get(ctx, *alias.Model.Properties.SubscriptionId) if err != nil { return []*pluginsdk.ResourceData{}, fmt.Errorf("failed parsing Subscription details for import: %+v", err) } diff --git a/internal/services/subscription/subscription_resource.go b/internal/services/subscription/subscription_resource.go index 24b19cebdfba..7c6cdf47c19b 100644 --- a/internal/services/subscription/subscription_resource.go +++ b/internal/services/subscription/subscription_resource.go @@ -9,7 +9,10 @@ import ( "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-06-01/resources" // nolint: staticcheck "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2021-01-01/subscriptions" // nolint: staticcheck subscriptionAlias "github.com/Azure/azure-sdk-for-go/services/subscription/mgmt/2020-09-01/subscription" // nolint: staticcheck + "github.com/google/uuid" + "github.com/hashicorp/go-azure-helpers/lang/response" + subscriptionAliasPandora "github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/locks" @@ -131,31 +134,31 @@ func resourceSubscriptionCreate(d *pluginsdk.ResourceData, meta interface{}) err d.Set("alias", aliasName) } - id := parse.NewSubscriptionAliasId(aliasName) + id := subscriptionAliasPandora.NewAliasID(aliasName) - existing, err := aliasClient.Get(ctx, id.Name) + existing, err := aliasClient.AliasGet(ctx, id) if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for existence of Subscription by Alias %q: %+v", id.Name, err) + if !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for existence of Subscription by Alias %q: %+v", id.AliasName, err) } } - if props := existing.Properties; props != nil { + if model := existing.Model; model != nil && model.Properties != nil { return tf.ImportAsExistsError("azurerm_subscription", id.ID()) } locks.ByName(aliasName, SubscriptionResourceName) defer locks.UnlockByName(aliasName, SubscriptionResourceName) - workload := subscriptionAlias.Production + workload := subscriptionAliasPandora.WorkloadProduction workloadRaw := d.Get("workload").(string) if workloadRaw != "" { - workload = subscriptionAlias.Workload(workloadRaw) + workload = subscriptionAliasPandora.Workload(workloadRaw) } - req := subscriptionAlias.PutAliasRequest{ - Properties: &subscriptionAlias.PutAliasRequestProperties{ - Workload: workload, + req := subscriptionAliasPandora.PutAliasRequest{ + Properties: &subscriptionAliasPandora.PutAliasRequestProperties{ + Workload: &workload, }, } @@ -180,7 +183,7 @@ func resourceSubscriptionCreate(d *pluginsdk.ResourceData, meta interface{}) err return fmt.Errorf("an Alias for Subscription %q already exists with name %q - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for %q for more information", subscriptionId, *exists, "azurerm_subscription") } - req.Properties.SubscriptionID = utils.String(subscriptionId) + req.Properties.SubscriptionId = utils.String(subscriptionId) existingSub, err := client.Get(ctx, subscriptionId) if err != nil { return fmt.Errorf("could not read existing Subscription %q", subscriptionId) @@ -194,7 +197,7 @@ func resourceSubscriptionCreate(d *pluginsdk.ResourceData, meta interface{}) err deadline, _ := ctx.Deadline() createDeadline := time.Until(deadline) if err := waitForSubscriptionStateToSettle(ctx, meta.(*clients.Client), subscriptionId, "Active", createDeadline); err != nil { - return fmt.Errorf("failed waiting for Subscription %q (Alias %q) to enter %q state: %+v", subscriptionId, id.Name, "Active", err) + return fmt.Errorf("failed waiting for Subscription %q (Alias %q) to enter %q state: %+v", subscriptionId, id.AliasName, "Active", err) } } } else { @@ -203,31 +206,31 @@ func resourceSubscriptionCreate(d *pluginsdk.ResourceData, meta interface{}) err req.Properties.BillingScope = utils.String(d.Get("billing_scope_id").(string)) } - future, err := aliasClient.Create(ctx, aliasName, req) + future, err := aliasClient.AliasCreate(ctx, id, req) if err != nil { return fmt.Errorf("creating new Subscription (Alias %q): %+v", aliasName, err) } - if err := future.WaitForCompletionRef(ctx, aliasClient.Client); err != nil { - return fmt.Errorf("waiting for creation of Subscription with Alias %q: %+v", id.Name, err) + if err := future.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("waiting for creation of Subscription with Alias %q: %+v", id.AliasName, err) } - alias, err := aliasClient.Get(ctx, id.Name) - if err != nil || alias.Properties == nil || alias.Properties.SubscriptionID == nil { - return fmt.Errorf("failed reading subscription details for Alias %q: %+v", id.Name, err) + alias, err := aliasClient.AliasGet(ctx, id) + if err != nil || alias.Model == nil || alias.Model.Properties == nil || alias.Model.Properties.SubscriptionId == nil { + return fmt.Errorf("failed reading subscription details for Alias %q: %+v", id.AliasName, err) } deadline, _ := ctx.Deadline() createDeadline := time.Until(deadline) - if err := waitForSubscriptionStateToSettle(ctx, meta.(*clients.Client), *alias.Properties.SubscriptionID, "Active", createDeadline); err != nil { - return fmt.Errorf("failed waiting for Subscription %q (Alias %q) to enter %q state: %+v", *alias.Properties.SubscriptionID, id.Name, "Active", err) + if err := waitForSubscriptionStateToSettle(ctx, meta.(*clients.Client), *alias.Model.Properties.SubscriptionId, "Active", createDeadline); err != nil { + return fmt.Errorf("failed waiting for Subscription %q (Alias %q) to enter %q state: %+v", *alias.Model.Properties.SubscriptionId, id.AliasName, "Active", err) } if d.HasChange("tags") { - tagsClient := meta.(*clients.Client).Resource.TagsClientForSubscription(*alias.Properties.SubscriptionID) + tagsClient := meta.(*clients.Client).Resource.TagsClientForSubscription(*alias.Model.Properties.SubscriptionId) t := tags.Expand(d.Get("tags").(map[string]interface{})) - scope := fmt.Sprintf("subscriptions/%s", *alias.Properties.SubscriptionID) + scope := fmt.Sprintf("subscriptions/%s", *alias.Model.Properties.SubscriptionId) tagsResource := resources.TagsResource{ Properties: &resources.Tags{ Tags: t, @@ -249,19 +252,19 @@ func resourceSubscriptionUpdate(d *pluginsdk.ResourceData, meta interface{}) err ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.SubscriptionAliasID(d.Id()) + id, err := subscriptionAliasPandora.ParseAliasID(d.Id()) if err != nil { return err } - locks.ByName(id.Name, SubscriptionResourceName) - defer locks.UnlockByName(id.Name, SubscriptionResourceName) - resp, err := aliasClient.Get(ctx, id.Name) - if err != nil || resp.Properties == nil { + locks.ByName(id.AliasName, SubscriptionResourceName) + defer locks.UnlockByName(id.AliasName, SubscriptionResourceName) + resp, err := aliasClient.AliasGet(ctx, *id) + if err != nil || resp.Model == nil || resp.Model.Properties == nil { return fmt.Errorf("could not read Subscription Alias for update: %+v", err) } - subscriptionId := resp.Properties.SubscriptionID + subscriptionId := resp.Model.Properties.SubscriptionId if subscriptionId == nil || *subscriptionId == "" { return fmt.Errorf("could not read Subscription ID from Alias") } @@ -301,32 +304,32 @@ func resourceSubscriptionRead(d *pluginsdk.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.SubscriptionAliasID(d.Id()) + id, err := subscriptionAliasPandora.ParseAliasID(d.Id()) if err != nil { return err } - d.Set("alias", id.Name) + d.Set("alias", id.AliasName) - alias, err := aliasClient.Get(ctx, id.Name) - if err != nil { - if utils.ResponseWasNotFound(alias.Response) { + alias, err := aliasClient.AliasGet(ctx, *id) + if err != nil || alias.Model == nil { + if response.WasNotFound(alias.HttpResponse) { log.Printf("[INFO] Error reading Subscription %q - removing from state", d.Id()) d.SetId("") return nil } - return fmt.Errorf("reading Subscription Alias %q: %+v", id.Name, err) + return fmt.Errorf("reading Subscription Alias %q: %+v", id.AliasName, err) } subscriptionId := "" subscriptionName := "" tenantId := "" t := make(map[string]*string) - if props := alias.Properties; props != nil && props.SubscriptionID != nil { - subscriptionId = *props.SubscriptionID + if props := alias.Model.Properties; props != nil && props.SubscriptionId != nil { + subscriptionId = *props.SubscriptionId resp, err := client.Get(ctx, subscriptionId) if err != nil { - return fmt.Errorf("failed to read Subscription %q (Alias %q) for Tenant Information: %+v", subscriptionId, id.Name, err) + return fmt.Errorf("failed to read Subscription %q (Alias %q) for Tenant Information: %+v", subscriptionId, id.AliasName, err) } if resp.TenantID != nil { tenantId = *resp.TenantID @@ -364,21 +367,21 @@ func resourceSubscriptionDelete(d *pluginsdk.ResourceData, meta interface{}) err ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.SubscriptionAliasID(d.Id()) + id, err := subscriptionAliasPandora.ParseAliasID(d.Id()) if err != nil { return err } - locks.ByName(id.Name, SubscriptionResourceName) - defer locks.UnlockByName(id.Name, SubscriptionResourceName) + locks.ByName(id.AliasName, SubscriptionResourceName) + defer locks.UnlockByName(id.AliasName, SubscriptionResourceName) // Get subscription details for later - alias, err := aliasClient.Get(ctx, id.Name) - if err != nil || alias.Properties == nil { - return fmt.Errorf("could not read Alias %q for Subscription: %+v", id.Name, err) + alias, err := aliasClient.AliasGet(ctx, *id) + if err != nil || alias.Model == nil || alias.Model.Properties == nil { + return fmt.Errorf("could not read Alias %q for Subscription: %+v", id.AliasName, err) } subscriptionId := "" - if subscriptionIdRaw := alias.Properties.SubscriptionID; subscriptionIdRaw != nil { + if subscriptionIdRaw := alias.Model.Properties.SubscriptionId; subscriptionIdRaw != nil { subscriptionId = *subscriptionIdRaw } locks.ByID(subscriptionId) @@ -404,10 +407,10 @@ func resourceSubscriptionDelete(d *pluginsdk.ResourceData, meta interface{}) err } } - resp, err := aliasClient.Delete(ctx, id.Name) + resp, err := aliasClient.AliasDelete(ctx, *id) if err != nil { - if !utils.ResponseWasNotFound(resp) { - return fmt.Errorf("could not delete Alias %q for Subscription %q (ID: %q): %+v", id.Name, subscriptionName, subscriptionId, err) + if !response.WasNotFound(resp.HttpResponse) { + return fmt.Errorf("could not delete Alias %q for Subscription %q (ID: %q): %+v", id.AliasName, subscriptionName, subscriptionId, err) } } @@ -420,7 +423,7 @@ func resourceSubscriptionDelete(d *pluginsdk.ResourceData, meta interface{}) err deleteDeadline := time.Until(deadline) if err := waitForSubscriptionStateToSettle(ctx, meta.(*clients.Client), subscriptionId, "Cancelled", deleteDeadline); err != nil { - return fmt.Errorf("failed to cancel Subscription %q (Alias %q): %+v", subscriptionId, id.Name, err) + return fmt.Errorf("failed to cancel Subscription %q (Alias %q): %+v", subscriptionId, id.AliasName, err) } return nil @@ -471,20 +474,20 @@ func waitForSubscriptionStateToSettle(ctx context.Context, clients *clients.Clie return nil } -func checkExistingAliases(ctx context.Context, client subscriptionAlias.AliasClient, subscriptionId string) (*string, int, error) { - aliasList, err := client.List(ctx) +func checkExistingAliases(ctx context.Context, client subscriptionAliasPandora.SubscriptionsClient, subscriptionId string) (*string, int, error) { + aliasList, err := client.AliasList(ctx) if err != nil { - return nil, len(*aliasList.Value), fmt.Errorf("could not List existing Subscription Aliases") + return nil, 0, fmt.Errorf("could not List existing Subscription Aliases") } - if aliasList.Value == nil { - return nil, len(*aliasList.Value), fmt.Errorf("failed reading Subscription Alias list") + if aliasList.Model == nil || aliasList.Model.Value == nil { + return nil, 0, fmt.Errorf("failed reading Subscription Alias list") } - for _, v := range *aliasList.Value { - if v.Properties != nil && v.Properties.SubscriptionID != nil && subscriptionId == *v.Properties.SubscriptionID { - return v.Name, len(*aliasList.Value), nil + for _, v := range *aliasList.Model.Value { + if v.Properties != nil && v.Properties.SubscriptionId != nil && subscriptionId == *v.Properties.SubscriptionId { + return v.Name, len(*aliasList.Model.Value), nil } } - return nil, len(*aliasList.Value), nil + return nil, len(*aliasList.Model.Value), nil } diff --git a/internal/services/subscription/subscription_resource_test.go b/internal/services/subscription/subscription_resource_test.go index eb3a1415d8d7..5f19c3e3d720 100644 --- a/internal/services/subscription/subscription_resource_test.go +++ b/internal/services/subscription/subscription_resource_test.go @@ -6,10 +6,11 @@ import ( "os" "testing" + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/subscription/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" ) @@ -94,16 +95,16 @@ func TestAccSubscriptionResource_devTest(t *testing.T) { } func (SubscriptionResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.SubscriptionAliasID(state.ID) + id, err := subscriptions.ParseAliasID(state.ID) if err != nil { return nil, err } - resp, err := client.Subscription.AliasClient.Get(ctx, id.Name) + resp, err := client.Subscription.AliasClient.AliasGet(ctx, *id) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { return utils.Bool(false), nil } - return nil, fmt.Errorf("retrieving Subscription Alias %q: %+v", id.Name, err) + return nil, fmt.Errorf("retrieving Subscription Alias %q: %+v", id.AliasName, err) } return utils.Bool(true), nil diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/README.md new file mode 100644 index 000000000000..7c6de0f6b2d3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/README.md @@ -0,0 +1,240 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions` Documentation + +The `subscriptions` SDK allows for interaction with the Azure Resource Manager Service `subscription` (API Version `2021-10-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions" +``` + + +### Client Initialization + +```go +client := subscriptions.NewSubscriptionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SubscriptionsClient.AliasCreate` + +```go +ctx := context.TODO() +id := subscriptions.NewAliasID("aliasValue") + +payload := subscriptions.PutAliasRequest{ + // ... +} + + +if err := client.AliasCreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SubscriptionsClient.AliasDelete` + +```go +ctx := context.TODO() +id := subscriptions.NewAliasID("aliasValue") + +read, err := client.AliasDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionsClient.AliasGet` + +```go +ctx := context.TODO() +id := subscriptions.NewAliasID("aliasValue") + +read, err := client.AliasGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionsClient.AliasList` + +```go +ctx := context.TODO() + + +read, err := client.AliasList(ctx) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionsClient.BillingAccountGetPolicy` + +```go +ctx := context.TODO() +id := subscriptions.NewBillingAccountID("billingAccountIdValue") + +read, err := client.BillingAccountGetPolicy(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionsClient.SubscriptionAcceptOwnership` + +```go +ctx := context.TODO() +id := subscriptions.NewProviderSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := subscriptions.AcceptOwnershipRequest{ + // ... +} + + +if err := client.SubscriptionAcceptOwnershipThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SubscriptionsClient.SubscriptionAcceptOwnershipStatus` + +```go +ctx := context.TODO() +id := subscriptions.NewProviderSubscriptionID("12345678-1234-9876-4563-123456789012") + +read, err := client.SubscriptionAcceptOwnershipStatus(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionsClient.SubscriptionCancel` + +```go +ctx := context.TODO() +id := subscriptions.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +read, err := client.SubscriptionCancel(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionsClient.SubscriptionEnable` + +```go +ctx := context.TODO() +id := subscriptions.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +read, err := client.SubscriptionEnable(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionsClient.SubscriptionPolicyAddUpdatePolicyForTenant` + +```go +ctx := context.TODO() + +payload := subscriptions.PutTenantPolicyRequestProperties{ + // ... +} + + +read, err := client.SubscriptionPolicyAddUpdatePolicyForTenant(ctx, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionsClient.SubscriptionPolicyGetPolicyForTenant` + +```go +ctx := context.TODO() + + +read, err := client.SubscriptionPolicyGetPolicyForTenant(ctx) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionsClient.SubscriptionPolicyListPolicyForTenant` + +```go +ctx := context.TODO() + + +// alternatively `client.SubscriptionPolicyListPolicyForTenant(ctx)` can be used to do batched pagination +items, err := client.SubscriptionPolicyListPolicyForTenantComplete(ctx) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SubscriptionsClient.SubscriptionRename` + +```go +ctx := context.TODO() +id := subscriptions.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := subscriptions.SubscriptionName{ + // ... +} + + +read, err := client.SubscriptionRename(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/client.go new file mode 100644 index 000000000000..da1257d5d970 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/client.go @@ -0,0 +1,18 @@ +package subscriptions + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionsClient struct { + Client autorest.Client + baseUri string +} + +func NewSubscriptionsClientWithBaseURI(endpoint string) SubscriptionsClient { + return SubscriptionsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/constants.go new file mode 100644 index 000000000000..974b7d49a4a2 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/constants.go @@ -0,0 +1,127 @@ +package subscriptions + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AcceptOwnership string + +const ( + AcceptOwnershipCompleted AcceptOwnership = "Completed" + AcceptOwnershipExpired AcceptOwnership = "Expired" + AcceptOwnershipPending AcceptOwnership = "Pending" +) + +func PossibleValuesForAcceptOwnership() []string { + return []string{ + string(AcceptOwnershipCompleted), + string(AcceptOwnershipExpired), + string(AcceptOwnershipPending), + } +} + +func parseAcceptOwnership(input string) (*AcceptOwnership, error) { + vals := map[string]AcceptOwnership{ + "completed": AcceptOwnershipCompleted, + "expired": AcceptOwnershipExpired, + "pending": AcceptOwnershipPending, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AcceptOwnership(input) + return &out, nil +} + +type Provisioning string + +const ( + ProvisioningAccepted Provisioning = "Accepted" + ProvisioningPending Provisioning = "Pending" + ProvisioningSucceeded Provisioning = "Succeeded" +) + +func PossibleValuesForProvisioning() []string { + return []string{ + string(ProvisioningAccepted), + string(ProvisioningPending), + string(ProvisioningSucceeded), + } +} + +func parseProvisioning(input string) (*Provisioning, error) { + vals := map[string]Provisioning{ + "accepted": ProvisioningAccepted, + "pending": ProvisioningPending, + "succeeded": ProvisioningSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Provisioning(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + } +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type Workload string + +const ( + WorkloadDevTest Workload = "DevTest" + WorkloadProduction Workload = "Production" +) + +func PossibleValuesForWorkload() []string { + return []string{ + string(WorkloadDevTest), + string(WorkloadProduction), + } +} + +func parseWorkload(input string) (*Workload, error) { + vals := map[string]Workload{ + "devtest": WorkloadDevTest, + "production": WorkloadProduction, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Workload(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_alias.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_alias.go new file mode 100644 index 000000000000..b7a98fcba861 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_alias.go @@ -0,0 +1,98 @@ +package subscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = AliasId{} + +// AliasId is a struct representing the Resource ID for a Alias +type AliasId struct { + AliasName string +} + +// NewAliasID returns a new AliasId struct +func NewAliasID(aliasName string) AliasId { + return AliasId{ + AliasName: aliasName, + } +} + +// ParseAliasID parses 'input' into a AliasId +func ParseAliasID(input string) (*AliasId, error) { + parser := resourceids.NewParserFromResourceIdType(AliasId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := AliasId{} + + if id.AliasName, ok = parsed.Parsed["aliasName"]; !ok { + return nil, fmt.Errorf("the segment 'aliasName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseAliasIDInsensitively parses 'input' case-insensitively into a AliasId +// note: this method should only be used for API response data and not user input +func ParseAliasIDInsensitively(input string) (*AliasId, error) { + parser := resourceids.NewParserFromResourceIdType(AliasId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := AliasId{} + + if id.AliasName, ok = parsed.Parsed["aliasName"]; !ok { + return nil, fmt.Errorf("the segment 'aliasName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateAliasID checks that 'input' can be parsed as a Alias ID +func ValidateAliasID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAliasID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Alias ID +func (id AliasId) ID() string { + fmtString := "/providers/Microsoft.Subscription/aliases/%s" + return fmt.Sprintf(fmtString, id.AliasName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Alias ID +func (id AliasId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSubscription", "Microsoft.Subscription", "Microsoft.Subscription"), + resourceids.StaticSegment("staticAliases", "aliases", "aliases"), + resourceids.UserSpecifiedSegment("aliasName", "aliasValue"), + } +} + +// String returns a human-readable description of this Alias ID +func (id AliasId) String() string { + components := []string{ + fmt.Sprintf("Alias Name: %q", id.AliasName), + } + return fmt.Sprintf("Alias (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_billingaccount.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_billingaccount.go new file mode 100644 index 000000000000..55d892975f5d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_billingaccount.go @@ -0,0 +1,98 @@ +package subscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = BillingAccountId{} + +// BillingAccountId is a struct representing the Resource ID for a Billing Account +type BillingAccountId struct { + BillingAccountId string +} + +// NewBillingAccountID returns a new BillingAccountId struct +func NewBillingAccountID(billingAccountId string) BillingAccountId { + return BillingAccountId{ + BillingAccountId: billingAccountId, + } +} + +// ParseBillingAccountID parses 'input' into a BillingAccountId +func ParseBillingAccountID(input string) (*BillingAccountId, error) { + parser := resourceids.NewParserFromResourceIdType(BillingAccountId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := BillingAccountId{} + + if id.BillingAccountId, ok = parsed.Parsed["billingAccountId"]; !ok { + return nil, fmt.Errorf("the segment 'billingAccountId' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseBillingAccountIDInsensitively parses 'input' case-insensitively into a BillingAccountId +// note: this method should only be used for API response data and not user input +func ParseBillingAccountIDInsensitively(input string) (*BillingAccountId, error) { + parser := resourceids.NewParserFromResourceIdType(BillingAccountId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := BillingAccountId{} + + if id.BillingAccountId, ok = parsed.Parsed["billingAccountId"]; !ok { + return nil, fmt.Errorf("the segment 'billingAccountId' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateBillingAccountID checks that 'input' can be parsed as a Billing Account ID +func ValidateBillingAccountID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBillingAccountID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Billing Account ID +func (id BillingAccountId) ID() string { + fmtString := "/providers/Microsoft.Billing/billingAccounts/%s" + return fmt.Sprintf(fmtString, id.BillingAccountId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Billing Account ID +func (id BillingAccountId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftBilling", "Microsoft.Billing", "Microsoft.Billing"), + resourceids.StaticSegment("staticBillingAccounts", "billingAccounts", "billingAccounts"), + resourceids.UserSpecifiedSegment("billingAccountId", "billingAccountIdValue"), + } +} + +// String returns a human-readable description of this Billing Account ID +func (id BillingAccountId) String() string { + components := []string{ + fmt.Sprintf("Billing Account: %q", id.BillingAccountId), + } + return fmt.Sprintf("Billing Account (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_providersubscription.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_providersubscription.go new file mode 100644 index 000000000000..68cf0ea42dbb --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_providersubscription.go @@ -0,0 +1,98 @@ +package subscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ProviderSubscriptionId{} + +// ProviderSubscriptionId is a struct representing the Resource ID for a Provider Subscription +type ProviderSubscriptionId struct { + SubscriptionId string +} + +// NewProviderSubscriptionID returns a new ProviderSubscriptionId struct +func NewProviderSubscriptionID(subscriptionId string) ProviderSubscriptionId { + return ProviderSubscriptionId{ + SubscriptionId: subscriptionId, + } +} + +// ParseProviderSubscriptionID parses 'input' into a ProviderSubscriptionId +func ParseProviderSubscriptionID(input string) (*ProviderSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(ProviderSubscriptionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProviderSubscriptionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseProviderSubscriptionIDInsensitively parses 'input' case-insensitively into a ProviderSubscriptionId +// note: this method should only be used for API response data and not user input +func ParseProviderSubscriptionIDInsensitively(input string) (*ProviderSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(ProviderSubscriptionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProviderSubscriptionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateProviderSubscriptionID checks that 'input' can be parsed as a Provider Subscription ID +func ValidateProviderSubscriptionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProviderSubscriptionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Subscription ID +func (id ProviderSubscriptionId) ID() string { + fmtString := "/providers/Microsoft.Subscription/subscriptions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Subscription ID +func (id ProviderSubscriptionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSubscription", "Microsoft.Subscription", "Microsoft.Subscription"), + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + } +} + +// String returns a human-readable description of this Provider Subscription ID +func (id ProviderSubscriptionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + } + return fmt.Sprintf("Provider Subscription (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_aliascreate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_aliascreate_autorest.go new file mode 100644 index 000000000000..0d736475f472 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_aliascreate_autorest.go @@ -0,0 +1,79 @@ +package subscriptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AliasCreateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// AliasCreate ... +func (c SubscriptionsClient) AliasCreate(ctx context.Context, id AliasId, input PutAliasRequest) (result AliasCreateOperationResponse, err error) { + req, err := c.preparerForAliasCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "AliasCreate", nil, "Failure preparing request") + return + } + + result, err = c.senderForAliasCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "AliasCreate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// AliasCreateThenPoll performs AliasCreate then polls until it's completed +func (c SubscriptionsClient) AliasCreateThenPoll(ctx context.Context, id AliasId, input PutAliasRequest) error { + result, err := c.AliasCreate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AliasCreate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after AliasCreate: %+v", err) + } + + return nil +} + +// preparerForAliasCreate prepares the AliasCreate request. +func (c SubscriptionsClient) preparerForAliasCreate(ctx context.Context, id AliasId, input PutAliasRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForAliasCreate sends the AliasCreate request. The method will close the +// http.Response Body if it receives an error. +func (c SubscriptionsClient) senderForAliasCreate(ctx context.Context, req *http.Request) (future AliasCreateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_aliasdelete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_aliasdelete_autorest.go new file mode 100644 index 000000000000..d6a15f774be1 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_aliasdelete_autorest.go @@ -0,0 +1,66 @@ +package subscriptions + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AliasDeleteOperationResponse struct { + HttpResponse *http.Response +} + +// AliasDelete ... +func (c SubscriptionsClient) AliasDelete(ctx context.Context, id AliasId) (result AliasDeleteOperationResponse, err error) { + req, err := c.preparerForAliasDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "AliasDelete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "AliasDelete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForAliasDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "AliasDelete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForAliasDelete prepares the AliasDelete request. +func (c SubscriptionsClient) preparerForAliasDelete(ctx context.Context, id AliasId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForAliasDelete handles the response to the AliasDelete request. The method always +// closes the http.Response Body. +func (c SubscriptionsClient) responderForAliasDelete(resp *http.Response) (result AliasDeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_aliasget_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_aliasget_autorest.go new file mode 100644 index 000000000000..59e89bb335cc --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_aliasget_autorest.go @@ -0,0 +1,68 @@ +package subscriptions + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AliasGetOperationResponse struct { + HttpResponse *http.Response + Model *SubscriptionAliasResponse +} + +// AliasGet ... +func (c SubscriptionsClient) AliasGet(ctx context.Context, id AliasId) (result AliasGetOperationResponse, err error) { + req, err := c.preparerForAliasGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "AliasGet", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "AliasGet", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForAliasGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "AliasGet", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForAliasGet prepares the AliasGet request. +func (c SubscriptionsClient) preparerForAliasGet(ctx context.Context, id AliasId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForAliasGet handles the response to the AliasGet request. The method always +// closes the http.Response Body. +func (c SubscriptionsClient) responderForAliasGet(resp *http.Response) (result AliasGetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_aliaslist_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_aliaslist_autorest.go new file mode 100644 index 000000000000..ba833e2cd525 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_aliaslist_autorest.go @@ -0,0 +1,68 @@ +package subscriptions + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AliasListOperationResponse struct { + HttpResponse *http.Response + Model *SubscriptionAliasListResult +} + +// AliasList ... +func (c SubscriptionsClient) AliasList(ctx context.Context) (result AliasListOperationResponse, err error) { + req, err := c.preparerForAliasList(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "AliasList", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "AliasList", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForAliasList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "AliasList", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForAliasList prepares the AliasList request. +func (c SubscriptionsClient) preparerForAliasList(ctx context.Context) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath("/providers/Microsoft.Subscription/aliases"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForAliasList handles the response to the AliasList request. The method always +// closes the http.Response Body. +func (c SubscriptionsClient) responderForAliasList(resp *http.Response) (result AliasListOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_billingaccountgetpolicy_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_billingaccountgetpolicy_autorest.go new file mode 100644 index 000000000000..715007109ef4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_billingaccountgetpolicy_autorest.go @@ -0,0 +1,69 @@ +package subscriptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BillingAccountGetPolicyOperationResponse struct { + HttpResponse *http.Response + Model *BillingAccountPoliciesResponse +} + +// BillingAccountGetPolicy ... +func (c SubscriptionsClient) BillingAccountGetPolicy(ctx context.Context, id BillingAccountId) (result BillingAccountGetPolicyOperationResponse, err error) { + req, err := c.preparerForBillingAccountGetPolicy(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "BillingAccountGetPolicy", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "BillingAccountGetPolicy", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForBillingAccountGetPolicy(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "BillingAccountGetPolicy", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForBillingAccountGetPolicy prepares the BillingAccountGetPolicy request. +func (c SubscriptionsClient) preparerForBillingAccountGetPolicy(ctx context.Context, id BillingAccountId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Subscription/policies/default", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForBillingAccountGetPolicy handles the response to the BillingAccountGetPolicy request. The method always +// closes the http.Response Body. +func (c SubscriptionsClient) responderForBillingAccountGetPolicy(resp *http.Response) (result BillingAccountGetPolicyOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionacceptownership_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionacceptownership_autorest.go new file mode 100644 index 000000000000..da1e1e7031c2 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionacceptownership_autorest.go @@ -0,0 +1,79 @@ +package subscriptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionAcceptOwnershipOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// SubscriptionAcceptOwnership ... +func (c SubscriptionsClient) SubscriptionAcceptOwnership(ctx context.Context, id ProviderSubscriptionId, input AcceptOwnershipRequest) (result SubscriptionAcceptOwnershipOperationResponse, err error) { + req, err := c.preparerForSubscriptionAcceptOwnership(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionAcceptOwnership", nil, "Failure preparing request") + return + } + + result, err = c.senderForSubscriptionAcceptOwnership(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionAcceptOwnership", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// SubscriptionAcceptOwnershipThenPoll performs SubscriptionAcceptOwnership then polls until it's completed +func (c SubscriptionsClient) SubscriptionAcceptOwnershipThenPoll(ctx context.Context, id ProviderSubscriptionId, input AcceptOwnershipRequest) error { + result, err := c.SubscriptionAcceptOwnership(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SubscriptionAcceptOwnership: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after SubscriptionAcceptOwnership: %+v", err) + } + + return nil +} + +// preparerForSubscriptionAcceptOwnership prepares the SubscriptionAcceptOwnership request. +func (c SubscriptionsClient) preparerForSubscriptionAcceptOwnership(ctx context.Context, id ProviderSubscriptionId, input AcceptOwnershipRequest) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/acceptOwnership", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForSubscriptionAcceptOwnership sends the SubscriptionAcceptOwnership request. The method will close the +// http.Response Body if it receives an error. +func (c SubscriptionsClient) senderForSubscriptionAcceptOwnership(ctx context.Context, req *http.Request) (future SubscriptionAcceptOwnershipOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionacceptownershipstatus_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionacceptownershipstatus_autorest.go new file mode 100644 index 000000000000..b61f540f15ad --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionacceptownershipstatus_autorest.go @@ -0,0 +1,69 @@ +package subscriptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionAcceptOwnershipStatusOperationResponse struct { + HttpResponse *http.Response + Model *AcceptOwnershipStatusResponse +} + +// SubscriptionAcceptOwnershipStatus ... +func (c SubscriptionsClient) SubscriptionAcceptOwnershipStatus(ctx context.Context, id ProviderSubscriptionId) (result SubscriptionAcceptOwnershipStatusOperationResponse, err error) { + req, err := c.preparerForSubscriptionAcceptOwnershipStatus(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionAcceptOwnershipStatus", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionAcceptOwnershipStatus", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForSubscriptionAcceptOwnershipStatus(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionAcceptOwnershipStatus", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForSubscriptionAcceptOwnershipStatus prepares the SubscriptionAcceptOwnershipStatus request. +func (c SubscriptionsClient) preparerForSubscriptionAcceptOwnershipStatus(ctx context.Context, id ProviderSubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/acceptOwnershipStatus", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForSubscriptionAcceptOwnershipStatus handles the response to the SubscriptionAcceptOwnershipStatus request. The method always +// closes the http.Response Body. +func (c SubscriptionsClient) responderForSubscriptionAcceptOwnershipStatus(resp *http.Response) (result SubscriptionAcceptOwnershipStatusOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptioncancel_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptioncancel_autorest.go new file mode 100644 index 000000000000..f4c3e829f87c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptioncancel_autorest.go @@ -0,0 +1,70 @@ +package subscriptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionCancelOperationResponse struct { + HttpResponse *http.Response + Model *CanceledSubscriptionId +} + +// SubscriptionCancel ... +func (c SubscriptionsClient) SubscriptionCancel(ctx context.Context, id commonids.SubscriptionId) (result SubscriptionCancelOperationResponse, err error) { + req, err := c.preparerForSubscriptionCancel(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionCancel", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionCancel", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForSubscriptionCancel(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionCancel", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForSubscriptionCancel prepares the SubscriptionCancel request. +func (c SubscriptionsClient) preparerForSubscriptionCancel(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Subscription/cancel", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForSubscriptionCancel handles the response to the SubscriptionCancel request. The method always +// closes the http.Response Body. +func (c SubscriptionsClient) responderForSubscriptionCancel(resp *http.Response) (result SubscriptionCancelOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionenable_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionenable_autorest.go new file mode 100644 index 000000000000..1a2bcb01953f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionenable_autorest.go @@ -0,0 +1,70 @@ +package subscriptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionEnableOperationResponse struct { + HttpResponse *http.Response + Model *EnabledSubscriptionId +} + +// SubscriptionEnable ... +func (c SubscriptionsClient) SubscriptionEnable(ctx context.Context, id commonids.SubscriptionId) (result SubscriptionEnableOperationResponse, err error) { + req, err := c.preparerForSubscriptionEnable(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionEnable", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionEnable", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForSubscriptionEnable(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionEnable", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForSubscriptionEnable prepares the SubscriptionEnable request. +func (c SubscriptionsClient) preparerForSubscriptionEnable(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Subscription/enable", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForSubscriptionEnable handles the response to the SubscriptionEnable request. The method always +// closes the http.Response Body. +func (c SubscriptionsClient) responderForSubscriptionEnable(resp *http.Response) (result SubscriptionEnableOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionpolicyaddupdatepolicyfortenant_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionpolicyaddupdatepolicyfortenant_autorest.go new file mode 100644 index 000000000000..bbf1d5113626 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionpolicyaddupdatepolicyfortenant_autorest.go @@ -0,0 +1,69 @@ +package subscriptions + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionPolicyAddUpdatePolicyForTenantOperationResponse struct { + HttpResponse *http.Response + Model *GetTenantPolicyResponse +} + +// SubscriptionPolicyAddUpdatePolicyForTenant ... +func (c SubscriptionsClient) SubscriptionPolicyAddUpdatePolicyForTenant(ctx context.Context, input PutTenantPolicyRequestProperties) (result SubscriptionPolicyAddUpdatePolicyForTenantOperationResponse, err error) { + req, err := c.preparerForSubscriptionPolicyAddUpdatePolicyForTenant(ctx, input) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionPolicyAddUpdatePolicyForTenant", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionPolicyAddUpdatePolicyForTenant", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForSubscriptionPolicyAddUpdatePolicyForTenant(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionPolicyAddUpdatePolicyForTenant", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForSubscriptionPolicyAddUpdatePolicyForTenant prepares the SubscriptionPolicyAddUpdatePolicyForTenant request. +func (c SubscriptionsClient) preparerForSubscriptionPolicyAddUpdatePolicyForTenant(ctx context.Context, input PutTenantPolicyRequestProperties) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath("/providers/Microsoft.Subscription/policies/default"), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForSubscriptionPolicyAddUpdatePolicyForTenant handles the response to the SubscriptionPolicyAddUpdatePolicyForTenant request. The method always +// closes the http.Response Body. +func (c SubscriptionsClient) responderForSubscriptionPolicyAddUpdatePolicyForTenant(resp *http.Response) (result SubscriptionPolicyAddUpdatePolicyForTenantOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionpolicygetpolicyfortenant_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionpolicygetpolicyfortenant_autorest.go new file mode 100644 index 000000000000..fccc1159a19e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionpolicygetpolicyfortenant_autorest.go @@ -0,0 +1,68 @@ +package subscriptions + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionPolicyGetPolicyForTenantOperationResponse struct { + HttpResponse *http.Response + Model *GetTenantPolicyResponse +} + +// SubscriptionPolicyGetPolicyForTenant ... +func (c SubscriptionsClient) SubscriptionPolicyGetPolicyForTenant(ctx context.Context) (result SubscriptionPolicyGetPolicyForTenantOperationResponse, err error) { + req, err := c.preparerForSubscriptionPolicyGetPolicyForTenant(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionPolicyGetPolicyForTenant", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionPolicyGetPolicyForTenant", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForSubscriptionPolicyGetPolicyForTenant(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionPolicyGetPolicyForTenant", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForSubscriptionPolicyGetPolicyForTenant prepares the SubscriptionPolicyGetPolicyForTenant request. +func (c SubscriptionsClient) preparerForSubscriptionPolicyGetPolicyForTenant(ctx context.Context) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath("/providers/Microsoft.Subscription/policies/default"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForSubscriptionPolicyGetPolicyForTenant handles the response to the SubscriptionPolicyGetPolicyForTenant request. The method always +// closes the http.Response Body. +func (c SubscriptionsClient) responderForSubscriptionPolicyGetPolicyForTenant(resp *http.Response) (result SubscriptionPolicyGetPolicyForTenantOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionpolicylistpolicyfortenant_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionpolicylistpolicyfortenant_autorest.go new file mode 100644 index 000000000000..6cdae3f2e4b3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionpolicylistpolicyfortenant_autorest.go @@ -0,0 +1,186 @@ +package subscriptions + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionPolicyListPolicyForTenantOperationResponse struct { + HttpResponse *http.Response + Model *[]GetTenantPolicyResponse + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (SubscriptionPolicyListPolicyForTenantOperationResponse, error) +} + +type SubscriptionPolicyListPolicyForTenantCompleteResult struct { + Items []GetTenantPolicyResponse +} + +func (r SubscriptionPolicyListPolicyForTenantOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r SubscriptionPolicyListPolicyForTenantOperationResponse) LoadMore(ctx context.Context) (resp SubscriptionPolicyListPolicyForTenantOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// SubscriptionPolicyListPolicyForTenant ... +func (c SubscriptionsClient) SubscriptionPolicyListPolicyForTenant(ctx context.Context) (resp SubscriptionPolicyListPolicyForTenantOperationResponse, err error) { + req, err := c.preparerForSubscriptionPolicyListPolicyForTenant(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionPolicyListPolicyForTenant", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionPolicyListPolicyForTenant", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForSubscriptionPolicyListPolicyForTenant(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionPolicyListPolicyForTenant", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForSubscriptionPolicyListPolicyForTenant prepares the SubscriptionPolicyListPolicyForTenant request. +func (c SubscriptionsClient) preparerForSubscriptionPolicyListPolicyForTenant(ctx context.Context) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath("/providers/Microsoft.Subscription/policies"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForSubscriptionPolicyListPolicyForTenantWithNextLink prepares the SubscriptionPolicyListPolicyForTenant request with the given nextLink token. +func (c SubscriptionsClient) preparerForSubscriptionPolicyListPolicyForTenantWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForSubscriptionPolicyListPolicyForTenant handles the response to the SubscriptionPolicyListPolicyForTenant request. The method always +// closes the http.Response Body. +func (c SubscriptionsClient) responderForSubscriptionPolicyListPolicyForTenant(resp *http.Response) (result SubscriptionPolicyListPolicyForTenantOperationResponse, err error) { + type page struct { + Values []GetTenantPolicyResponse `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result SubscriptionPolicyListPolicyForTenantOperationResponse, err error) { + req, err := c.preparerForSubscriptionPolicyListPolicyForTenantWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionPolicyListPolicyForTenant", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionPolicyListPolicyForTenant", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForSubscriptionPolicyListPolicyForTenant(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionPolicyListPolicyForTenant", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// SubscriptionPolicyListPolicyForTenantComplete retrieves all of the results into a single object +func (c SubscriptionsClient) SubscriptionPolicyListPolicyForTenantComplete(ctx context.Context) (SubscriptionPolicyListPolicyForTenantCompleteResult, error) { + return c.SubscriptionPolicyListPolicyForTenantCompleteMatchingPredicate(ctx, GetTenantPolicyResponseOperationPredicate{}) +} + +// SubscriptionPolicyListPolicyForTenantCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c SubscriptionsClient) SubscriptionPolicyListPolicyForTenantCompleteMatchingPredicate(ctx context.Context, predicate GetTenantPolicyResponseOperationPredicate) (resp SubscriptionPolicyListPolicyForTenantCompleteResult, err error) { + items := make([]GetTenantPolicyResponse, 0) + + page, err := c.SubscriptionPolicyListPolicyForTenant(ctx) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := SubscriptionPolicyListPolicyForTenantCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionrename_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionrename_autorest.go new file mode 100644 index 000000000000..a78e7ac47a57 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/method_subscriptionrename_autorest.go @@ -0,0 +1,71 @@ +package subscriptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionRenameOperationResponse struct { + HttpResponse *http.Response + Model *RenamedSubscriptionId +} + +// SubscriptionRename ... +func (c SubscriptionsClient) SubscriptionRename(ctx context.Context, id commonids.SubscriptionId, input SubscriptionName) (result SubscriptionRenameOperationResponse, err error) { + req, err := c.preparerForSubscriptionRename(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionRename", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionRename", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForSubscriptionRename(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SubscriptionRename", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForSubscriptionRename prepares the SubscriptionRename request. +func (c SubscriptionsClient) preparerForSubscriptionRename(ctx context.Context, id commonids.SubscriptionId, input SubscriptionName) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Subscription/rename", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForSubscriptionRename handles the response to the SubscriptionRename request. The method always +// closes the http.Response Body. +func (c SubscriptionsClient) responderForSubscriptionRename(resp *http.Response) (result SubscriptionRenameOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_acceptownershiprequest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_acceptownershiprequest.go new file mode 100644 index 000000000000..4aee6114a12e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_acceptownershiprequest.go @@ -0,0 +1,8 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AcceptOwnershipRequest struct { + Properties *AcceptOwnershipRequestProperties `json:"properties,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_acceptownershiprequestproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_acceptownershiprequestproperties.go new file mode 100644 index 000000000000..b703ee20cefd --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_acceptownershiprequestproperties.go @@ -0,0 +1,10 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AcceptOwnershipRequestProperties struct { + DisplayName string `json:"displayName"` + ManagementGroupId *string `json:"managementGroupId,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_acceptownershipstatusresponse.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_acceptownershipstatusresponse.go new file mode 100644 index 000000000000..fe667fd60a55 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_acceptownershipstatusresponse.go @@ -0,0 +1,14 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AcceptOwnershipStatusResponse struct { + AcceptOwnershipState *AcceptOwnership `json:"acceptOwnershipState,omitempty"` + BillingOwner *string `json:"billingOwner,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + ProvisioningState *Provisioning `json:"provisioningState,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` + SubscriptionTenantId *string `json:"subscriptionTenantId,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_billingaccountpoliciesresponse.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_billingaccountpoliciesresponse.go new file mode 100644 index 000000000000..35148a9dbdb1 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_billingaccountpoliciesresponse.go @@ -0,0 +1,16 @@ +package subscriptions + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BillingAccountPoliciesResponse struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *BillingAccountPoliciesResponseProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_billingaccountpoliciesresponseproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_billingaccountpoliciesresponseproperties.go new file mode 100644 index 000000000000..0ee931811099 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_billingaccountpoliciesresponseproperties.go @@ -0,0 +1,9 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BillingAccountPoliciesResponseProperties struct { + AllowTransfers *bool `json:"allowTransfers,omitempty"` + ServiceTenants *[]ServiceTenantResponse `json:"serviceTenants,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_canceledsubscriptionid.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_canceledsubscriptionid.go new file mode 100644 index 000000000000..eeb97156f487 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_canceledsubscriptionid.go @@ -0,0 +1,8 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CanceledSubscriptionId struct { + SubscriptionId *string `json:"subscriptionId,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_enabledsubscriptionid.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_enabledsubscriptionid.go new file mode 100644 index 000000000000..c45c2b6149a2 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_enabledsubscriptionid.go @@ -0,0 +1,8 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnabledSubscriptionId struct { + SubscriptionId *string `json:"subscriptionId,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_gettenantpolicyresponse.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_gettenantpolicyresponse.go new file mode 100644 index 000000000000..43805ed7a14e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_gettenantpolicyresponse.go @@ -0,0 +1,16 @@ +package subscriptions + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetTenantPolicyResponse struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TenantPolicy `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_putaliasrequest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_putaliasrequest.go new file mode 100644 index 000000000000..4111c78112f9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_putaliasrequest.go @@ -0,0 +1,8 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PutAliasRequest struct { + Properties *PutAliasRequestProperties `json:"properties,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_putaliasrequestadditionalproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_putaliasrequestadditionalproperties.go new file mode 100644 index 000000000000..fd5df00dee46 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_putaliasrequestadditionalproperties.go @@ -0,0 +1,11 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PutAliasRequestAdditionalProperties struct { + ManagementGroupId *string `json:"managementGroupId,omitempty"` + SubscriptionOwnerId *string `json:"subscriptionOwnerId,omitempty"` + SubscriptionTenantId *string `json:"subscriptionTenantId,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_putaliasrequestproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_putaliasrequestproperties.go new file mode 100644 index 000000000000..6165ab32f324 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_putaliasrequestproperties.go @@ -0,0 +1,13 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PutAliasRequestProperties struct { + AdditionalProperties *PutAliasRequestAdditionalProperties `json:"additionalProperties,omitempty"` + BillingScope *string `json:"billingScope,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + ResellerId *string `json:"resellerId,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` + Workload *Workload `json:"workload,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_puttenantpolicyrequestproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_puttenantpolicyrequestproperties.go new file mode 100644 index 000000000000..4226cbe8f2aa --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_puttenantpolicyrequestproperties.go @@ -0,0 +1,10 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PutTenantPolicyRequestProperties struct { + BlockSubscriptionsIntoTenant *bool `json:"blockSubscriptionsIntoTenant,omitempty"` + BlockSubscriptionsLeavingTenant *bool `json:"blockSubscriptionsLeavingTenant,omitempty"` + ExemptedPrincipals *[]string `json:"exemptedPrincipals,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_renamedsubscriptionid.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_renamedsubscriptionid.go new file mode 100644 index 000000000000..3d070ba1c8d9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_renamedsubscriptionid.go @@ -0,0 +1,8 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RenamedSubscriptionId struct { + SubscriptionId *string `json:"subscriptionId,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_servicetenantresponse.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_servicetenantresponse.go new file mode 100644 index 000000000000..d26ab536c986 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_servicetenantresponse.go @@ -0,0 +1,9 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServiceTenantResponse struct { + TenantId *string `json:"tenantId,omitempty"` + TenantName *string `json:"tenantName,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_subscriptionaliaslistresult.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_subscriptionaliaslistresult.go new file mode 100644 index 000000000000..4e74d563fabc --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_subscriptionaliaslistresult.go @@ -0,0 +1,9 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionAliasListResult struct { + NextLink *string `json:"nextLink,omitempty"` + Value *[]SubscriptionAliasResponse `json:"value,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_subscriptionaliasresponse.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_subscriptionaliasresponse.go new file mode 100644 index 000000000000..5b5bc89881ac --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_subscriptionaliasresponse.go @@ -0,0 +1,16 @@ +package subscriptions + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionAliasResponse struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SubscriptionAliasResponseProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_subscriptionaliasresponseproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_subscriptionaliasresponseproperties.go new file mode 100644 index 000000000000..85942bc7777a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_subscriptionaliasresponseproperties.go @@ -0,0 +1,19 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionAliasResponseProperties struct { + AcceptOwnershipState *AcceptOwnership `json:"acceptOwnershipState,omitempty"` + AcceptOwnershipUrl *string `json:"acceptOwnershipUrl,omitempty"` + BillingScope *string `json:"billingScope,omitempty"` + CreatedTime *string `json:"createdTime,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + ManagementGroupId *string `json:"managementGroupId,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + ResellerId *string `json:"resellerId,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` + SubscriptionOwnerId *string `json:"subscriptionOwnerId,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Workload *Workload `json:"workload,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_subscriptionname.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_subscriptionname.go new file mode 100644 index 000000000000..ee420ff8d812 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_subscriptionname.go @@ -0,0 +1,8 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionName struct { + SubscriptionName *string `json:"subscriptionName,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_tenantpolicy.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_tenantpolicy.go new file mode 100644 index 000000000000..2d460e57546c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/model_tenantpolicy.go @@ -0,0 +1,11 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TenantPolicy struct { + BlockSubscriptionsIntoTenant *bool `json:"blockSubscriptionsIntoTenant,omitempty"` + BlockSubscriptionsLeavingTenant *bool `json:"blockSubscriptionsLeavingTenant,omitempty"` + ExemptedPrincipals *[]string `json:"exemptedPrincipals,omitempty"` + PolicyId *string `json:"policyId,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/predicates.go new file mode 100644 index 000000000000..31bd820fe821 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/predicates.go @@ -0,0 +1,24 @@ +package subscriptions + +type GetTenantPolicyResponseOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GetTenantPolicyResponseOperationPredicate) Matches(input GetTenantPolicyResponse) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/version.go new file mode 100644 index 000000000000..8ade52d831dc --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/version.go @@ -0,0 +1,12 @@ +package subscriptions + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-10-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/subscriptions/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 18708f048060..233b4aa72db9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -546,6 +546,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/pr github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/streamingjobs github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/transformations github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2021-10-01-preview/outputs +github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions github.com/hashicorp/go-azure-sdk/resource-manager/timeseriesinsights/2020-05-15 github.com/hashicorp/go-azure-sdk/resource-manager/timeseriesinsights/2020-05-15/accesspolicies github.com/hashicorp/go-azure-sdk/resource-manager/timeseriesinsights/2020-05-15/environments From 6758fe707ef07f27362db64628613738012c424b Mon Sep 17 00:00:00 2001 From: Aris van Ommeren Date: Tue, 18 Oct 2022 08:52:27 +0200 Subject: [PATCH 2/8] Add extra functionality --- .../subscription/subscription_resource.go | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/internal/services/subscription/subscription_resource.go b/internal/services/subscription/subscription_resource.go index 7c6cdf47c19b..58f32a88cb19 100644 --- a/internal/services/subscription/subscription_resource.go +++ b/internal/services/subscription/subscription_resource.go @@ -78,7 +78,6 @@ func resourceSubscription() *pluginsdk.Resource { ), }, - // Optional "workload": { Type: pluginsdk.TypeString, Optional: true, @@ -95,6 +94,12 @@ func resourceSubscription() *pluginsdk.Resource { }, }, + "management_group_id": { + Type: pluginsdk.TypeString, + Description: "The Management Group ID to which the subscription belongs", + Optional: true, + }, + "subscription_id": { Type: pluginsdk.TypeString, Description: "The GUID of the Subscription.", @@ -162,6 +167,10 @@ func resourceSubscriptionCreate(d *pluginsdk.ResourceData, meta interface{}) err }, } + if managementGroupIdRaw, ok := d.GetOk("management_group_id"); ok { + req.Properties.AdditionalProperties.ManagementGroupId = utils.ToPtr(managementGroupIdRaw.(string)) + } + subscriptionId := "" // Check if we're adding alias management for an existing subscription @@ -249,6 +258,7 @@ func resourceSubscriptionCreate(d *pluginsdk.ResourceData, meta interface{}) err func resourceSubscriptionUpdate(d *pluginsdk.ResourceData, meta interface{}) error { aliasClient := meta.(*clients.Client).Subscription.AliasClient subscriptionClient := meta.(*clients.Client).Subscription.SubscriptionClient + managementGroupsClient := meta.(*clients.Client).ManagementGroups.SubscriptionClient ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() @@ -281,6 +291,22 @@ func resourceSubscriptionUpdate(d *pluginsdk.ResourceData, meta interface{}) err } } + if d.HasChange("management_group_id") { + groupName := d.Get("management_group_id").(string) + if groupName != "" { + if _, err := managementGroupsClient.Create(ctx, groupName, *subscriptionId, "no-cache"); err != nil { + return fmt.Errorf("[DEBUG] Error assigning Subscription ID %q to Management Group %q: %+v", *subscriptionId, groupName, err) + } + } else if old, _ := d.GetChange("management_group_id"); old.(string) != "" { + deleteResp, err := managementGroupsClient.Delete(ctx, old.(string), *subscriptionId, "no-cache") + if err != nil { + if !response.WasNotFound(deleteResp.Response) { + return fmt.Errorf("unable to de-associate Subscription %q from Management Group %q: %+v", *subscriptionId, old.(string), err) + } + } + } + } + if d.HasChange("tags") { tagsClient := meta.(*clients.Client).Resource.TagsClientForSubscription(*subscriptionId) t := tags.Expand(d.Get("tags").(map[string]interface{})) From 074191fd94303277128bfe1334947c42586e10c3 Mon Sep 17 00:00:00 2001 From: Aris van Ommeren Date: Mon, 9 Jan 2023 19:32:02 +0100 Subject: [PATCH 3/8] Remove management group --- .../subscription/subscription_resource.go | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/internal/services/subscription/subscription_resource.go b/internal/services/subscription/subscription_resource.go index 58f32a88cb19..3d85fb01d69d 100644 --- a/internal/services/subscription/subscription_resource.go +++ b/internal/services/subscription/subscription_resource.go @@ -94,12 +94,6 @@ func resourceSubscription() *pluginsdk.Resource { }, }, - "management_group_id": { - Type: pluginsdk.TypeString, - Description: "The Management Group ID to which the subscription belongs", - Optional: true, - }, - "subscription_id": { Type: pluginsdk.TypeString, Description: "The GUID of the Subscription.", @@ -167,10 +161,6 @@ func resourceSubscriptionCreate(d *pluginsdk.ResourceData, meta interface{}) err }, } - if managementGroupIdRaw, ok := d.GetOk("management_group_id"); ok { - req.Properties.AdditionalProperties.ManagementGroupId = utils.ToPtr(managementGroupIdRaw.(string)) - } - subscriptionId := "" // Check if we're adding alias management for an existing subscription @@ -258,7 +248,6 @@ func resourceSubscriptionCreate(d *pluginsdk.ResourceData, meta interface{}) err func resourceSubscriptionUpdate(d *pluginsdk.ResourceData, meta interface{}) error { aliasClient := meta.(*clients.Client).Subscription.AliasClient subscriptionClient := meta.(*clients.Client).Subscription.SubscriptionClient - managementGroupsClient := meta.(*clients.Client).ManagementGroups.SubscriptionClient ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() @@ -291,22 +280,6 @@ func resourceSubscriptionUpdate(d *pluginsdk.ResourceData, meta interface{}) err } } - if d.HasChange("management_group_id") { - groupName := d.Get("management_group_id").(string) - if groupName != "" { - if _, err := managementGroupsClient.Create(ctx, groupName, *subscriptionId, "no-cache"); err != nil { - return fmt.Errorf("[DEBUG] Error assigning Subscription ID %q to Management Group %q: %+v", *subscriptionId, groupName, err) - } - } else if old, _ := d.GetChange("management_group_id"); old.(string) != "" { - deleteResp, err := managementGroupsClient.Delete(ctx, old.(string), *subscriptionId, "no-cache") - if err != nil { - if !response.WasNotFound(deleteResp.Response) { - return fmt.Errorf("unable to de-associate Subscription %q from Management Group %q: %+v", *subscriptionId, old.(string), err) - } - } - } - } - if d.HasChange("tags") { tagsClient := meta.(*clients.Client).Resource.TagsClientForSubscription(*subscriptionId) t := tags.Expand(d.Get("tags").(map[string]interface{})) From bc6c9b37a02e892f58f038e6a98a6f477f87e6eb Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Mon, 6 Feb 2023 11:15:05 +0200 Subject: [PATCH 4/8] Subscriptions: update tests for MCA account --- .../subscription/subscription_resource_test.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/services/subscription/subscription_resource_test.go b/internal/services/subscription/subscription_resource_test.go index 5f19c3e3d720..de9af51012dc 100644 --- a/internal/services/subscription/subscription_resource_test.go +++ b/internal/services/subscription/subscription_resource_test.go @@ -113,23 +113,25 @@ func (SubscriptionResource) Exists(ctx context.Context, client *clients.Client, // TODO - Need Env vars in CI for Billing Account and Enrollment Account - Testing disabled for now func (SubscriptionResource) basicEnrollmentAccount(data acceptance.TestData) string { billingAccount := os.Getenv("ARM_BILLING_ACCOUNT") - enrollmentAccount := os.Getenv("ARM_BILLING_ENROLLMENT_ACCOUNT") + billingProfile := os.Getenv("ARM_BILLING_PROFILE") + invoiceSection := os.Getenv("ARM_INVOICE_SECTION") return fmt.Sprintf(` provider "azurerm" { features {} } -data "azurerm_billing_enrollment_account_scope" "test" { - billing_account = "%s" - enrollment_account = "%s" +data "azurerm_billing_mca_account_scope" "test" { + billing_account_name = "%[1]s" + billing_profile_name = "%[2]s" + invoice_section_name = "%[3]s" } resource "azurerm_subscription" "test" { - alias = "testAcc-%[3]d" - subscription_name = "testAccSubscription %[3]d" - billing_scope_id = data.azurerm_billing_enrollment_account_scope.test.id + alias = "testAcc-%[4]d" + subscription_name = "testAccSubscription %[4]d" + billing_scope_id = data.azurerm_billing_mca_account_scope.test.id } -`, billingAccount, enrollmentAccount, data.RandomInteger) +`, billingAccount, billingProfile, invoiceSection, data.RandomInteger) } func (SubscriptionResource) basicEnrollmentAccountUpdate(data acceptance.TestData) string { From 697767ee63514bf4bda8b2cb3883e239ede79f82 Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Tue, 28 Mar 2023 17:31:41 +0100 Subject: [PATCH 5/8] go mod vendor --- .../subscription/2021-10-01/subscriptions/id_alias.go | 3 +++ .../subscription/2021-10-01/subscriptions/id_billingaccount.go | 3 +++ .../2021-10-01/subscriptions/id_providersubscription.go | 3 +++ .../subscription/2021-10-01/subscriptions/predicates.go | 3 +++ 4 files changed, 12 insertions(+) diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_alias.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_alias.go index b7a98fcba861..58c6438a07a4 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_alias.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_alias.go @@ -7,6 +7,9 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + var _ resourceids.ResourceId = AliasId{} // AliasId is a struct representing the Resource ID for a Alias diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_billingaccount.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_billingaccount.go index 55d892975f5d..205aa673299c 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_billingaccount.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_billingaccount.go @@ -7,6 +7,9 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + var _ resourceids.ResourceId = BillingAccountId{} // BillingAccountId is a struct representing the Resource ID for a Billing Account diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_providersubscription.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_providersubscription.go index 68cf0ea42dbb..bded2232728c 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_providersubscription.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/id_providersubscription.go @@ -7,6 +7,9 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + var _ resourceids.ResourceId = ProviderSubscriptionId{} // ProviderSubscriptionId is a struct representing the Resource ID for a Provider Subscription diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/predicates.go index 31bd820fe821..d6bbb3cb5f14 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/predicates.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions/predicates.go @@ -1,5 +1,8 @@ package subscriptions +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + type GetTenantPolicyResponseOperationPredicate struct { Id *string Name *string From 972b6cd7541b9b74f9c9b4910110f611ffc828ae Mon Sep 17 00:00:00 2001 From: jackofallops Date: Wed, 29 Mar 2023 07:54:44 +0100 Subject: [PATCH 6/8] remove legacy sdk completely --- .../subscription/subscription_resource.go | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/internal/services/subscription/subscription_resource.go b/internal/services/subscription/subscription_resource.go index 3d85fb01d69d..a5dc73b3118a 100644 --- a/internal/services/subscription/subscription_resource.go +++ b/internal/services/subscription/subscription_resource.go @@ -6,13 +6,13 @@ import ( "log" "time" - "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-06-01/resources" // nolint: staticcheck - "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2021-01-01/subscriptions" // nolint: staticcheck - subscriptionAlias "github.com/Azure/azure-sdk-for-go/services/subscription/mgmt/2020-09-01/subscription" // nolint: staticcheck + "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-06-01/resources" // nolint: staticcheck + "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2021-01-01/subscriptions" // nolint: staticcheck "github.com/google/uuid" "github.com/hashicorp/go-azure-helpers/lang/response" - subscriptionAliasPandora "github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + subscriptionAlias "github.com/hashicorp/go-azure-sdk/resource-manager/subscription/2021-10-01/subscriptions" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/locks" @@ -85,8 +85,8 @@ func resourceSubscription() *pluginsdk.Resource { Description: "The workload type for the Subscription. Possible values are `Production` (default) and `DevTest`.", // Other RP's have updated Constants with contextual prefixes so these are likely to change ValidateFunc: validation.StringInSlice([]string{ - string(subscriptionAlias.Production), - string(subscriptionAlias.DevTest), + string(subscriptionAlias.WorkloadProduction), + string(subscriptionAlias.WorkloadDevTest), }, false), // Workload is not exposed in any way, so must be ignored if the resource is imported. DiffSuppressFunc: func(k, old, new string, d *pluginsdk.ResourceData) bool { @@ -133,7 +133,7 @@ func resourceSubscriptionCreate(d *pluginsdk.ResourceData, meta interface{}) err d.Set("alias", aliasName) } - id := subscriptionAliasPandora.NewAliasID(aliasName) + id := subscriptionAlias.NewAliasID(aliasName) existing, err := aliasClient.AliasGet(ctx, id) if err != nil { @@ -149,14 +149,14 @@ func resourceSubscriptionCreate(d *pluginsdk.ResourceData, meta interface{}) err locks.ByName(aliasName, SubscriptionResourceName) defer locks.UnlockByName(aliasName, SubscriptionResourceName) - workload := subscriptionAliasPandora.WorkloadProduction + workload := subscriptionAlias.WorkloadProduction workloadRaw := d.Get("workload").(string) if workloadRaw != "" { - workload = subscriptionAliasPandora.Workload(workloadRaw) + workload = subscriptionAlias.Workload(workloadRaw) } - req := subscriptionAliasPandora.PutAliasRequest{ - Properties: &subscriptionAliasPandora.PutAliasRequestProperties{ + req := subscriptionAlias.PutAliasRequest{ + Properties: &subscriptionAlias.PutAliasRequestProperties{ Workload: &workload, }, } @@ -247,11 +247,10 @@ func resourceSubscriptionCreate(d *pluginsdk.ResourceData, meta interface{}) err func resourceSubscriptionUpdate(d *pluginsdk.ResourceData, meta interface{}) error { aliasClient := meta.(*clients.Client).Subscription.AliasClient - subscriptionClient := meta.(*clients.Client).Subscription.SubscriptionClient ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := subscriptionAliasPandora.ParseAliasID(d.Id()) + id, err := subscriptionAlias.ParseAliasID(d.Id()) if err != nil { return err } @@ -263,25 +262,25 @@ func resourceSubscriptionUpdate(d *pluginsdk.ResourceData, meta interface{}) err return fmt.Errorf("could not read Subscription Alias for update: %+v", err) } - subscriptionId := resp.Model.Properties.SubscriptionId - if subscriptionId == nil || *subscriptionId == "" { - return fmt.Errorf("could not read Subscription ID from Alias") + subscriptionId, err := commonids.ParseSubscriptionID(*resp.Model.Properties.SubscriptionId) + if err != nil { + return fmt.Errorf("could not parse Subscription ID from Alias: %+v", err) } if d.HasChange("subscription_name") { - locks.ByID(*subscriptionId) - defer locks.UnlockByID(*subscriptionId) + locks.ByID(subscriptionId.ID()) + defer locks.UnlockByID(subscriptionId.ID()) - displayName := subscriptionAlias.Name{ + displayName := subscriptionAlias.SubscriptionName{ SubscriptionName: utils.String(d.Get("subscription_name").(string)), } - if _, err := subscriptionClient.Rename(ctx, *subscriptionId, displayName); err != nil { + if _, err := aliasClient.SubscriptionRename(ctx, *subscriptionId, displayName); err != nil { return fmt.Errorf("could not update Display Name of Subscription %q: %+v", *subscriptionId, err) } } if d.HasChange("tags") { - tagsClient := meta.(*clients.Client).Resource.TagsClientForSubscription(*subscriptionId) + tagsClient := meta.(*clients.Client).Resource.TagsClientForSubscription(subscriptionId.ID()) t := tags.Expand(d.Get("tags").(map[string]interface{})) scope := fmt.Sprintf("subscriptions/%s", *subscriptionId) tagsResource := resources.TagsResource{ @@ -303,7 +302,7 @@ func resourceSubscriptionRead(d *pluginsdk.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := subscriptionAliasPandora.ParseAliasID(d.Id()) + id, err := subscriptionAlias.ParseAliasID(d.Id()) if err != nil { return err } @@ -366,7 +365,7 @@ func resourceSubscriptionDelete(d *pluginsdk.ResourceData, meta interface{}) err ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := subscriptionAliasPandora.ParseAliasID(d.Id()) + id, err := subscriptionAlias.ParseAliasID(d.Id()) if err != nil { return err } @@ -473,7 +472,7 @@ func waitForSubscriptionStateToSettle(ctx context.Context, clients *clients.Clie return nil } -func checkExistingAliases(ctx context.Context, client subscriptionAliasPandora.SubscriptionsClient, subscriptionId string) (*string, int, error) { +func checkExistingAliases(ctx context.Context, client subscriptionAlias.SubscriptionsClient, subscriptionId string) (*string, int, error) { aliasList, err := client.AliasList(ctx) if err != nil { return nil, 0, fmt.Errorf("could not List existing Subscription Aliases") From 0f5d0d241d06d290c5db128ac97bb5721424e5d2 Mon Sep 17 00:00:00 2001 From: jackofallops Date: Wed, 29 Mar 2023 17:49:23 +0100 Subject: [PATCH 7/8] add note to docs on provider config --- website/docs/r/subscription.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/docs/r/subscription.html.markdown b/website/docs/r/subscription.html.markdown index f72e538e9036..4bbafff3c706 100644 --- a/website/docs/r/subscription.html.markdown +++ b/website/docs/r/subscription.html.markdown @@ -16,6 +16,8 @@ Manages an Alias for a Subscription - which adds an Alias to an existing Subscri ~> **NOTE:** Azure supports Multiple Aliases per Subscription, however, to reliably manage this resource in Terraform only a single Alias is supported. +~> **NOTE:** When using this resource across tenants the `client_id` and `tenant_id` of the `provider` config block should be for the home tenant details for the SPN / User or a permissions error will likely be encountered. See [the official documentation](https://learn.microsoft.com/en-us/azure/cost-management-billing/manage/programmatically-create-subscription) for more details. + ## Example Usage - creating a new Alias and Subscription for an Enrollment Account ```hcl From 11ab8b9ac538d8c567e4589994499378e6cedffc Mon Sep 17 00:00:00 2001 From: jackofallops Date: Wed, 29 Mar 2023 18:47:25 +0100 Subject: [PATCH 8/8] tweak custom poller for reliability --- internal/services/subscription/subscription_resource.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/services/subscription/subscription_resource.go b/internal/services/subscription/subscription_resource.go index a5dc73b3118a..b4957bd94e2e 100644 --- a/internal/services/subscription/subscription_resource.go +++ b/internal/services/subscription/subscription_resource.go @@ -433,9 +433,9 @@ func waitForSubscriptionStateToSettle(ctx context.Context, clients *clients.Clie status, err := clients.Subscription.Client.Get(ctx, subscriptionId) return status, string(status.State), err }, - PollInterval: 20 * time.Second, + PollInterval: 10 * time.Second, Timeout: timeout, - ContinuousTargetOccurence: 2, + ContinuousTargetOccurence: 4, Delay: 60 * time.Second, } switch targetState { @@ -446,6 +446,7 @@ func waitForSubscriptionStateToSettle(ctx context.Context, clients *clients.Clie } stateConf.Pending = []string{ string(subscriptions.StateEnabled), + "", // The `State` field can be empty whilst being updated } case "Active": @@ -455,6 +456,7 @@ func waitForSubscriptionStateToSettle(ctx context.Context, clients *clients.Clie stateConf.Pending = []string{ string(subscriptions.StateDisabled), string(subscriptions.StateWarned), + "", // The `State` field can be empty whilst being updated } default: return fmt.Errorf("unsupported target state %q for Subscription %q", targetState, subscriptionId)