Skip to content

Show where "(known after apply)" comes from #626

Open
@dylanratcliffe

Description

@dylanratcliffe

In some situations, it is possible to determine where the data in a field that is marked as "(known after apply)" is coming from. A good example is creating an EC2 instance and a security group. We won't know the security group ID until we create it and therefore we won't know the list of security groups for that instance until the security group has been created. However, we do know that the list of security groups for that instance will contain the ID of the security group that we are creating and if we can show that to users it will help them to understand what is actually going on. Also, we might be able to extract relationships from these things which could be useful.

For example if we look at the following code:

locals {
  text = "hello world"
}

resource "terraform_data" "one" {
  input = local.text
}

resource "terraform_data" "two" {
    input = terraform_data.one.output
}

We get the following plan:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the
following symbols:
  + create

Terraform will perform the following actions:

  # terraform_data.one will be created
  + resource "terraform_data" "one" {
      + id     = (known after apply)
      + input  = "hello world"
      + output = (known after apply)
    }

  # terraform_data.two will be created
  + resource "terraform_data" "two" {
      + id     = (known after apply)
      + input  = (known after apply)
      + output = (known after apply)
    }

Plan: 2 to add, 0 to change, 0 to destroy.

The problem here is that terraform_data.two just says that its input will be (known after apply). Where it would be much more useful if we knew that the input was from terraform_data.one.output as we could infer what that meant. It would be good if we could change the text that we added here to be something like (known after apply) From: terraform_data.one.output

Here is the full JSON plan for reference:

{
    "format_version": "1.2",
    "terraform_version": "1.9.8",
    "planned_values": {
        "root_module": {
            "resources": [
                {
                    "address": "terraform_data.one",
                    "mode": "managed",
                    "type": "terraform_data",
                    "name": "one",
                    "provider_name": "terraform.io/builtin/terraform",
                    "schema_version": 0,
                    "values": {
                        "input": "hello world",
                        "triggers_replace": null
                    },
                    "sensitive_values": {}
                },
                {
                    "address": "terraform_data.two",
                    "mode": "managed",
                    "type": "terraform_data",
                    "name": "two",
                    "provider_name": "terraform.io/builtin/terraform",
                    "schema_version": 0,
                    "values": {
                        "triggers_replace": null
                    },
                    "sensitive_values": {}
                }
            ]
        }
    },
    "resource_changes": [
        {
            "address": "terraform_data.one",
            "mode": "managed",
            "type": "terraform_data",
            "name": "one",
            "provider_name": "terraform.io/builtin/terraform",
            "change": {
                "actions": [
                    "create"
                ],
                "before": null,
                "after": {
                    "input": "hello world",
                    "triggers_replace": null
                },
                "after_unknown": {
                    "id": true,
                    "output": true
                },
                "before_sensitive": false,
                "after_sensitive": {}
            }
        },
        {
            "address": "terraform_data.two",
            "mode": "managed",
            "type": "terraform_data",
            "name": "two",
            "provider_name": "terraform.io/builtin/terraform",
            "change": {
                "actions": [
                    "create"
                ],
                "before": null,
                "after": {
                    "triggers_replace": null
                },
                "after_unknown": {
                    "id": true,
                    "input": true,
                    "output": true
                },
                "before_sensitive": false,
                "after_sensitive": {}
            }
        }
    ],
    "configuration": {
        "provider_config": {
            "terraform": {
                "name": "terraform",
                "full_name": "terraform.io/builtin/terraform"
            }
        },
        "root_module": {
            "resources": [
                {
                    "address": "terraform_data.one",
                    "mode": "managed",
                    "type": "terraform_data",
                    "name": "one",
                    "provider_config_key": "terraform",
                    "expressions": {
                        "input": {
                            "references": [
                                "local.text"
                            ]
                        }
                    },
                    "schema_version": 0
                },
                {
                    "address": "terraform_data.two",
                    "mode": "managed",
                    "type": "terraform_data",
                    "name": "two",
                    "provider_config_key": "terraform",
                    "expressions": {
                        "input": {
                            "references": [
                                "terraform_data.one.output",
                                "terraform_data.one"
                            ]
                        }
                    },
                    "schema_version": 0
                }
            ]
        }
    },
    "relevant_attributes": [
        {
            "resource": "terraform_data.one",
            "attribute": [
                "output"
            ]
        }
    ],
    "timestamp": "2024-10-24T14:02:28Z",
    "applyable": true,
    "complete": true,
    "errored": false
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions