<!---
Please note the following potential times when an issue might be in Terra…form core:
* [Configuration Language](https://www.terraform.io/docs/configuration/index.html) or resource ordering issues
* [State](https://www.terraform.io/docs/state/index.html) and [State Backend](https://www.terraform.io/docs/backends/index.html) issues
* [Provisioner](https://www.terraform.io/docs/provisioners/index.html) issues
* [Registry](https://registry.terraform.io/) issues
* Spans resources across multiple providers
If you are running into one of these scenarios, we recommend opening an issue in the [Terraform core repository](https://github.com/hashicorp/terraform/) instead.
--->
### Community Note
* Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request
* Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
* If you are interested in working on this issue or have submitted a pull request, please leave a comment
<!--
Hi there,
Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.
If your issue relates to Terraform Cloud/Enterprise, please contact tf-cloud@hashicorp.support.
If your issue relates to a specific Terraform provider, please open it in the provider's own repository. The index of providers is at https://registry.terraform.io/browse/providers.
To fix problems, we need clear reproduction cases - we need to be able to see it happen locally. A reproduction case is ideally something a Terraform Core engineer can git-clone or copy-paste and run immediately, without inventing any details or context.
* A short example can be directly copy-pasteable; longer examples should be in separate git repositories, especially if multiple files are needed
* Please include all needed context. For example, if you figured out that an expression can cause a crash, put the expression in a variable definition or a resource
* Set defaults on (or omit) any variables. The person reproducing it should not need to invent variable settings
* If multiple steps are required, such as running terraform twice, consider scripting it in a simple shell script. Providing a script can be easier than explaining what changes to make to the config between runs.
* Omit any unneeded complexity: remove variables, conditional statements, functions, modules, providers, and resources that are not needed to trigger the bug
* When possible, use the [null resource](https://www.terraform.io/docs/providers/null/resource.html) provider rather than a real provider in order to minimize external dependencies. We know this isn't always feasible. The Terraform Core team doesn't have deep domain knowledge in every provider, or access to every cloud platform for reproduction cases.
-->
### Terraform Version
<!---
Run `terraform version` to show the version, and paste the result between the ``` marks below.
If you are not running the latest version of Terraform, please try upgrading because your issue may have already been fixed.
-->
```
Terraform v1.1.2
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v3.70.0
+ provider registry.terraform.io/hashicorp/template v2.2.0
```
### Terraform Configuration Files
<!--
Paste the relevant parts of your Terraform configuration between the ``` marks below.
For Terraform configs larger than a few resources, or that involve multiple files, please make a GitHub repository that we can clone, rather than copy-pasting multiple files in here. For security, you can also encrypt the files using our GPG public key at https://www.hashicorp.com/security.
-->
```terraform
resource "aws_route" "kubernetes_destinations" {
for_each = local.route_tables
route_table_id = each.key
destination_cidr_block = "10.103.0.0/16"
transit_gateway_id = data.aws_ec2_transit_gateway.tgw.id
}
```
### Expected Behavior
It should not report changes made with terraform as changes from the outside.
### Actual Behavior
It reports changes made with terraform as they were made outside of it.
### Steps to Reproduce
1. I added the following resource to my terraform config:
```terraform
resource "aws_route" "kubernetes_destinations" {
for_each = local.route_tables
route_table_id = each.key
destination_cidr_block = "10.103.0.0/16"
transit_gateway_id = data.aws_ec2_transit_gateway.tgw.id
}
```
2. I ran terraform apply. It already complained about my previous apply like it was made outside of terraform.
```terraform
Note: Objects have changed outside of Terraform
Terraform detected the following changes made outside of Terraform since the
last "terraform apply":
# module.vpc.aws_route_table.private[0] has changed
~ resource "aws_route_table" "private" {
id = "rtb-0b1REDACTED"
~ route = [
+ {
+ carrier_gateway_id = ""
+ cidr_block = "10.15.0.0/16"
+ destination_prefix_list_id = ""
+ egress_only_gateway_id = ""
[...]
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:
# aws_route.kubernetes_destinations["rtb-0b14REDACTED"] will be created
+ resource "aws_route" "kubernetes_destinations" {
+ destination_cidr_block = "10.103.0.0/16"
+ id = (known after apply)
+ instance_id = (known after apply)
+ instance_owner_id = (known after apply)
+ network_interface_id = (known after apply)
+ origin = (known after apply)
+ route_table_id = "rtb-0b1REDACTED"
+ state = (known after apply)
+ transit_gateway_id = "tgw-0e8dREDACTED"
}
[...]
Plan: 3 to add, 0 to change, 0 to destroy.
aws_route.kubernetes_destinations["rtb-08eREDACTED"]: Creating...
[...]
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
```
3. I ran terraform plan and I saw my recently apply changes reported as non terraform changes:
```terraform
Note: Objects have changed outside of Terraform
Terraform detected the following changes made outside of Terraform since the last "terraform apply":
# module.vpc.aws_route_table.private[0] has changed
~ resource "aws_route_table" "private" {
id = "rtb-0b1REDACTED"
~ route = [
+ {
+ carrier_gateway_id = ""
+ cidr_block = "10.103.0.0/16"
+ destination_prefix_list_id = ""
+ egress_only_gateway_id = ""
+ gateway_id = ""
+ instance_id = ""
+ ipv6_cidr_block = ""
+ local_gateway_id = ""
+ nat_gateway_id = ""
+ network_interface_id = ""
+ transit_gateway_id = "tgw-0e8REDACTED"
+ vpc_endpoint_id = ""
+ vpc_peering_connection_id = ""
},
# (2 unchanged elements hidden)
]
tags = {
"Name" = "staging-private-a"
}
# (5 unchanged attributes hidden)
}
# module.vpc.aws_route_table.private[1] has changed
#...
```
4. Checked the remote state file, the changes are there though...
```
{
"index_key": "rtb-0b1REDACTED",
"schema_version": 0,
"attributes": {
"carrier_gateway_id": "",
"destination_cidr_block": "10.103.0.0/16",
"destination_ipv6_cidr_block": "",
"destination_prefix_list_id": "",
"egress_only_gateway_id": "",
"gateway_id": "",
"id": "r-rtb-0b14REDACTED",
"instance_id": "",
"instance_owner_id": "",
"local_gateway_id": "",
"nat_gateway_id": "",
"network_interface_id": "",
"origin": "CreateRoute",
"route_table_id": "rtb-0b14REDACTED",
"state": "active",
"timeouts": null,
"transit_gateway_id": "tgw-0e8REDACTED",
"vpc_endpoint_id": "",
"vpc_peering_connection_id": ""
},
"sensitive_attributes": [],
"private": "REDACTED",
"dependencies": [
"data.aws_ec2_transit_gateway.tgw",
"module.vpc.aws_route_table.private"
]
}
```
5. Note that the complaint that was there before the apply is not reported anymore, only the most recent changes, the latest apply is reported. I saw this issue after I created the vpc too.
### Notes
Reported it as a generic terraform problem before: https://github.com/hashicorp/terraform/issues/30239