juju / terraform-provider-juju

A Terraform provider for Juju
Apache License 2.0
19 stars 36 forks source link

Cross-model integrations across controllers #119

Open kian99 opened 1 year ago

kian99 commented 1 year ago

Hi there,

As far as I can tell there is no way to create integrations across models that are within different controllers. This is described in the Juju docs (see the link at the bottom of the page titled Scenario 2).

Is there any plan to support this or is there a way to do it currently?

juanmanuel-tirado commented 1 year ago

You're right. Integrations are only supported between applications deployed in the same model. The cross model integration requires the concept of offers which is not supported now. I will add this to the wish list.

kian99 commented 1 year ago

Thanks for the information! I was able to successfully consume the offer manually with juju consume and then use Terraform to relate to the offer that exists within the model so that is almost all the way there. The only other issue I have is that I want to relate a k8s application (in Controller A) to a machine app (in Controller B) and the Terraform provider also seems to be missing the --via option that can be provided to juju relate. I've made a PR to hopefully address this #120

cbartz commented 9 months ago

Hi @juanmanuel-tirado, what is the status of this issue? I am unable to integrate two applications using cross-model integration across controllers. I have successfully consumed the offer and am able to integrate manually using juju integrate, but not using the terraform provider. I am specifying the controllers within the offer_url, but it seems that this is being ignored.

used terraform provider 0.10.0 and juju 3.1.6

juanmanuel-tirado commented 9 months ago

Hi @cbartz . I no longer work in the project. @hmlanigan and @cderici can give you more details around this issue.

hmlanigan commented 9 months ago

@cbartz, are you using an offer resource and an integration resource? Or just the integration one? Please share the plan pieces and what errors you see.

cbartz commented 9 months ago

@hmlanigan I have manually consumed an offer from other-controller:admin/other-model using juju consume. Note that this offer is from a different controller. I can manually integrate with

juju integrate my-app saas-app

When I try to do this with Terraform, I get the following error message

 Error: model "admin/other-model" not found

Here is the terraform plan and here the juju status output.

kian99 commented 9 months ago

@cbartz If I recall back to when I did this, I think the after manually running juju consume the Terraform plan can now relate the two application as if they were in the same model i.e. instead of relating to an offer-url, relate to an application with the name of the SAAS app (effectively do the same thing as you did via the Juju CLI).

Note that you can't do the cross-controller integration completely in Terraform because the Juju Terraform provider is currently only aware of a single controller at a time, but the Juju CLI doesn't have that limitation. So you have to manually juju consume the offer then you can use Terraform afterwards if you want.

cbartz commented 2 months ago

@kian99 This did not work. I could do juju integrate grafana-agent loki (loki name of the saas app), but not the same with terraform. I get

│ Error: Client Error
│ 
│   with module.cos_integration.juju_integration.loki_push_api[0],
│   on ../../modules/cos/main.tf line 107, in resource "juju_integration" "loki_push_api":
│  107: resource "juju_integration" "loki_push_api" {
│ 
│ Unable to create integration, got error: the applications were not available to be integrated

See also https://pastebin.canonical.com/p/X5ZDcP8TvF/

kian99 commented 2 months ago

@cbartz,

I'm not sure why it wouldn't work, it's been a fair while since I tried it. It could be that something has changed in a recent version of the Terraform provider. Searching for the error "the applications were not available to be integrated" shows that comes from this portion of the provider code, where it waits for the specific apps to be ready before performing relations. That seems to have been added in JUJU-3442 which was released as part of v0.7.0 of the provider in May 2023, I filed this bug in December of 2022 so the change to "wait for applications" to be ready likely broke my workaround.

hemanthnakkina commented 2 months ago

I have the same issue in sunbeam when trying to cross model integrate with cos across remote juju controller.

Here is a sample setup used to reproduce the problem: https://pastebin.canonical.com/p/JgdJb8nj7t/

Error message:

juju_integration.keystone-to-traefik: Creating...
╷
│ Error: Client Error
│ 
│   with juju_integration.keystone-to-traefik,
│   on main.tf line 63, in resource "juju_integration" "keystone-to-traefik":
│   63: resource "juju_integration" "keystone-to-traefik" {
│ 
│ Unable to consume remote offer, got error: model "admin/ingress" not found (not found)
hmlanigan commented 1 month ago

@hemanthnakkina please add a small reproducer plan directly to this bug. Using a pastebin means the data is only available for a short time. The pastbins above no longer accessible.

hemanthnakkina commented 1 month ago

@hmlanigan Here are the steps (Used 2 VMs with juju+k8s):

On node-1

sudo snap install juju --channel 3.4/stable
sudo snap install microk8s --channel 1.28-strict/stable
sudo microk8s enable dns hostpath-storage metallb:10.121.193.180-10.121.193.190
sudo usermod -a -G snap_microk8s ubuntu
newgrp snap_microk8s
juju bootstrap --config controller-service-type=loadbalancer microk8s microk8s-1

# Plan on node-1 attached plan1-node1.txt
sudo snap install terraform --classic
terraform init
terraform apply -auto-approve

juju add-user remoteuser
juju grant remoteuser consume admin/ingress.traefik

On node-2

sudo snap install juju --channel 3.4/stable
sudo snap install microk8s --channel 1.28-strict/stable
sudo microk8s enable dns hostpath-storage metallb:10.121.193.191-10.121.193.200
sudo usermod -a -G snap_microk8s ubuntu
newgrp snap_microk8s
juju bootstrap --config controller-service-type=loadbalancer microk8s microk8s-2

juju register <>  # use controller name as remotemicrok8s
juju switch microk8s-2

# Plan on node-2: plan2-node2.txt
sudo snap install terraform --classic
terraform init
terraform apply -auto-approve -var ingress-offer-url=remotemicrok8s:admin/ingress.traefik

plan2-node2.txt plan1-node1.txt