Loading...
Loading...
### Terraform Version ```shell Terraform v1.14.0-beta2 ``` ### Terraform Configuration Files ```terraform terraform { required_version = ">=1.14.0" required_providers { aws = { source = "hashicorp/aws" version = "=6.14.1" } } } ``` ### Debug Output [terraform-debug.log](https://github.com/user-attachments/files/22645091/terraform-debug.log) ### Expected Behavior After generating a config output containing unmanaged AWS EC2 instances using the ```terraform query -generate-config-out="generated.tf"``` command, one should be able to seamlessly use the ```terraform apply``` command to import those resources into state (as referenced in the [documentation](https://developer.hashicorp.com/terraform/language/v1.14.x/import/bulk)). ### Actual Behavior The following error messages are received after running a ```terraform apply``` with the resources retrieved from the ```terraform query``` command: ```terraform Error: Conflicting configuration arguments │ │ with aws_instance.unmanaged_0, │ on generated.tf line 5, in resource "aws_instance" "unmanaged_0": │ 5: resource "aws_instance" "unmanaged_0" { │ │ "primary_network_interface": conflicts with associate_public_ip_address ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_0, │ on generated.tf line 8, in resource "aws_instance" "unmanaged_0": │ 8: arn = "arn:aws:ec2:us-east-1:008971679752:instance/i-045ff1be5987fe244" │ │ Can't configure a value for "arn": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Invalid or unknown key │ │ with aws_instance.unmanaged_0, │ on generated.tf line 19, in resource "aws_instance" "unmanaged_0": │ 19: id = "i-045ff1be5987fe244" │ ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_0, │ on generated.tf line 21, in resource "aws_instance" "unmanaged_0": │ 21: instance_lifecycle = "" │ │ Can't configure a value for "instance_lifecycle": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_0, │ on generated.tf line 22, in resource "aws_instance" "unmanaged_0": │ 22: instance_state = "running" │ │ Can't configure a value for "instance_state": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Conflicting configuration arguments │ │ with aws_instance.unmanaged_0, │ on generated.tf line 24, in resource "aws_instance" "unmanaged_0": │ 24: ipv6_address_count = 0 │ │ "ipv6_address_count": conflicts with ipv6_addresses ╵ ╷ │ Error: Conflicting configuration arguments │ │ with aws_instance.unmanaged_0, │ on generated.tf line 25, in resource "aws_instance" "unmanaged_0": │ 25: ipv6_addresses = [] │ │ "ipv6_addresses": conflicts with ipv6_address_count ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_0, │ on generated.tf line 28, in resource "aws_instance" "unmanaged_0": │ 28: outpost_arn = "" │ │ Can't configure a value for "outpost_arn": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_0, │ on generated.tf line 29, in resource "aws_instance" "unmanaged_0": │ 29: password_data = "" │ │ Can't configure a value for "password_data": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Conflicting configuration arguments │ │ with aws_instance.unmanaged_0, │ on generated.tf line 30, in resource "aws_instance" "unmanaged_0": │ 30: placement_group = "" │ │ "placement_group": conflicts with placement_group_id ╵ ╷ │ Error: Conflicting configuration arguments │ │ with aws_instance.unmanaged_0, │ on generated.tf line 31, in resource "aws_instance" "unmanaged_0": │ 31: placement_group_id = "" │ │ "placement_group_id": conflicts with placement_group ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_0, │ on generated.tf line 33, in resource "aws_instance" "unmanaged_0": │ 33: primary_network_interface_id = "eni-010b5e8457d1f4a7d" │ │ Can't configure a value for "primary_network_interface_id": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_0, │ on generated.tf line 34, in resource "aws_instance" "unmanaged_0": │ 34: private_dns = "ip-172-31-24-116.ec2.internal" │ │ Can't configure a value for "private_dns": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_0, │ on generated.tf line 36, in resource "aws_instance" "unmanaged_0": │ 36: public_dns = "ec2-98-81-220-39.compute-1.amazonaws.com" │ │ Can't configure a value for "public_dns": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_0, │ on generated.tf line 37, in resource "aws_instance" "unmanaged_0": │ 37: public_ip = "98.81.220.39" │ │ Can't configure a value for "public_ip": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_0, │ on generated.tf line 42, in resource "aws_instance" "unmanaged_0": │ 42: spot_instance_request_id = "" │ │ Can't configure a value for "spot_instance_request_id": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: expected amd_sev_snp to be one of ["enabled" "disabled"], got │ │ with aws_instance.unmanaged_0, │ on generated.tf line 61, in resource "aws_instance" "unmanaged_0": │ 61: amd_sev_snp = "" │ ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_0, │ on generated.tf line 92, in resource "aws_instance" "unmanaged_0": │ 92: device_name = "/dev/xvda" │ │ Can't configure a value for "root_block_device.0.device_name": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_0, │ on generated.tf line 99, in resource "aws_instance" "unmanaged_0": │ 99: volume_id = "vol-020ccf4da80153897" │ │ Can't configure a value for "root_block_device.0.volume_id": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Conflicting configuration arguments │ │ with aws_instance.unmanaged_1, │ on generated.tf line 121, in resource "aws_instance" "unmanaged_1": │ 121: resource "aws_instance" "unmanaged_1" { │ │ "primary_network_interface": conflicts with associate_public_ip_address ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_1, │ on generated.tf line 124, in resource "aws_instance" "unmanaged_1": │ 124: arn = "arn:aws:ec2:us-east-1:008971679752:instance/i-00a7d7f5d63a75c18" │ │ Can't configure a value for "arn": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Invalid or unknown key │ │ with aws_instance.unmanaged_1, │ on generated.tf line 135, in resource "aws_instance" "unmanaged_1": │ 135: id = "i-00a7d7f5d63a75c18" │ ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_1, │ on generated.tf line 137, in resource "aws_instance" "unmanaged_1": │ 137: instance_lifecycle = "" │ │ Can't configure a value for "instance_lifecycle": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_1, │ on generated.tf line 138, in resource "aws_instance" "unmanaged_1": │ 138: instance_state = "running" │ │ Can't configure a value for "instance_state": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Conflicting configuration arguments │ │ with aws_instance.unmanaged_1, │ on generated.tf line 140, in resource "aws_instance" "unmanaged_1": │ 140: ipv6_address_count = 0 │ │ "ipv6_address_count": conflicts with ipv6_addresses ╵ ╷ │ Error: Conflicting configuration arguments │ │ with aws_instance.unmanaged_1, │ on generated.tf line 141, in resource "aws_instance" "unmanaged_1": │ 141: ipv6_addresses = [] │ │ "ipv6_addresses": conflicts with ipv6_address_count ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_1, │ on generated.tf line 144, in resource "aws_instance" "unmanaged_1": │ 144: outpost_arn = "" │ │ Can't configure a value for "outpost_arn": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_1, │ on generated.tf line 145, in resource "aws_instance" "unmanaged_1": │ 145: password_data = "" │ │ Can't configure a value for "password_data": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Conflicting configuration arguments │ │ with aws_instance.unmanaged_1, │ on generated.tf line 146, in resource "aws_instance" "unmanaged_1": │ 146: placement_group = "" │ │ "placement_group": conflicts with placement_group_id ╵ ╷ │ Error: Conflicting configuration arguments │ │ with aws_instance.unmanaged_1, │ on generated.tf line 147, in resource "aws_instance" "unmanaged_1": │ 147: placement_group_id = "" │ │ "placement_group_id": conflicts with placement_group ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_1, │ on generated.tf line 149, in resource "aws_instance" "unmanaged_1": │ 149: primary_network_interface_id = "eni-08a0064b9979e6432" │ │ Can't configure a value for "primary_network_interface_id": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_1, │ on generated.tf line 150, in resource "aws_instance" "unmanaged_1": │ 150: private_dns = "ip-172-31-18-31.ec2.internal" │ │ Can't configure a value for "private_dns": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_1, │ on generated.tf line 152, in resource "aws_instance" "unmanaged_1": │ 152: public_dns = "ec2-34-228-168-227.compute-1.amazonaws.com" │ │ Can't configure a value for "public_dns": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_1, │ on generated.tf line 153, in resource "aws_instance" "unmanaged_1": │ 153: public_ip = "34.228.168.227" │ │ Can't configure a value for "public_ip": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_1, │ on generated.tf line 158, in resource "aws_instance" "unmanaged_1": │ 158: spot_instance_request_id = "" │ │ Can't configure a value for "spot_instance_request_id": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: expected amd_sev_snp to be one of ["enabled" "disabled"], got │ │ with aws_instance.unmanaged_1, │ on generated.tf line 177, in resource "aws_instance" "unmanaged_1": │ 177: amd_sev_snp = "" │ ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_1, │ on generated.tf line 208, in resource "aws_instance" "unmanaged_1": │ 208: device_name = "/dev/xvda" │ │ Can't configure a value for "root_block_device.0.device_name": its value will be decided automatically based on the result of applying this configuration. ╵ ╷ │ Error: Value for unconfigurable attribute │ │ with aws_instance.unmanaged_1, │ on generated.tf line 215, in resource "aws_instance" "unmanaged_1": │ 215: volume_id = "vol-027a49e2bd34cdedf" │ │ Can't configure a value for "root_block_device.0.volume_id": its value will be decided automatically based on the result of applying this configuration. ``` ### Steps to Reproduce 1. Create one or more EC2 instances within AWS that are not managed by Terraform / present within the state file. 2. Create a search.tfquery.hcl to look for unmanaged AWS instances: ``` list "aws_instance" "unmanaged" { provider = aws config { region = "us-east-1" filter { name = "tag:ManagedBy" values = ["unmanaged"] } filter { name = "instance-state-name" values = ["running"] } } } ``` 3. Run the ```terraform query -generate-config-out="./generated.tf``` command in order to generate the required Terraform code to import the unmanged resources. 4. Run a ```terraform apply``` command. ### Additional Context _No response_ ### References _No response_ ### Generative AI / LLM assisted development? _No response_
Click on a version to see all relevant bugs
Terraform Integration
Learn more about where this data comes from
Bug Scrub Advisor
Streamline upgrades with automated vendor bug scrubs
BugZero Enterprise
Wish you caught this bug sooner? Get proactive today.