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

output variables are causing issue with external resources #134

Closed
MDBox opened this issue Nov 19, 2019 · 2 comments
Closed

output variables are causing issue with external resources #134

MDBox opened this issue Nov 19, 2019 · 2 comments

Comments

@MDBox
Copy link
Contributor

MDBox commented Nov 19, 2019

Summary

We have noticed that when we change the instance count out external drive mounts are flagged to be replaced. I tracked this back to how the output is being wrapped in function calls such as, compact. This function seems to always return a new list, which it seem that Terraform will then flag everything that uses it as being new. I feel these function calls served a purpose in the older version when the resource was separated but now I do not see a reason for them.

Example

module "test_cluster" {
  source  = "terraform-aws-modules/ec2-instance/aws"
  version = "~> v2.0"

  name           = "${var.network_name} Test Cluster"
  instance_count = var.resource_count

  ami                                = var.image_id
  instance_type               = var.resource_type
  key_name                      = var.key_name
  monitoring                    = false
  vpc_security_group_ids      = [aws_security_group.test.id]
  subnet_id                      = var.subnet_id
  associate_public_ip_address = false
}

resource "aws_ebs_volume" "test_data_volume" {
  count = var.resource_count

  availability_zone = module.test_cluster.availability_zone[count.index]
  size                      = var.data_remote_volume_size
  type                     = var.data_remote_volume_type
}

resource "aws_volume_attachment" "test_data_volume_attachment" {
  count = var.resource_count

  device_name = "/dev/xvdh"
  volume_id   = aws_ebs_volume.test_data_volume.*.id[count.index]
  instance_id = module.test_cluster.id[count.index]
}
  • When var.resource_count changes, aws_volume_attachment and aws_ebs_volume are flagged to be replaced.
  • If I remove the function methods in the output.tf var the volume and attachments seem to keep between apply.

Possible Solution

I propose the following update to the output.tf file so that it is easier to use this module with external drives and null_resource steps.

locals {
  this_id                           = aws_instance.this.*.id
  this_availability_zone            = aws_instance.this.*.availability_zone
  this_key_name                     = aws_instance.this.*.key_name
  this_public_dns                   = aws_instance.this.*.public_dns
  this_public_ip                    = aws_instance.this.*.public_ip
  this_primary_network_interface_id = aws_instance.this.*.primary_network_interface_id
  this_private_dns                  = aws_instance.this.*.private_dns
  this_private_ip                   = aws_instance.this.*.private_ip
  this_placement_group              = aws_instance.this.*.placement_group
  this_security_groups              = aws_instance.this.*.security_groups
  this_vpc_security_group_ids       = aws_instance.this.*.vpc_security_group_ids
  this_subnet_id                    = aws_instance.this.*.subnet_id
  this_credit_specification         = aws_instance.this.*.credit_specification
  this_tags                         = aws_instance.this.*.tags
  this_volume_tags                  = aws_instance.this.*.volume_tags
  this_password_data                = aws_instance.this.*.password_data
}
@antonbabenko
Copy link
Member

Fixed by #135

v2.9.0 has been released.

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 9, 2022
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