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

Can't use programmatic resource names #571

Closed
dgarstang opened this Issue Nov 17, 2014 · 3 comments

Comments

Projects
None yet
3 participants
@dgarstang

dgarstang commented Nov 17, 2014

resource "aws_instance" "mongo-cfg01.${var.env_name}.${var.domain_name}" {
    ami = "${var.ami_id}"
    instance_type = "m1.small"
    tags {
        Name = "mongo-cfg01.${var.env_name}.${var.domain_name}"
    }
}
Douglass-MacBook-Pro:terraform doug$ terraform plan -var-file dev.tfvars 
There are warnings and/or errors related to your configuration. Please
fix these before continuing.

Warnings:

  * aws_instance.mongo-cfg01.${var.env_name}.${var.domain_name}: module name can only contain letters, numbers, dashes, and underscores.
This will be an error in Terraform 0.4

Seems I can't use programmatic resource names. We've mapped environments (qa, dev, prod etc) to domain names, e.g.: mongo-cfg01.prod.foobar.com, mongo-cfg01.qa.foobar.com and so on. This means we'd have to have one file per environment, which does not scale.

@armon

This comment has been minimized.

Show comment
Hide comment
@armon

armon Nov 18, 2014

Member

The names in Terraform are just logical for the purposes of referring to them. You want to parameterize the values inside the resource, and not the name itself, so this is by design.

Multiple environments are supported by using different variable and state files.

Member

armon commented Nov 18, 2014

The names in Terraform are just logical for the purposes of referring to them. You want to parameterize the values inside the resource, and not the name itself, so this is by design.

Multiple environments are supported by using different variable and state files.

@dgarstang

This comment has been minimized.

Show comment
Hide comment
@dgarstang

dgarstang Nov 19, 2014

Not a bug.

dgarstang commented Nov 19, 2014

Not a bug.

@yellowmegaman

This comment has been minimized.

Show comment
Hide comment
@yellowmegaman

yellowmegaman Sep 7, 2018

Hi! After I've started using modules, this is a problem once again.
For google_dns_record_set managed_zone argument is required.
So after defining zone as module, I cant reference it in records for different zones.

modules/dns-zone/main.tf

resource "google_dns_managed_zone" "dns-zone" {
  name        = "${var.name}"
  dns_name    = "${var.dns_name}"
  description = "${var.description}"
}

dns.tf

module "test0-dns-zone" {
  source      = "modules/dns-zone"
  name        = "test0-zone"
  dns_name    = "test0.im."
  description = "Developer test0 DNS zone"
}
module "test1-dns-zone" {
  source      = "modules/dns-zone"
  name        = "test1-zone"
  dns_name    = "test1.im."
  description = "Developer test1 DNS zone"
}

records.tf

resource "google_dns_record_set" "test1_oktanium_im" {
  name = "test1.${google_dns_managed_zone.dns-zone.dns_name}"
  type = "A"
  ttl  = 60
  managed_zone = "${google_dns_managed_zone.dns-zone.name}"
  rrdatas = [
    "${google_compute_instance.somevm.0.network_interface.0.access_config.0.assigned_nat_ip}",
  ]
}

So, basically all my zones will have dns-zone name.

Maybe modules approach is not the best for zones/records? Or maybe zones as modules should be named.

yellowmegaman commented Sep 7, 2018

Hi! After I've started using modules, this is a problem once again.
For google_dns_record_set managed_zone argument is required.
So after defining zone as module, I cant reference it in records for different zones.

modules/dns-zone/main.tf

resource "google_dns_managed_zone" "dns-zone" {
  name        = "${var.name}"
  dns_name    = "${var.dns_name}"
  description = "${var.description}"
}

dns.tf

module "test0-dns-zone" {
  source      = "modules/dns-zone"
  name        = "test0-zone"
  dns_name    = "test0.im."
  description = "Developer test0 DNS zone"
}
module "test1-dns-zone" {
  source      = "modules/dns-zone"
  name        = "test1-zone"
  dns_name    = "test1.im."
  description = "Developer test1 DNS zone"
}

records.tf

resource "google_dns_record_set" "test1_oktanium_im" {
  name = "test1.${google_dns_managed_zone.dns-zone.dns_name}"
  type = "A"
  ttl  = 60
  managed_zone = "${google_dns_managed_zone.dns-zone.name}"
  rrdatas = [
    "${google_compute_instance.somevm.0.network_interface.0.access_config.0.assigned_nat_ip}",
  ]
}

So, basically all my zones will have dns-zone name.

Maybe modules approach is not the best for zones/records? Or maybe zones as modules should be named.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment