juju / terraform-provider-juju

A Terraform provider for Juju
Apache License 2.0
21 stars 41 forks source link

Unable to relate to consumed offer #437

Open kian99 opened 7 months ago

kian99 commented 7 months ago

Description

The Juju TF provider currently doesn't support cross-controller relations because it can only speak to 1 controller at a given time. To workaround this issue it was hoped to manually run a juju consume <offer-url> <application-name> and then perform an integration in the provider between an application and the consumed offer. The consumed offer becomes a SAAS in the Juju model which we can then try and relate to.

The above fails with error details described below. Using the Juju CLI it is possible to relate a local application to a SAAS offer.

Urgency

Casually reporting

Terraform Juju Provider version

0.10.1

Terraform version

v1.7.5

Terraform Configuration(s)

A snippet of a TF plan is below.

resource "juju_integration" "my-app_consumed-app" {
  model = var.juju_model_name

  application {
    name = juju_application.my-app.name
  }

  application {
    name = "my-consumed-app"
  }
}

Reproduce / Test

- juju add-model test
- juju consume <offer-url> my-consumed-app
- terraform apply

Debug/Panic Output

╷
│ Error: Client Error
│ 
│   with module.contracts-core.juju_integration.contracts-k8s_loki,
│   on ../../modules/contracts/main.tf line 150, in resource "juju_integration" "contracts-k8s_loki":
│  150: resource "juju_integration" "contracts-k8s_loki" {
│ 
│ Unable to create integration, got error: the applications were not available to be integrated
╵

Notes & References

I believe the issue comes about because of this line in CreateIntegration which waits for the desired applications to become available which underneath calls client.ApplicationsInfo. Because the consumed application is a SAAS, I believe it is never returned in the call to client.ApplicationsInfo and that is why we get the error "the applications were not available to be integrated".

I'm not sure what the best resolution is for this but some ideas I've thought up are:

cderici commented 7 months ago

@kian99 thanks for opening this, can you please give a reproducer with a minimal plan required to reproduce the issue? Thanks!

hmlanigan commented 7 months ago

@kian99 have you tried making the offer from a different controller a data source in your plan? As well, the offer should be represented in the juju_integration as "offer_url" not an "application".

For example:

data "juju_offer" "a" {
    url = "admin/modela.myconsumedapplication"
}

resource "juju_integration" "my-app_consumed-app" {
  model = var.juju_model_name

  application {
    name = juju_application.my-app.name
  }

  application {
    offer_url = data.juju_offer.a.url
  }
}