juju / terraform-provider-juju

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

Application creation not successful until storages for all apps in the batch are completed #539

Open hemanthnakkina opened 3 months ago

hemanthnakkina commented 3 months ago

Description

Deployed a terraform plan with a mix of application resources that requires storage and does not require storage. When terraform plan is applied, the "Creation complete" for application resource that does not require storage only printed after storages are created for all the applications.

The expectation is to complete the application resources that does not require storage with no dependency on storages of other applications and start creation of new resources that exist in plan.

This is observed on juju 3.5.3 + microk8s v1.28.10 cloud

Urgency

Casually reporting

Terraform Juju Provider version

0.13.0

Terraform version

1.9.3

Juju version

3.5.3

Terraform Configuration(s)

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

provider "juju" {}

resource "juju_model" "sunbeam" {
  name = var.model

  cloud {
    name   = var.cloud
    region = "localhost"
  }

  credential = var.credential
  config     = var.config
}

# 1 storage resource
resource "juju_application" "mysql" {
  model = juju_model.sunbeam.name
  name  = "mysql"

  charm {
    name     = "mysql-k8s"
    channel  = "8.0/stable"
    revision = null
  }

  config             = var.mysql-config
  storage_directives = var.mysql-storage
  units              = 1
  trust              = false
}

resource "juju_application" "mysql-router" {
  name  = "keystone-mysql-router"
  model = juju_model.sunbeam.name

  charm {
    name    = "mysql-router-k8s"
    channel = "8.0/stable"
  }

  units = 1
  trust = false
}

resource "juju_integration" "mysql-router-to-mysql" {
  model = juju_model.sunbeam.name

  application {
    name     = juju_application.mysql-router.name
    endpoint = "backend-database"
  }

  application {
    name     = juju_application.mysql.name
    endpoint = "database"
  }
}

# 2 storage resources
resource "juju_application" "keystone" {
  model = juju_model.sunbeam.name
  name  = "keystone"

  charm {
    name     = "keystone-k8s"
    channel  = "2024.1/edge"
  }

  config             = {}
  storage_directives = {}
  units              = 1
  trust              = false
}

resource "juju_integration" "service-to-mysql-router" {
  model = juju_model.sunbeam.name

  application {
    name     = juju_application.keystone.name
    endpoint = "database"
  }

  application {
    name     = juju_application.mysql-router.name
    endpoint = "database"
  }
}

# 4 storage resources
resource "juju_application" "vault" {
  model = juju_model.sunbeam.name
  name  = "vault"

  charm {
    name     = "vault-k8s"
    channel  = "1.15/edge"
    revision = 61
  }

  config             = var.vault-config
  storage_directives = var.vault-storage
  units              = 1
  trust              = false
}

# No storage resources
resource "juju_application" "bind" {
  name  = "bind"
  model = juju_model.sunbeam.name

  charm {
    name     = "designate-bind-k8s"
    channel  = "9/stable"
    revision = null
  }

  config = {}
  units  = 1
}

variable "model" {
  description = "Name of Juju model to use for deployment"
  type        = string
  default     = "openstack"
}

variable "cloud" {
  description = "Name of K8S cloud to use for deployment"
  type        = string
  default     = "microk8s"
}

# https://github.com/juju/terraform-provider-juju/issues/147
variable "credential" {
  description = "Name of credential to use for deployment"
  type        = string
  default     = "microk8s"
}

variable "config" {
  description = "Set configuration on model"
  type        = map(string)
  default     = {}
}

variable "mysql-config" {
  description = "Operator configs for MySQL deployment"
  type        = map(string)
  default = {
    "profile-limit-memory" = 3456
  }
}

variable "mysql-storage" {
  description = "Storage directives for MySQL deployment"
  type        = map(string)
  default     = {}
}

variable "vault-config" {
  description = "Operator config for Vault deployment"
  type        = map(string)
  default     = {}
}

variable "vault-storage" {
  description = "Operator storage directives for Vault deployment"
  type        = map(string)
  default     = {}
}

Reproduce / Test

terraform init
terraform apply -auto-approve | ts '[%Y-%m-%d %H:%M:%.S]'

Debug/Panic Output

Logs attached

Notes & References

I have run the terraform plan with modified terraform-juju-provider on main. The modifications are just printouts which should be reflected in debug log. Attached print.patch.txt that contains the changes.

Attached console and debug logs for terraform apply command and hostpath-provisioner logs which provisions storage for juju+microkk8s.

tfapplyconsoleout.log tfapplydebug.log hostpath-provisioner.log prints.patch.txt

From tfapplyconsoleout.log, bind application (no storage requirement) creation is started at 2024-08-05 03:02:20.786997 and completed at 2024-08-05 03:04:30.837884, that took 2 min 10 seconds for provider to consider it complete. On my observation the app is created in juju with active/idle status in 1 min.

From tfapplydebug.log, it shows bind is waiting for storage vault-raft-3 but that particular storage is required for vault application but not bind application 2024-08-05T03:02:30.370Z [DEBUG] provider.terraform-provider-juju_v0.13.0: waiting for application "bind": @caller=github.com/juju/terraform-provider-juju/internal/juju/client.go:235 @module=juju.client err="retrying: storage label \"vault-raft-3\" missing detail" timestamp=2024-08-05T03:02:30.370Z

hemanthnakkina commented 3 months ago

https://github.com/juju/terraform-provider-juju/issues/535 can be related