Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

mysql_database import operation timeouts on terraform refresh action for the provider. #129

Open
dannyibishev opened this issue Jun 19, 2020 · 1 comment

Comments

@dannyibishev
Copy link

dannyibishev commented Jun 19, 2020

Terraform Version

terraform: 0.12.15
+ provider.mysql v1.9.0

Affected Resource(s)

  • mysql_database
  1. importing on the above resource doesn't work.
  2. code works and tested for plan and apply actions on new database instances.

This has previously been an issue in terraform core, but their ticket seems to have been closed for a while now. hashicorp/terraform#11264

After testing numerous ways including the recommended input=false approach, I still cannot get a valid import to work.

Terraform Configuration Files

# ----------------------------#
#! >> parent module block <<
# ----------------------------#

data "terraform_remote_state" "inventory" {
  backend = "s3"

  config = {
    bucket  = "<ommited>"
    key     = "<ommited>"
    region  = "eu-west-1"
    encrypt = true
  }
}

module "mysql_container" {
  /*
 * splat join hack required to deal with non instantiated db instances.
 * If db count = 0, then mysql resources will not get created.
 * if db count = 1 (no state transition), resources will be created.
 ! if db count = 1 and a transition occurs (0 > 1): you will need to do a targetted apply prior on the db
*/
  source = "../../modules/mysql_management"

  endpoint   = join("", data.terraform_remote_state.inventory.outputs.rds_map.endpoint)
  user       = join("", data.terraform_remote_state.inventory.outputs.rds_map.username)
  password   = join("", data.terraform_remote_state.inventory.outputs.rds_map.password)
  service    = "container"
  dependancy = null_resource.db_state_checker.id
}

# ------------------------------------------#
#! >> Lower level in child module block <<
# ------------------------------------------#

provider "mysql" {
  version = "~> 1.9"

  endpoint = var.endpoint
  username = var.user
  password = var.password
}

resource "mysql_database" "db" {
  for_each = var.endpoint == "" ? {} : lookup(local.database, var.service, "")

  name                  = each.key
  default_character_set = "latin"
  defaulty_collation    = "latin1_swedish_ci"

  lifecycle {
    prevent_destroy = true
  }
}

variable "endpoint" {
  type        = string
  description = "RDS mysql endpoint with port :3306"
}

variable "dependancy" {
  description = "a variable that causes the module to wait on the null_resource to finish"
}

variable "user" {
  type        = string
  description = "mysql username for master account"
}

variable "password" {
  type        = string
  description = "mysql password for master account"
}

Debug Output

module.mysql_container.mysql_database.db["container"]: Importing from ID "container"...
2020/06/18 17:47:52 [TRACE] EvalImportState: import module.mysql_container.mysql_database.db["container"] "container" produced instance object of type mysql_database
2020/06/18 17:47:52 [TRACE] [walkImport] Exiting eval tree: module.mysql_container.mysql_database.db["container"] (import id "container")
2020/06/18 17:47:52 [TRACE] vertex "module.mysql_container.mysql_database.db[\"container\"] (import id \"container\")": expanding dynamic subgraph
2020/06/18 17:47:52 [TRACE] vertex "module.mysql_container.mysql_database.db[\"container\"] (import id \"container\")": entering dynamic subgraph
2020/06/18 17:47:52 [TRACE] dag/walk: updating graph
2020/06/18 17:47:52 [TRACE] dag/walk: added new vertex: "import module.mysql_container.mysql_database.db[\"container\"] result"
2020/06/18 17:47:52 [TRACE] dag/walk: visiting "import module.mysql_container.mysql_database.db[\"container\"] result"
2020/06/18 17:47:52 [TRACE] vertex "import module.mysql_container.mysql_database.db[\"container\"] result": starting visit (*terraform.graphNodeImportStateSub)
module.mysql_container.mysql_database.db["container"]: Import prepared!
  Prepared mysql_database for import
2020/06/18 17:47:52 [TRACE] vertex "import module.mysql_container.mysql_database.db[\"container\"] result": evaluating
2020/06/18 17:47:52 [TRACE] [walkImport] Entering eval tree: import module.mysql_container.mysql_database.db["container"] result
2020/06/18 17:47:52 [TRACE] module.mysql_container: eval: *terraform.EvalSequence
2020/06/18 17:47:52 [TRACE] module.mysql_container: eval: *terraform.EvalGetProvider
2020/06/18 17:47:52 [TRACE] module.mysql_container: eval: *terraform.EvalRefresh
2020/06/18 17:47:52 [TRACE] GRPCProvider: ReadResource
2020-06-18T17:47:52.360+0100 [DEBUG] plugin.terraform-provider-mysql_v1.9.0_x4: 2020/06/18 17:47:52 [DEBUG] Waiting for state to become: [success]
2020-06-18T17:47:52.360+0100 [DEBUG] plugin.terraform-provider-mysql_v1.9.0_x4: 2020/06/18 17:47:52 [TRACE] Waiting 500ms before next try
module.mysql_container.mysql_database.db["container"]: Refreshing state... [id=container]
2020-06-18T17:47:52.863+0100 [DEBUG] plugin.terraform-provider-mysql_v1.9.0_x4: 2020/06/18 17:47:52 [TRACE] Waiting 1s before next try
2020-06-18T17:47:53.869+0100 [DEBUG] plugin.terraform-provider-mysql_v1.9.0_x4: 2020/06/18 17:47:53 [TRACE] Waiting 2s before next try
2020-06-18T17:47:55.874+0100 [DEBUG] plugin.terraform-provider-mysql_v1.9.0_x4: 2020/06/18 17:47:55 [TRACE] Waiting 4s before next try
2020/06/18 17:47:57 [TRACE] dag/walk: vertex "root" is waiting for "module.mysql_container.provider.mysql (close)"
2020/06/18 17:47:57 [TRACE] dag/walk: vertex "module.mysql_container.provider.mysql (close)" is waiting for "module.mysql_container.mysql_database.db[\"container\"] (import id \"container\")"
2020-06-18T17:47:59.878+0100 [DEBUG] plugin.terraform-provider-mysql_v1.9.0_x4: 2020/06/18 17:47:59 [TRACE] Waiting 8s before next try
2020/06/18 17:48:02 [TRACE] dag/walk: vertex "root" is waiting for "module.mysql_container.provider.mysql (close)"
2020/06/18 17:48:02 [TRACE] dag/walk: vertex "module.mysql_container.provider.mysql (close)" is waiting for "module.mysql_container.mysql_database.db[\"container\"] (import id \"container\")"
2020/06/18 17:48:07 [TRACE] dag/walk: vertex "root" is waiting for "module.mysql_container.provider.mysql (close)"
2020/06/18 17:48:07 [TRACE] dag/walk: vertex "module.mysql_container.provider.mysql (close)" is waiting for "module.mysql_container.mysql_database.db[\"container\"] (import id \"container\")"
2020-06-18T17:48:07.880+0100 [DEBUG] plugin.terraform-provider-mysql_v1.9.0_x4: 2020/06/18 17:48:07 [TRACE] Waiting 10s before next try
2020/06/18 17:48:12 [TRACE] dag/walk: vertex "root" is waiting for "module.mysql_container.provider.mysql (close)"
2020/06/18 17:48:12 [TRACE] dag/walk: vertex "module.mysql_container.provider.mysql (close)" is waiting for "module.mysql_container.mysql_database.db[\"container\"] (import id \"container\")"
2020/06/18 17:48:17 [TRACE] dag/walk: vertex "root" is waiting for "module.mysql_container.provider.mysql (close)"
2020/06/18 17:48:17 [TRACE] dag/walk: vertex "module.mysql_container.provider.mysql (close)" is waiting for "module.mysql_container.mysql_database.db[\"container\"] (import id \"container\")"

Expected Behavior

The provider is able to receive the provided data sources and able to refresh successfully in order for the import command to be successful.

Actual Behavior

Timeouts seem to point to localhost, despite being given an endpoint, username and password from data resources.

Steps to Reproduce

terraform import -input=false 'module.mysql_container.mysql_database.db["container"] container
or
terraform import 'module.mysql_container.mysql_database.db["container"] container

References

This has previously been an issue in terraform core, but their ticket seems to be closed for a while now, and it more resembled their core functionality which may be different for this provider. hashicorp/terraform#11264

@dannyibishev dannyibishev changed the title mysql_database import operation stuck on terraform refresh action for the provider. mysql_database import operation timeouts on terraform refresh action for the provider. Jun 19, 2020
@rfpludwick
Copy link

I've just come across this issue as well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants