Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JUJU-1969] Fix channel during imports #98

Merged

Conversation

juanmanuel-tirado
Copy link
Contributor

During the import operation the channel attribute for charms was ignored. It looks like a hardcoded latest/stable value remained there. In this change, we obtain the channel from the response as done with the other fields. This should fix #95.

Following the example mentioned at #95, you can use these steps for testing.

Compile the terraform provider and make it available as usual.

 $ go build
 $ cp terraform-provider-juju <path-to-terraform>/.terraform.d/plugins/registry.terraform.io/juju/juju/0.4.1/linux_amd64/terraform-provider-juju_v0.4.1
 $ cd <path-to-wherever-you-put-the demo.tf>

Using microk8s create a model and a redis deployment.

juju add-model newmodel
juju deploy redis-k8s --channel=edge -m newmodel

Use the following terraform plan:

terraform {
   required_providers {
     juju = {
       source  = "juju/juju"
       version = "0.4.1"
     }
  }
}

provider "juju" {}

resource "juju_model" "development" {
  name = "newmodel"
}

resource "juju_application" "redis_cache" {
  name  = "redis-cache2"
  model = juju_model.development.name

  charm {
    name    = "redis-k8s"
    channel = "edge"
  }

  units = 1
}

Initialize a terraform environment and import the redis application.

terraform init
terraform import juju_application.redis_cache newmodel:redis-k8

Now the plan should not indicate any changes in the channel attribute:

terraform plan
....
# juju_application.redis_cache must be replaced
-/+ resource "juju_application" "redis_cache" {
      - config = {} -> null
      ~ id     = "newmodel:redis-k8s" -> (known after apply)
      ~ name   = "redis-k8s" -> "redis-cache2" # forces replacement
        # (3 unchanged attributes hidden)

      ~ charm {
            name     = "redis-k8s"
          ~ revision = 19 -> (known after apply)
          ~ series   = "focal" -> (known after apply)
            # (1 unchanged attribute hidden)
        }
    }

  # juju_model.development will be created
  + resource "juju_model" "development" {
      + id   = (known after apply)
      + name = "newmodel"
      + type = (known after apply)

      + cloud {
          + name   = (known after apply)
          + region = (known after apply)
        }
    }

@juanmanuel-tirado juanmanuel-tirado added the kind/bug indicates a bug in the project label Oct 12, 2022
@juanmanuel-tirado juanmanuel-tirado self-assigned this Oct 12, 2022
Copy link

@cderici cderici left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Typo in QA Steps threw me off a bit :)

terraform init
terraform import juju_application.redis_cache newmodel:redis-k8 <----------------------- k8s

@juanmanuel-tirado juanmanuel-tirado merged commit f55ac33 into juju:main Oct 13, 2022
@juanmanuel-tirado juanmanuel-tirado deleted the JUJU-1969_fix_channel_import branch October 13, 2022 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug indicates a bug in the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

After terraform import the charm channel isn't correctly recognised
3 participants