Skip to content

Commit

Permalink
r/marketplace_agreement: fixing the Resource ID / downgrading to use …
Browse files Browse the repository at this point in the history
…API Version `2015-06-01` (#22264)
  • Loading branch information
tombuildsstuff authored and jackofallops committed Jun 23, 2023
1 parent 4c5880b commit f3f1c0b
Show file tree
Hide file tree
Showing 27 changed files with 54 additions and 63 deletions.
2 changes: 1 addition & 1 deletion internal/services/compute/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleries"
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryapplications"
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryapplicationversions"
"github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2021-01-01/agreements"
"github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2015-06-01/agreements"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
"github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2021-01-01/agreements"
"github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2015-06-01/agreements"
"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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2021-01-01/agreements"
"github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2015-06-01/agreements"
"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"
Expand Down
12 changes: 7 additions & 5 deletions internal/services/compute/marketplace_agreement_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2021-01-01/agreements"
"github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2015-06-01/agreements"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand Down Expand Up @@ -59,14 +59,16 @@ func dataSourceMarketplaceAgreementRead(d *pluginsdk.ResourceData, meta interfac
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id := agreements.NewOfferPlanID(subscriptionId, d.Get("publisher").(string), d.Get("offer").(string), d.Get("plan").(string))
// The Resource ID for this is the Plan ID, however we have to retrieve information about the signed plan
id := agreements.NewPlanID(subscriptionId, d.Get("publisher").(string), d.Get("offer").(string), d.Get("plan").(string))

log.Printf("[DEBUG] retrieving %s", id)

term, err := client.MarketplaceAgreementsGet(ctx, id)
getId := agreements.NewOfferPlanID(id.SubscriptionId, id.PublisherId, id.OfferId, id.PlanId)
term, err := client.MarketplaceAgreementsGet(ctx, getId)
if err != nil {
if !response.WasNotFound(term.HttpResponse) {
return fmt.Errorf("%s was not found", id)
if response.WasNotFound(term.HttpResponse) {
return fmt.Errorf("%s was not found", getId)
}

return fmt.Errorf("retrieving %s: %s", id, err)
Expand Down
29 changes: 12 additions & 17 deletions internal/services/compute/marketplace_agreement_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2021-01-01/agreements"
"github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2015-06-01/agreements"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Expand All @@ -21,7 +21,7 @@ func resourceMarketplaceAgreement() *pluginsdk.Resource {
Read: resourceMarketplaceAgreementRead,
Delete: resourceMarketplaceAgreementDelete,
Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := agreements.ParseOfferPlanID(id)
_, err := agreements.ParsePlanID(id)
return err
}),

Expand Down Expand Up @@ -73,11 +73,12 @@ func resourceMarketplaceAgreementCreateUpdate(d *pluginsdk.ResourceData, meta in
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
defer cancel()

id := agreements.NewOfferPlanID(subscriptionId, d.Get("publisher").(string), d.Get("offer").(string), d.Get("plan").(string))
id := agreements.NewPlanID(subscriptionId, d.Get("publisher").(string), d.Get("offer").(string), d.Get("plan").(string))

log.Printf("[DEBUG] retrieving %s", id)

term, err := client.MarketplaceAgreementsGet(ctx, id)
agreementId := agreements.NewOfferPlanID(id.SubscriptionId, id.PublisherId, id.OfferId, id.PlanId)
term, err := client.MarketplaceAgreementsGet(ctx, agreementId)
if err != nil {
if !response.WasNotFound(term.HttpResponse) {
return fmt.Errorf("retrieving %s: %s", id, err)
Expand All @@ -93,16 +94,10 @@ func resourceMarketplaceAgreementCreateUpdate(d *pluginsdk.ResourceData, meta in
}
}
if accepted {
agreement, err := client.MarketplaceAgreementsGet(ctx, id)
if err != nil {
if !response.WasNotFound(agreement.HttpResponse) {
return fmt.Errorf("retrieving %s: %s", id, err)
}
}
return tf.ImportAsExistsError("azurerm_marketplace_agreement", id.ID())
}

resp, err := client.MarketplaceAgreementsGet(ctx, id)
resp, err := client.MarketplaceAgreementsGet(ctx, agreementId)
if err != nil {
return fmt.Errorf("retrieving %s: %s", id, err)
}
Expand All @@ -119,7 +114,7 @@ func resourceMarketplaceAgreementCreateUpdate(d *pluginsdk.ResourceData, meta in
terms.Properties.Accepted = utils.Bool(true)

log.Printf("[DEBUG] Accepting the Marketplace Terms for %s", id)
if _, err := client.MarketplaceAgreementsCreate(ctx, id, *terms); err != nil {
if _, err := client.MarketplaceAgreementsCreate(ctx, agreementId, *terms); err != nil {
return fmt.Errorf("accepting Terms for %s: %s", id, err)
}
log.Printf("[DEBUG] Accepted the Marketplace Terms for %s", id)
Expand All @@ -134,12 +129,13 @@ func resourceMarketplaceAgreementRead(d *pluginsdk.ResourceData, meta interface{
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := agreements.ParseOfferPlanID(d.Id())
id, err := agreements.ParsePlanID(d.Id())
if err != nil {
return err
}

term, err := client.MarketplaceAgreementsGet(ctx, *id)
agreementId := agreements.NewOfferPlanID(id.SubscriptionId, id.PublisherId, id.OfferId, id.PlanId)
term, err := client.MarketplaceAgreementsGet(ctx, agreementId)
if err != nil {
if response.WasNotFound(term.HttpResponse) {
log.Printf("[DEBUG] The Marketplace Terms was not found for %s", id)
Expand Down Expand Up @@ -172,13 +168,12 @@ func resourceMarketplaceAgreementDelete(d *pluginsdk.ResourceData, meta interfac
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := agreements.ParseOfferPlanID(d.Id())
id, err := agreements.ParsePlanID(d.Id())
if err != nil {
return err
}
idCancel := agreements.NewPlanID(id.SubscriptionId, id.PublisherId, id.OfferId, id.PlanId)

if _, err = client.MarketplaceAgreementsCancel(ctx, idCancel); err != nil {
if _, err = client.MarketplaceAgreementsCancel(ctx, *id); err != nil {
return fmt.Errorf("cancelling agreement for %s: %s", *id, err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2021-01-01/agreements"
"github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2015-06-01/agreements"
"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"
Expand Down Expand Up @@ -68,12 +68,13 @@ func TestAccMarketplaceAgreement_requiresImport(t *testing.T) {
}

func (t MarketplaceAgreementResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := agreements.ParseOfferPlanID(state.ID)
id, err := agreements.ParsePlanID(state.ID)
if err != nil {
return nil, err
}

resp, err := clients.Compute.MarketplaceAgreementsClient.MarketplaceAgreementsGet(ctx, *id)
agreementId := agreements.NewOfferPlanID(id.SubscriptionId, id.PublisherId, id.OfferId, id.PlanId)
resp, err := clients.Compute.MarketplaceAgreementsClient.MarketplaceAgreementsGet(ctx, agreementId)
if err != nil {
return nil, fmt.Errorf("retrieving Compute Marketplace Agreement %q", id)
}
Expand Down Expand Up @@ -136,7 +137,6 @@ func (r MarketplaceAgreementResource) cancelExistingAgreement(offer string) acce

idGet := agreements.NewOfferPlanID(subscriptionId, "barracudanetworks", offer, "hourly")
idCancel := agreements.NewPlanID(subscriptionId, "barracudanetworks", offer, "hourly")

existing, err := client.MarketplaceAgreementsGet(ctx, idGet)
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/virtualmachines"
"github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2021-01-01/agreements"
"github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2015-06-01/agreements"
"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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2021-01-01/agreements"
"github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2015-06-01/agreements"
"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"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/mariadb/2018-06-01/databases
github.com/hashicorp/go-azure-sdk/resource-manager/mariadb/2018-06-01/firewallrules
github.com/hashicorp/go-azure-sdk/resource-manager/mariadb/2018-06-01/servers
github.com/hashicorp/go-azure-sdk/resource-manager/mariadb/2018-06-01/virtualnetworkrules
github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2021-01-01/agreements
github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2015-06-01/agreements
github.com/hashicorp/go-azure-sdk/resource-manager/media/2021-11-01
github.com/hashicorp/go-azure-sdk/resource-manager/media/2021-11-01/accountfilters
github.com/hashicorp/go-azure-sdk/resource-manager/media/2021-11-01/accounts
Expand Down

0 comments on commit f3f1c0b

Please sign in to comment.