Hi all,
I’m trying out tutorial Store remote state | Terraform | HashiCorp Developer
I migrated to HCP Terraform, copy the latest state snapshot to the configured
HCP Terraform workspace (overwriting).
However, when I running plan in HCP Terraform.
I received error: Error: No Terraform configuration files found in working directory
Didn’t I just run everything from my main.tf?
Am I missing an important step?
Below is my console log:
PS C:\Users\abyzz\OneDrive\Documents\Terraform\Terra4\learn-terraform-aws-instance>
terraform initInitializing the backend…
Initializing provider plugins…
- Reusing previous version of hashicorp/aws from the dependency lock file
- Using previously-installed hashicorp/aws v4.67.0
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running “terraform plan” to see
any changes that are required for your infrastructure. All Terraform commands
should now work.If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.PS C:\Users\abyzz\OneDrive\Documents\Terraform\Terra4\learn-terraform-aws-instance>
terraform showaws_instance.app_server:
resource “aws_instance” “app_server” {
ami = “ami-08d70e59c07c61a3a”
arn = “arn:aws:ec2:us-west-2:767397964569:instance/i-09f4741c382b660d5”
associate_public_ip_address = true
availability_zone = “us-west-2b”
cpu_core_count = 1
cpu_threads_per_core = 1
disable_api_stop = false
disable_api_termination = false
ebs_optimized = false
get_password_data = false
hibernation = false
host_id = null
iam_instance_profile = null
id = “i-09f4741c382b660d5”
instance_initiated_shutdown_behavior = “stop”
instance_state = “running”
instance_type = “t2.micro”
ipv6_address_count = 0
ipv6_addresses =
key_name = null
monitoring = false
outpost_arn = null
password_data = null
placement_group = null
placement_partition_number = 0
primary_network_interface_id = “eni-056e537e69833235b”
private_dns = “ip-172-31-16-227.us-west-2.compute.internal”
private_ip = “172.31.16.227”
public_dns = “ec2-34-212-34-11.us-west-2.compute.amazonaws.com”
public_ip = “34.212.34.11”
secondary_private_ips =
security_groups = [
“default”,
]
source_dest_check = true
subnet_id = “subnet-0623373a4ec85cb3d”
tags_all = {}
tenancy = “default”
user_data_replace_on_change = false
vpc_security_group_ids = [
“sg-037309673569d762c”,
]capacity_reservation_specification { capacity_reservation_preference = "open" } cpu_options { amd_sev_snp = null core_count = 1 threads_per_core = 1 } credit_specification { cpu_credits = "standard" } enclave_options { enabled = false } maintenance_options { auto_recovery = "default" } metadata_options { http_endpoint = "enabled" http_put_response_hop_limit = 1 http_tokens = "optional" instance_metadata_tags = "disabled" } private_dns_name_options { enable_resource_name_dns_a_record = false enable_resource_name_dns_aaaa_record = false hostname_type = "ip-name" } root_block_device { delete_on_termination = true device_name = "/dev/sda1" encrypted = false iops = 100 kms_key_id = null tags = {} throughput = 0 volume_id = "vol-0bdaada9ea01bd9ae" volume_size = 8 volume_type = "gp2" }
}
PS C:\Users\abyzz\OneDrive\Documents\Terraform\Terra4\learn-terraform-aws-instance>
terraform state list
aws_instance.app_serverPS C:\Users\abyzz\OneDrive\Documents\Terraform\Terra4\learn-terraform-aws-instance>
terraform plan
aws_instance.app_server: Refreshing state… [id=i-09f4741c382b660d5]No changes. Your infrastructure matches the configuration.
Terraform has compared your real infrastructure against your configuration and found no differences, so no changes
are needed.PS C:\Users\abyzz\OneDrive\Documents\Terraform\Terra4\learn-terraform-aws-instance>
terraform initInitializing HCP Terraform…
Do you wish to proceed?
As part of migrating to HCP Terraform, Terraform can optionally copy
your current workspace state to the configured HCP Terraform workspace.Answer “yes” to copy the latest state snapshot to the configured
HCP Terraform workspace.Answer “no” to ignore the existing state and just activate the configured
HCP Terraform workspace with its existing state, if any.Should Terraform migrate your existing state?
Enter a value: yes
Do you want to copy existing state to HCP Terraform?
Pre-existing state was found while migrating the previous “local” backend to
HCP Terraform. An existing non-empty state already exists in HCP Terraform.
The two states have been saved to temporary files that will be removed after
responding to this query.Previous (type “local”): C:\Users\abyzz\AppData\Local\Temp\terraform3301586185\1-local.tfstate
New (HCP Terraform): C:\Users\abyzz\AppData\Local\Temp\terraform3301586185\2-cloud.tfstateDo you want to overwrite the state in HCP Terraform with the previous state?
Enter “yes” to copy and “no” to start with the existing state in %!.(MISSING)Enter a value: yes
Initializing provider plugins…
- Reusing previous version of hashicorp/aws from the dependency lock file
- Using previously-installed hashicorp/aws v4.67.0
HCP Terraform has been successfully initialized!
You may now begin working with HCP Terraform. Try running “terraform plan” to
see any changes that are required for your infrastructure.If you ever set or change modules or Terraform Settings, run “terraform init”
again to reinitialize your working directory.PS C:\Users\abyzz\OneDrive\Documents\Terraform\Terra4\learn-terraform-aws-instance>
terraform initInitializing HCP Terraform…
Initializing provider plugins…
- Reusing previous version of hashicorp/aws from the dependency lock file
- Using previously-installed hashicorp/aws v4.67.0
HCP Terraform has been successfully initialized!
You may now begin working with HCP Terraform. Try running “terraform plan” to
see any changes that are required for your infrastructure.If you ever set or change modules or Terraform Settings, run “terraform init”
again to reinitialize your working directory.PS C:\Users\abyzz\OneDrive\Documents\Terraform\Terra4\learn-terraform-aws-instance>
terraform planRunning plan in HCP Terraform. Output will stream here. Pressing Ctrl-C
will stop streaming the logs, but will not stop the plan running remotely.Preparing the remote plan…
To view this run in a browser, visit:
Waiting for the plan to start…
Terraform v1.8.5
on linux_amd64Error: No Terraform configuration files found in working directory
Terraform requires configuration files to plan changes. Planning without a
configuration would mark everything for destruction, which is normally not what
is desired. If you would like to destroy everything, queue a destroy plan
instead. Otherwise, create a Terraform configuration file (.tf file), or check
that the working directory is set correctly on the workspace, and try again.
Operation failed: failed checking for terraform files: terraform config contains no *.tf or *.tf.json files───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Note: You didn’t use the -out option to save this plan, so Terraform can’t guarantee to take exactly these actions
if you run “terraform apply” now.PS C:\Users\abyzz\OneDrive\Documents\Terraform\Terra4\learn-terraform-aws-instance>
terraform destroy
Running apply in HCP Terraform. Output will stream here. Pressing Ctrl-C
will cancel the remote apply if it’s still pending. If the apply started it
will stop streaming the logs, but will not stop the apply running remotely.Preparing the remote apply…
To view this run in a browser, visit:
Waiting for the plan to start…
Terraform v1.8.5
on linux_amd64Error: No Terraform configuration files found in working directory
Terraform requires configuration files to plan changes. Planning without a
configuration would mark everything for destruction, which is normally not what
is desired. If you would like to destroy everything, queue a destroy plan
instead. Otherwise, create a Terraform configuration file (.tf file), or check
that the working directory is set correctly on the workspace, and try again.
Operation failed: failed checking for terraform files: terraform config contains no *.tf or *.tf.json filesPS C:\Users\abyzz\OneDrive\Documents\Terraform\Terra4\learn-terraform-aws-instance>