diff --git a/internal/juju/offers.go b/internal/juju/offers.go index b8428417..2574d88c 100644 --- a/internal/juju/offers.go +++ b/internal/juju/offers.go @@ -195,16 +195,17 @@ func (c offersClient) DestroyOffer(input *DestroyOfferInput) error { return err } - forceDestroy := false - //This code loops until it detects 0 connections in the offer or 3 minutes elapses + //This code loops until it detects 0 connections in the offer or 5 minutes elapses if len(offer.Connections) > 0 { end := time.Now().Add(5 * time.Minute) for ok := true; ok; ok = len(offer.Connections) > 0 { - //if we have been failing to destroy offer for 5 minutes then force destroy - //TODO: investigate cleaner solution (acceptance tests fail even if timeout set to 20m) + //if we have been failing to destroy offer for 5 minutes then fail on destroy if time.Now().After(end) { - forceDestroy = true - break + connections := make([]string, len(offer.Connections)) + for i, connection := range offer.Connections { + connections[i] = fmt.Sprintf("%s:%s", connection.SourceModelUUID, connection.Endpoint) + } + return fmt.Errorf("offer %q has remaining integrations: %s", input.OfferURL, strings.Join(connections, ", ")) } time.Sleep(10 * time.Second) offer, err = client.ApplicationOffer(input.OfferURL) @@ -214,7 +215,7 @@ func (c offersClient) DestroyOffer(input *DestroyOfferInput) error { } } - err = client.DestroyOffers(forceDestroy, input.OfferURL) + err = client.DestroyOffers(false, input.OfferURL) if err != nil { return err } diff --git a/internal/provider/resource_integration_test.go b/internal/provider/resource_integration_test.go index 4c334a2a..eb6ccd86 100644 --- a/internal/provider/resource_integration_test.go +++ b/internal/provider/resource_integration_test.go @@ -208,6 +208,8 @@ resource "juju_integration" "a" { application { offer_url = juju_offer.b.url } + + depends_on = [juju_offer.b] } `, srcModelName, aOS, dstModelName, bOS, viaCIDRs) } @@ -315,6 +317,8 @@ resource "juju_integration" "b1" { application { offer_url = juju_offer.a.url } + + depends_on = [juju_offer.a] } resource "juju_application" "b2" { @@ -339,6 +343,8 @@ resource "juju_integration" "b2" { application { offer_url = juju_offer.a.url } + + depends_on = [juju_offer.a] } variable "enable-b1-consumer" { diff --git a/internal/provider/resource_offer_test.go b/internal/provider/resource_offer_test.go index 53dd75af..396f06f0 100644 --- a/internal/provider/resource_offer_test.go +++ b/internal/provider/resource_offer_test.go @@ -101,6 +101,8 @@ resource "juju_integration" "int" { application { offer_url = juju_offer.offerone.url } + + depends_on = [juju_offer.offerone] } `, srcModelName, destModelName) }