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

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

Open
dylanratcliffe opened this issue Oct 24, 2024 · 0 comments
Open

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

dylanratcliffe opened this issue Oct 24, 2024 · 0 comments

Comments

@dylanratcliffe
Copy link
Member

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
}
@dylanratcliffe dylanratcliffe self-assigned this Oct 24, 2024
@dylanratcliffe dylanratcliffe removed their assignment Oct 31, 2024
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

No branches or pull requests

1 participant