hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.62k stars 9.55k forks source link

aws_cloudformation_stack output values broken? #6602

Closed spanktar closed 8 years ago

spanktar commented 8 years ago

When using a CloudFormation template to create an ElastiCache replication cluster, I added some outputs so I could get the EC Cluster's primary address (for eventual use in Consul). Instead of getting the expected output value (imi1dyi60vqjp42a.FOO.ng.0001.usw2.cache.amazonaws.com:6379) I got the following string: B780FFEC-B661-4EB8-9236-A01737AD98B6. All other outputs are working correctly.

Terraform Version

Terraform v0.6.12

Affected Resource(s)

cloudformation_template_snippet

    "Outputs": {
        "ElastiCachePrimaryEndpoint":{
            "Description":"The primary endpoint of the Redis cluster",
            "Value":{
                "Fn::GetAtt": [
                    "ReplicationGroupName",
                    "PrimaryEndPoint.Address" ]
            }
        }
    }

terraform file snippet

output "elasticache_primary_address" {
    value = "${aws_cloudformation_stack.mycf-stack.outputs}"
}

Expected Behavior

I would expect to the the value defined as the output in my AWS CF template (PrimaryEndPoint.Address) as the output. This output is working correctly, as I can see it in the ElastiCache AWS Console or the CloudFormation Stack's OUTPUT tab.

Actual Behavior

Instead, I got the following value: B780FFEC-B661-4EB8-9236-A01737AD98B6 which doesn't seem to correspond to anything in particular

Important Factoids

When I destroyed the CF stack and created a new one with terraform apply, I got the same string again. I expected that this string would be different on each run.

stack72 commented 8 years ago

Hi @spanktar

Thanks for the report here - sorry this is causing pain right now. I see that you are using Terraform 0.6.12 here - we just released 0.6.16 yesterday - can you try the latest version and see if the issue exists?

A lot of bug fixes have been pushed out over the past few months and we should be sure that the issue still exists on the latest before we can look into this

Thanks

Paul

spanktar commented 8 years ago

Thanks for the reply! The reason I'm using v0.6.12 (and 14) is that there's a problem with queues that's preventing me from going past 0.6.15.
I just disabled the queues and tested with 0.6.15 and 0.6.16, same result:

elasticache_primary_address = B780FFEC-B661-4EB8-9236-A01737AD98B6

stack72 commented 8 years ago

Hi @spanktar

Thanks for the details here - this will help try and diagnose the issue

Paul

boxrick commented 8 years ago

I tried to use cloud_formation_stack to get around the following issue:

https://github.com/hashicorp/terraform/issues/4946

But this bug prevents me doing this, effectively making either option not possible. Any fix or addition for either would be greatly appreciated!

spanktar commented 8 years ago

Maybe related? #4761

spanktar commented 8 years ago

To work around this issue in the meantime, I've created a t2.micro "service instance" that depends on the CF stack that simply queries the AWS API, gets the value and pushes it to Consul. It's a hack, but it accomplishes the goal.

callmeradical commented 8 years ago

I am also running into this issue. I need to create lambda function that is referencing an ECS Task arn that is created in terraform. I created a cloudformation resource to allow me to create a more dynamic lambda function, but when retrieving outputs I am met with

cf_outputs = B780FFEC-B661-4EB8-9236-A01737AD98B6

I am also on 0.6.16 of Terraform

callmeradical commented 8 years ago

@stack72 I just saw this posted here #2708

I am supposing there is an error in parsing cloudformation Outputs, I don't know if this was caused by a change in the aws-sdk-go, or if the delimitting string is somehow being interfered with.

EDIT: Minimal Reproduction

provider "aws" {
  region = "us-east-1"
}

resource "aws_cloudformation_stack" "testing" {
  name = "terraform-test"

  template_body = <<STACK
{
  "AWSTemplateFormatVersion":"2010-09-09",
  "Resources" : {
    "eip":{
          "Type" : "AWS::EC2::EIP",
      "Properties" : {
        "Domain" :  "vpc"
      }
        }
  },
  "Outputs" : {
    "test" : {
        "Description" : "Testing outputs",
        "Value": { "Fn::GetAtt" : ["eip", "AllocationId"] }
    }
  }
}
STACK
}

output "cf_outputs" {
  value = "${aws_cloudformation_stack.testing.outputs}"
}

Interestingly enough, you can delete the outputs of the CFT, destroy, recreate, and still get the same "output"

spanktar commented 8 years ago

See: https://github.com/hashicorp/terraform/issues/7914

try: value = "${aws_cloudformation_stack.testing.outputs["AllocationId"]}"

and watch the nested quotes, they're required. Works in v0.7.4

ghost commented 4 years ago

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.