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

Expose optional blocks #6974

Closed
joshuaspence opened this issue Jun 1, 2016 · 2 comments
Closed

Expose optional blocks #6974

joshuaspence opened this issue Jun 1, 2016 · 2 comments

Comments

@joshuaspence
Copy link
Contributor

I know that Terraform doesn't support conditionals, but I was wondering if three was any other way to support this use case... I have an instance module which we use to create aws_instance resources. The reason for using a module is to avoid having to redeclare user_data everrywhere (we use a shared bootstrap script as user data). Currently, our module basically looks like this:

module "user_data" {
  source = "../user_data"

  puppet_realm = "${var.puppet_realm}"
  puppet_role  = "${var.puppet_role}"
  region       = "${var.region}"
}

resource "aws_instance" "instance" {
  ami               = "${var.ami}"
  availability_zone = "${element(split(",", var.availability_zone), count.index)}"
  ebs_optimized     = "${var.ebs_optimized}"
  instance_type     = "${var.instance_type}"
  monitoring        = "${var.monitoring}"

  security_groups        = ["${compact(concat(split(",", var.security_groups), var.common_security_group))}"]
  vpc_security_group_ids = ["${compact(split(",", var.vpc_security_group_ids))}"]

  subnet_id                   = "${var.subnet_id}"
  associate_public_ip_address = "${var.associate_public_ip_address}"
  private_ip                  = "${var.private_ip}"
  source_dest_check           = "${var.source_dest_check}"

  user_data            = "${module.user_data.rendered}"
  iam_instance_profile = "${var.iam_instance_profile}"

  tags {
    Name  = "${var.name}"
    realm = "${var.puppet_realm}"
    role  = "${var.puppet_role}"
  }

  lifecycle {
    ignore_changes = ["ami", "user_data"]
  }

  count = "${var.count}"
}

I want to add support for root_block_device mapping, but this mapping should only exist for EBS-backed instances. Is there anyway to achieve this? Can I just do something like this and set the default value for ${var.root_block_device_volume_size} to "" or some such equivalent?

root_block_device {
  volume_size = "${var.root_block_device_volume_size}"
}
@apparentlymart
Copy link
Contributor

Hi @joshuaspence! Sorry for the long silence here. This issue was using an older labeling scheme and so we missed it on previous update passes.

The problem you described here is the same idea as for #7034, which is now closed due to the addition of a new feature in master ready for the forthcoming v0.12.0 release. I left some comments over there showing how it can be used to generate nested blocks based on variables.

@apparentlymart apparentlymart added this to the v0.12.0 milestone Nov 7, 2018
@ghost
Copy link

ghost commented Mar 31, 2020

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.

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants