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

Cannot ignore changes for replication_specs when autoscaling is enabled #888

Closed
ilya-scale opened this issue Oct 27, 2022 · 12 comments
Closed

Comments

@ilya-scale
Copy link

ilya-scale commented Oct 27, 2022

Terraform CLI and Terraform MongoDB Atlas Provider Version

Terraform v1.3.3
on linux_amd64
+ provider registry.terraform.io/mongodb/mongodbatlas v1.4.3

Terraform Configuration File

resource "mongodbatlas_advanced_cluster" "common" {
  project_id             = mongodbatlas_project.myproject.id
  name                   = "common"
  cluster_type           = "REPLICASET"
  mongo_db_major_version = "6.0"
  version_release_system = "LTS"
  backup_enabled         = var.mongodb_atlas.common_cluster.backup_enabled
  pit_enabled            = var.mongodb_atlas.common_cluster.point_in_time_backup_enabled

  replication_specs {
    region_configs {
      provider_name = "AZURE"
      region_name   = "EUROPE_NORTH"
      priority      = 7

      electable_specs {
        instance_size = var.mongodb_atlas.common_cluster.instance_size
        node_count    = 3
      }

      auto_scaling {
        disk_gb_enabled            = true
        compute_enabled            = true
        compute_scale_down_enabled = true
        compute_min_instance_size  = var.mongodb_atlas.common_cluster.instance_size
        compute_max_instance_size  = var.mongodb_atlas.common_cluster.max_instance_size
      }
    }
  }

  lifecycle {
    ignore_changes = [
      replication_specs # I would like to have a more fine grained control only for instance_size
    ]
    prevent_destroy = true
  }
}

Steps to Reproduce

  1. Create a cluster with terraform that supports autoscaling
  2. Add some load to the cluster so that it can be autoscaled
  3. Wait for the autoscaling to kick in
  4. Run terraform

Expected Behavior

I expect that there is a possibility to ignore instance_size

Actual Behavior

It is not possible to do since terraform does not support referencing elements of a set. This is what I get if I try to reference region_configs:

Block type "replication_specs" is represented by a set of objects, and set elements do not have addressable keys. To find elements matching specific criteria, use a "for" expression with an "if" clause.

Debug Output

Crash Output

Additional Context

References

An issue in terraform core that says pretty much that it is not possible to reference sets and providers should use e.g. a list: hashicorp/terraform#26359

@martinstibbe
Copy link
Contributor

martinstibbe commented Nov 2, 2022

@ilya-scale We will have to explore options to restructure the datatype to a list Internal ticket INTMDB-464

@ilya-scale
Copy link
Author

ilya-scale commented Nov 2, 2022

Sounds great! Maybe there are better options though that will allow to use autoscaling without an ignore, i.e. not specifying the instance_size directly (at least to have it as an option), but always using the compute_min_instance_size config from autoscaling e.g. as a starting point

@ivan-sukhomlyn
Copy link

@martinstibbe thanks for taking it into a backlog.
I'm waiting for such a possibility as well. Seems like it will require changing of attributes structure to list or map instead of a set - hashicorp/terraform#26359 (comment).

Error example,

╷
│ Error: Cannot index a set value
│ 
│   on mongodb_atlas_cluster.tf line 70, in resource "mongodbatlas_advanced_cluster" "product_api":
│   70:       replication_specs.region_configs.electable_specs.instance_size
│ 
│ Block type "replication_specs" is represented by a set of objects, and set elements do not have addressable keys. To find elements matching specific criteria, use a
│ "for" expression with an "if" clause.

@leo-ferlin-sutton
Copy link
Contributor

Just wanted to add a +1. We are very interested in this as well.

@Zuhairahmed
Copy link
Contributor

Zuhairahmed commented Jan 18, 2023

@ilya-scale @leo-ferlin-sutton @ivan-sukhomlyn brief update, we have allocated this fix to our next v1.8.0 release which should be out next week. will keep you posted when it has been published to the Terraform Registry.

@icco
Copy link

icco commented Jan 23, 2023

Similar issue but ours is slightly more complex in that our replication_specs and region_configs are dynamic. Just wanted to flag the use case so it gets tested with your 1.0 fix.

  replication_specs {
    dynamic "region_configs" {
      for_each = var.regions
      content {
        region_name   = replace(upper(region_configs.value["region_name"]), "-", "_")
        provider_name = "AWS"
        priority      = region_configs.value["electable_nodes"] > 0 ? region_configs.value["priority"] : 0

        electable_specs {
          node_count    = region_configs.value["electable_nodes"]
          instance_size = var.provider_default_instance_size
        }

        read_only_specs {
          node_count    = region_configs.value["read_only_nodes"]
          instance_size = var.provider_default_instance_size
        }

        auto_scaling {
          disk_gb_enabled            = true
          compute_enabled            = true
          compute_scale_down_enabled = true
          compute_min_instance_size  = var.provider_auto_scaling_compute_min_instance_size
          compute_max_instance_size  = var.provider_auto_scaling_compute_max_instance_size
        }
      }
    }

@icco
Copy link

icco commented Jan 23, 2023

Worth also noting that your docs about auto_scaling recommend a solution that does not work: https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/advanced_cluster#auto_scaling

@Zuhairahmed
Copy link
Contributor

@ilya-scale @leo-ferlin-sutton @ivan-sukhomlyn @icco we just released v1.8.0, feel free to give it try! issue should have been resolved.

@Zuhairahmed Zuhairahmed removed the not_stale Not stale issue or PR label Jan 27, 2023
@ivan-sukhomlyn
Copy link

I can confirm that the issue has been fixed with the v1.8.0 version.

Config example,

  lifecycle {
    # as storage and compute autoscaling is enabled
    ignore_changes = [
      disk_size_gb,
      replication_specs[0].region_configs[0].electable_specs[0].instance_size
    ]
  }
$ terraform version
+ provider registry.terraform.io/mongodb/mongodbatlas v1.8.0

Thanks @Zuhairahmed @evertsd 👍

@Zuhairahmed
Copy link
Contributor

Wonderful to hear! Thanks for the confirmation @ivan-sukhomlyn

@ilya-scale
Copy link
Author

It seems to work fine for me as well, thanks for the fix!

@leo-ferlin-sutton
Copy link
Contributor

I agree. Thanks a lot!

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

No branches or pull requests

6 participants