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 resource not committed to tfstate file #4369

Closed
packplusplus opened this issue Dec 17, 2015 · 3 comments
Closed

Output resource not committed to tfstate file #4369

packplusplus opened this issue Dec 17, 2015 · 3 comments

Comments

@packplusplus
Copy link

If an output references a resource attribute that doesn't exist, the output fails silently and doesn't show up in the tfstate file.

In my case, a subnet didn't have auto assign ip turned on, and when an instance was launched there, no output showed up. Here's a simplified test case. You need to disable auto-assign ip in the default subnets for this test case to work. I assume it applies to all calculated attributes / values.

FWIW: referencing variables that don't exist errors on compile. Maybe calculated variables / attributes should dereference as "false" or "" if the data doesn't exist.

provider "aws" {
  region = "us-west-2"
}

resource "aws_instance" "test" {
  #centos6 community
  ami = "ami-81d092b1"
  instance_type = "t2.micro"

  associate_public_ip_address = false
}

output "test" {
  value = "echo ${aws_instance.test.public_ip}"
}

output

$ terraform apply
aws_instance.test: Creating...
  ami:                         "" => "ami-81d092b1"
  associate_public_ip_address: "" => "0"
  availability_zone:           "" => "<computed>"
  ebs_block_device.#:          "" => "<computed>"
  ephemeral_block_device.#:    "" => "<computed>"
  instance_type:               "" => "t2.micro"
  key_name:                    "" => "<computed>"
  placement_group:             "" => "<computed>"
  private_dns:                 "" => "<computed>"
  private_ip:                  "" => "<computed>"
  public_dns:                  "" => "<computed>"
  public_ip:                   "" => "<computed>"
  root_block_device.#:         "" => "<computed>"
  security_groups.#:           "" => "<computed>"
  source_dest_check:           "" => "1"
  subnet_id:                   "" => "<computed>"
  tenancy:                     "" => "<computed>"
  vpc_security_group_ids.#:    "" => "<computed>"
aws_instance.test: Creation complete

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.

State path: terraform.tfstate
$ terraform show
aws_instance.test:
  id = i-6ff3b6b6
  ami = ami-81d092b1
  associate_public_ip_address = false
  availability_zone = us-west-2b
  ebs_block_device.# = 0
  ebs_optimized = false
  ephemeral_block_device.# = 0
  iam_instance_profile = 
  instance_type = t2.micro
  monitoring = false
  private_dns = ip-172-31-25-150.us-west-2.compute.internal
  private_ip = 172.31.25.150
  public_dns = 
  root_block_device.# = 1
  root_block_device.0.delete_on_termination = false
  root_block_device.0.iops = 24
  root_block_device.0.volume_size = 8
  root_block_device.0.volume_type = gp2
  security_groups.# = 0
  source_dest_check = true
  subnet_id = subnet-b3aa40c4
  tags.# = 0
  tenancy = default
  vpc_security_group_ids.# = 1
  vpc_security_group_ids.434905629 = sg-2462e741

$ terraform output
The state file has no outputs defined. Define an output
in your configuration with the `output` directive and re-run
`terraform apply` for it to become available.
@stack72
Copy link
Contributor

stack72 commented Dec 17, 2015

@packplusplus you don't need the echo

output "test" {
  value = "${aws_instance.test.public_ip}"
}

@mitchellh
Copy link
Contributor

Going to centralize on other dups of this, see #5334

@ghost
Copy link

ghost commented Apr 21, 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 Apr 21, 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

5 participants