aliyun / terraform-provider-alicloud

Terraform AliCloud provider
https://www.terraform.io/docs/providers/alicloud/
Mozilla Public License 2.0
589 stars 553 forks source link

[Bug] alicloud_mongodb_sharding_instance - Missing details on terraform output attributes `mongo_list` and `shard_list` #2299

Open jianzhiteh opened 4 years ago

jianzhiteh commented 4 years ago

Hi there, I have encounter some unexpected behaviours on MongoDB resource creation. Based on your documentation(https://www.terraform.io/docs/providers/alicloud/r/mongodb_sharding_instance.html#attributes-reference), Terraform can output the following details on resource creation:

  1. mongo_list
  2. shard_list

However the details of these 2 Terraform outputs are incomplete. Please refer to the "Actual Behavior" below.

Terraform Version

Terraform v0.12.19
terraform-provider-alicloud_v1.75.0_x4

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

provider "alicloud" {
  # Allow >= 1.57, < 2.0 version of the AliCloud provider.
  version = "~> 1.57"

  region = "cn-hongkong"
}

data "alicloud_zones" "mongodb_zones" {
  available_resource_creation = "MongoDB"
}

locals {
  mongodb_mongos_node_count  = 2
  mongodb_mongos_node_spec   = "dds.mongos.mid"
  mongodb_shard_node_count   = 2
  mongodb_shard_node_spec    = "dds.shard.mid"
  mongodb_shard_node_storage = 10
}

resource "alicloud_vpc" "vpc" {
  name       = "test-mongodb"
  cidr_block = "192.168.0.0/16"
}

resource "alicloud_vswitch" "vswitch" {
  name              = "test-mongodb-vswitch"
  vpc_id            = alicloud_vpc.vpc.id
  cidr_block        = "192.168.0.0/16"
  availability_zone = data.alicloud_zones.mongodb_zones.zones.0.id
}

resource "alicloud_mongodb_sharding_instance" "mongodb_cluster" {
  instance_charge_type = "PostPaid"
  engine_version       = "4.0"
  name                 = "test-mongodb"
  zone_id              = "cn-hongkong-b"
  vswitch_id           = alicloud_vswitch.vswitch.id
  account_password     = "asdf1234_123"
  security_ip_list     = ["192.168.0.0/16"]
  dynamic "mongo_list" {
    for_each = range(local.mongodb_mongos_node_count)

    content {
      node_class = local.mongodb_mongos_node_spec
    }
  }

  dynamic "shard_list" {
    for_each = range(local.mongodb_shard_node_count)

    content {
      node_class   = local.mongodb_shard_node_spec
      node_storage = local.mongodb_shard_node_storage
    }
  }
}

output "mongodb_mongos_list" {
  description = <<EOF
List of mongos details created. Includes node_id, connect_string and port.
EOF
  value       = alicloud_mongodb_sharding_instance.mongodb_cluster.mongo_list
}

output "mongodb_shard_list" {
  description = <<EOF
List of shard details created. Includes node_id, connect_string and port.
EOF
  value       = alicloud_mongodb_sharding_instance.mongodb_cluster.shard_list
}

Debug Output

https://gist.githubusercontent.com/jianzhiteh/57a3f344b148deae3efbdf7f2f017bf6/raw/940f82aede3c6ffb47f608ba129962081882003a/terraform_%2520alicloud_mongodb_sharding_output_bug

Panic Output

nil

Expected Behavior

  1. Terraform output mongo_list should return connection_string and node_id.
  2. Terraform output shard_list should return node_id.

Actual Behavior

  1. Terraform output mongo_list returns connection_string and node_id as empty string "".

    [
    {
      "connect_string" = ""
      "node_class" = "dds.mongos.mid"
      "node_id" = ""
      "port" = 0
    },
    {
      "connect_string" = ""
      "node_class" = "dds.mongos.mid"
      "node_id" = ""
      "port" = 0
    },
    ]
  2. Terraform output shard_list returns node_id as empty string "".

    [
    {
      "node_class" = "dds.shard.mid"
      "node_id" = ""
      "node_storage" = 10
    },
    {
      "node_class" = "dds.shard.mid"
      "node_id" = ""
      "node_storage" = 10
    },
    ]

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply
  2. Wait for the resource creation.
  3. Observe the printed Outputs on the console for mongodb_mongos_list and mongodb_shard_list.

Important Factoids

Nil

References

Nil

yinna123 commented 4 years ago

image Please download the latest terraform and then execute it. It has been fixed

jianzhiteh commented 4 years ago

Hi, referring to your console output, you might be running terraform apply for more than once. If you try on your end, on first terraform apply to create the MongoDB resource, the output doesn't return the node_id.

We need the node_id even for the first run as we are passing the output from this resource creation as input of another module, so getting empty list will fail our following modules. Please observe the attached screenshot.

Thanks! Screenshot 2020-03-26 at 6 59 28 PM