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

aws_cloudformation_stack resources no longer have an ARN in plan.json #423

Closed
rulatir opened this issue Feb 29, 2020 · 5 comments · Fixed by #433
Closed

aws_cloudformation_stack resources no longer have an ARN in plan.json #423

rulatir opened this issue Feb 29, 2020 · 5 comments · Fixed by #433

Comments

@rulatir
Copy link

rulatir commented Feb 29, 2020

I just rebuilt terraformer from master, and now when I do terraformer plan, the aws_cloudformation_stack resources in plan.json no longer contain the whole ARN. I can synthesize the ARN from the ID just fine since account ID is the only extra info needed, but the problem is that the bare ID seems to be just an arbitrary string with no characteristics indicating that it is an ID of a cloudformation stack, and I must basically downgrade to accept arbitrary strings as resource IDs.

The good thing about ARNs is that they are easily identifiable as resource references. I believe they should be used wherever possible. It would facilitate writing schema-less resource graph crawlers: if an object property looks like ARN, it is a graph edge.

@rulatir
Copy link
Author

rulatir commented Feb 29, 2020

Hmm, this is weird. Manual terraform import currently omits the ARN too. But I swear it must have worked previously, or my own script would have tripped just like it trips now, and I have imported cloudformation stacks successfully (with plan.json massage described in issue #420).

@rulatir
Copy link
Author

rulatir commented Feb 29, 2020

And it seems that the relevant code in terraform AWS provider hasn't changed in years. So this is really strange unless schema.ResourceData::SetId() changed its behavior between v2.48 and v2.50... probably an upstream issue though.

@patrykorwat
Copy link
Contributor

In #415 i changed the way how CF stacks are being imported. Now they are imported by its name, which is the correct way according to TF. Will take a look into the plan.json, perhaps there’s something more to adjust.

@rulatir
Copy link
Author

rulatir commented Feb 29, 2020

"Because UUIDs are so 1980s and so Microsoft" - Amazon/Hashicorp Joint Standards Committee

Seriously though, what's their rationale? Got a link to where they say it? I just terraform imported an ASG that was created with one of our CF stacks, and surely enough it is tagged with an ARN reference to the "mother" CF stack. How can TF say you shouldn't use the ARN as a CF stack's ID when the modeled reality does use ARNs as CF stack references?

(EDIT: it is also tagged with a name reference so perhaps the ARN reference is legacy stuff?)

@patrykorwat
Copy link
Contributor

@rulatir Terraform is all driven by the AWS API. You can read more about it in https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_DescribeStacks.html
and take a look at the parameter StackName. The name suggests that the accepted value is always a name but by taking closer look we can see the value is:

The name or the unique stack ID [...]:

  • Running stacks: You can specify either the stack's name or its unique stack ID.
  • Deleted stacks: You must specify the unique stack ID.
    AWS CloudFormation fixes #415 did improved the import process, so that it only used stack name but it did also started filtering out deleted stacks, so now Terraformer will import only running stacks (as Terraform itself supports management of running stacks only as well).

Because of that and fact that currently the tfstate file is inheritibly incorrect:

{
   ...
            "resources": {
                "aws_cloudformation_stack.tfer--abcI": {
                    "type": "aws_cloudformation_stack",
                    "depends_on": [],
                    "primary": {
                        "id": "<NAME>",
                        "attributes": {
                            ...
                            "id": "<NAME>",
                            "name": "<NAME>"
                        }
}

Because of those facts, it is better to refer to the CF template by its identifier.

In a more broad sense, Terraform as well as AWS doesn't strongly define what is an identifier of a resource. It's up to a service (I assume internal development team) to define those specifics. I agree it's not making the development of tools that manage the resources easy because each resources must be uniquely checked for details of the practices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants