diff --git a/azurerm/internal/services/compute/marketplace_agreement_resource.go b/azurerm/internal/services/compute/marketplace_agreement_resource.go index 2547460541b4..f7094caa35c4 100644 --- a/azurerm/internal/services/compute/marketplace_agreement_resource.go +++ b/azurerm/internal/services/compute/marketplace_agreement_resource.go @@ -78,31 +78,37 @@ func resourceArmMarketplaceAgreementCreateUpdate(d *schema.ResourceData, meta in log.Printf("[DEBUG] Retrieving the Marketplace Terms for Publisher %q / Offer %q / Plan %q", publisher, offer, plan) if features.ShouldResourcesBeImported() { - agreement, err := client.Get(ctx, publisher, offer, plan) + term, err := client.Get(ctx, publisher, offer, plan) if err != nil { - if !utils.ResponseWasNotFound(agreement.Response) { - return fmt.Errorf("Error retrieving agreement for Publisher %q / Offer %q / Plan %q: %s", publisher, offer, plan, err) + if !utils.ResponseWasNotFound(term.Response) { + return fmt.Errorf("Error retrieving the Marketplace Terms for Publisher %q / Offer %q / Plan %q: %s", publisher, offer, plan, err) } } accepted := false - if props := agreement.AgreementProperties; props != nil { + if props := term.AgreementProperties; props != nil { if acc := props.Accepted; acc != nil { accepted = *acc } } if accepted { + agreement, err := client.GetAgreement(ctx, publisher, offer, plan) + if err != nil { + if !utils.ResponseWasNotFound(agreement.Response) { + return fmt.Errorf("Error retrieving agreement for Publisher %q / Offer %q / Plan %q: %s", publisher, offer, plan, err) + } + } return tf.ImportAsExistsError("azurerm_marketplace_agreement", *agreement.ID) } } terms, err := client.Get(ctx, publisher, offer, plan) if err != nil { - return fmt.Errorf("Error retrieving agreement for Publisher %q / Offer %q / Plan %q: %s", publisher, offer, plan, err) + return fmt.Errorf("Error retrieving the Marketplace Terms for Publisher %q / Offer %q / Plan %q: %s", publisher, offer, plan, err) } if terms.AgreementProperties == nil { - return fmt.Errorf("Error retrieving agreement for Publisher %q / Offer %q / Plan %q: AgreementProperties was nil", publisher, offer, plan) + return fmt.Errorf("Error retrieving the Marketplace Terms for Publisher %q / Offer %q / Plan %q: AgreementProperties was nil", publisher, offer, plan) } terms.AgreementProperties.Accepted = utils.Bool(true) @@ -137,22 +143,22 @@ func resourceArmMarketplaceAgreementRead(d *schema.ResourceData, meta interface{ offer := id.Path["offers"] plan := id.Path["plans"] - resp, err := client.Get(ctx, publisher, offer, plan) + term, err := client.Get(ctx, publisher, offer, plan) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[DEBUG] Agreement was not found for Publisher %q / Offer %q / Plan %q", publisher, offer, plan) + if utils.ResponseWasNotFound(term.Response) { + log.Printf("[DEBUG] The Marketplace Terms was not found for Publisher %q / Offer %q / Plan %q", publisher, offer, plan) d.SetId("") return nil } - return fmt.Errorf("Error retrieving agreement for Publisher %q / Offer %q / Plan %q: %s", publisher, offer, plan, err) + return fmt.Errorf("Error retrieving the Marketplace Terms for Publisher %q / Offer %q / Plan %q: %s", publisher, offer, plan, err) } d.Set("publisher", publisher) d.Set("offer", offer) d.Set("plan", plan) - if props := resp.AgreementProperties; props != nil { + if props := term.AgreementProperties; props != nil { if accepted := props.Accepted != nil && *props.Accepted; !accepted { // if props.Accepted is not true, the agreement does not exist d.SetId("") diff --git a/website/docs/r/marketplace_agreement.html.markdown b/website/docs/r/marketplace_agreement.html.markdown index 7e9ea601ed86..dc2d7805e9a3 100644 --- a/website/docs/r/marketplace_agreement.html.markdown +++ b/website/docs/r/marketplace_agreement.html.markdown @@ -50,5 +50,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/d Marketplace Agreement can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_marketplace_agreement.example /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.MarketplaceOrdering/offerTypes/virtualmachine/agreements/publisher1/offers/offer1/plans/plan1 +terraform import azurerm_marketplace_agreement.example /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.MarketplaceOrdering/agreements/publisher1/offers/offer1/plans/plan1 ```