hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.76k stars 9.12k forks source link

The resource cut the last 0 on the `elasticsearch_version` parameter #21813

Closed giorgiocerruti closed 4 months ago

giorgiocerruti commented 2 years ago

Community Note

Terraform CLI and Terraform AWS Provider Version

Affected Resource(s)

terraform -v Terraform v1.0.4 on linux_amd64

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key: https://keybase.io/hashicorp

resource "aws_elasticsearch_domain" "xs-ws-ec-search" {
  #   depends_on                  = [aws_cloudwatch_log_resource_policy.es-log-policy]
  domain_name           = var.domain_name
  elasticsearch_version = var.es_version # set to 7.10

  cluster_config {
    instance_type            = var.es_instance_type
    instance_count           = var.es_instance_count
    dedicated_master_enabled = var.es_dedicated_master
    dedicated_master_count   = var.es_dedicated_master_count
    dedicated_master_type    = var.es_dedicated_master_type
    zone_awareness_enabled   = var.es_zone_awereness

    zone_awareness_config {
      availability_zone_count = length(var.es_subnets)

    }
  }

  encrypt_at_rest {
    enabled = true
  }

  lifecycle {
    prevent_destroy = false
  }

  domain_endpoint_options {
    enforce_https       = true
    tls_security_policy = "Policy-Min-TLS-1-2-2019-07"
  }

  vpc_options {
    security_group_ids = var.es_security_groups
    subnet_ids         = var.es_subnets
  }

  ebs_options {
    ebs_enabled = true
    volume_type = "gp2"
    volume_size = var.volume_size
  }

  tags = var.tags 

  log_publishing_options {
    enabled                  = var.log_enabled
    log_type                 = "INDEX_SLOW_LOGS"
    cloudwatch_log_group_arn = aws_cloudwatch_log_group.xs-ws-ec-search-index.arn
  }
  log_publishing_options {
    enabled                  = var.log_enabled
    log_type                 = "SEARCH_SLOW_LOGS"
    cloudwatch_log_group_arn = aws_cloudwatch_log_group.xs-ws-ec-search-search.arn
  }
  log_publishing_options {
    enabled                  = var.log_enabled
    log_type                 = "ES_APPLICATION_LOGS"
    cloudwatch_log_group_arn = aws_cloudwatch_log_group.xs-ws-ec-search-application.arn
  }

}

Expected Behavior

The version must not be cut from the last 0

Actual Behavior

Setting version 7.10 terraform tries to set 7.1. I was not able to set the node instance type r6g.2xlarge.elasticsearch because of this, setting version 7.9 worked. The version was pèassed as a number but I've also tried to pass it as a string, same result.

Steps to Reproduce

  1. Set the elasticsearch_version = "7.10"
  2. terraform apply
+ advanced_options      = (known after apply)
      + arn                   = (known after apply)
      + domain_id             = (known after apply)
      + domain_name           = "rs-ws-ec-search-pod2"
      + elasticsearch_version = "7.1"
      + endpoint              = (known after apply)
      + id                    = (known after apply)
      + kibana_endpoint       = (known after apply)
abemusic commented 2 years ago

I'm also seeing this issue while migrating to terraform. We have an existing elastic search cluster running version "7.10" and I've imported the resource into terraform. When running a plan, it wants to downgrade us to "7.1" and there appears no way for terraform to take ownership of this cluster. We have a second cluster that's running "5.5" and it took control just fine.

Terraform v1.1.9
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v4.12.1
+ provider registry.terraform.io/hashicorp/dns v3.2.3
resource "aws_elasticsearch_domain" "default" {
  domain_name           = var.domain_name
  elasticsearch_version = var.es_version  # "7.10"
  ...
}
terraform plan
...

      ~ elasticsearch_version = "7.10" -> "7.1" # forces replacement

...
abemusic commented 2 years ago

I figured out the issue on my end. I was providing a string "7.10" to a variable that was of type number. For anyone else that might stumble upon this issue, first look at your version types and ensure you're using string instead of number or else the casting will lop off the 0.

variable "es_version" {
  type        = string  # not number :)
  description = "The Elastic Search version"
}
github-actions[bot] commented 5 months ago

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

github-actions[bot] commented 3 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.