Closed nvqna closed 4 years ago
Did you already run Terraform prior to having this error? It looks like you ran Terraform, removed the resources in Azure manually, and then re-ran Terraform. If that's the case, the Terraform state makes it think resources should still exist while they aren't, and you can simply nuke your terraform.tfstate
file and try again.
I thought that might have been the issue, but I received that error the first time I ran terraform apply
, and I have no resources listed in Azure. I'm using a brand new free Azure trial account.
$ az resource list
[]
I also don't have a terraform.tfstate
file.
$ ls -a
. .. .terraform data.tf domain_controller.tf elasticsearch_kibana.tf locals.tf main.tf network.tf outputs.tf provider.tf public_ips.tf vars.tf workstations.tf
What's your terraform version? (terraform --version
)
$ terraform --version
Terraform v0.13.0
+ provider registry.terraform.io/hashicorp/azurerm v2.12.0
+ provider registry.terraform.io/hashicorp/http v1.2.0
+ provider registry.terraform.io/hashicorp/null v2.1.2
+ provider registry.terraform.io/hashicorp/random v2.3.0
I had Terraform 0.12.3 installed, which does not cause the error. But with Terraform 0.13, I can reproduce the error, there is probably something breaking. I will fix this ASAP, in the meantime you can still use v0.12.3 to spin up the lab:
rm -r .terraform
wget https://releases.hashicorp.com/terraform/0.12.3/terraform_0.12.3_linux_amd64.zip
unzip terraform_0.12.3_linux_amd64.zip
rm terraform_0.12.3_linux_amd64.zip
./terraform init && ./terraform apply
Thanks a lot for reporting!
Nice one, thanks!
It seems that adding an explicit dependency on the data blocks fixes the issue, at least terraform apply doesn't crash before starting to create resources. Could you try to apply the patch and confirm it works?
diff --git a/terraform/data.tf b/terraform/data.tf
index 897b94e..1b38be3 100644
--- a/terraform/data.tf
+++ b/terraform/data.tf
@@ -1,6 +1,7 @@
data "azurerm_public_ip" "main" {
name = azurerm_public_ip.main.name
resource_group_name = var.resource_group
+ depends_on = [azurerm_public_ip.main]
}
data "azurerm_public_ip" "workstation" {
@@ -8,11 +9,13 @@ data "azurerm_public_ip" "workstation" {
name = azurerm_public_ip.workstation[count.index].name
resource_group_name = var.resource_group
+ depends_on = [azurerm_public_ip.workstation]
}
data "azurerm_public_ip" "elasticsearch" {
name = azurerm_public_ip.elasticsearch.name
resource_group_name = var.resource_group
+ depends_on = [azurerm_public_ip.elasticsearch]
}
data "http" "public_ip" {
(Store the diff in a file, then run git apply patch.diff
)
I applied the patch and ran terraform apply with Terraform version 0.13.0 and it worked!
Great, thanks for confirming!
What is not working? When running terraform plan or terraform apply, I receive the following errors:
` $ terraform plan Refreshing Terraform state in-memory prior to plan... The refreshed state will be used to calculate this plan, but will not be persisted to local or remote state storage.
data.http.public_ip: Refreshing state...
Error: Error: Public IP "ad-lab-ingress" (Resource Group "ad-hunting-lab") was not found
on data.tf line 1, in data "azurerm_public_ip" "main": 1: data "azurerm_public_ip" "main" {
Error: Error: Public IP "ad-lab-wks-0-ingress" (Resource Group "ad-hunting-lab") was not found
on data.tf line 6, in data "azurerm_public_ip" "workstation": 6: data "azurerm_public_ip" "workstation" {
Error: Error: Public IP "ad-lab-wks-1-ingress" (Resource Group "ad-hunting-lab") was not found
on data.tf line 6, in data "azurerm_public_ip" "workstation": 6: data "azurerm_public_ip" "workstation" {
Error: Error: Public IP "elasticsearch-ingress" (Resource Group "ad-hunting-lab") was not found
on data.tf line 13, in data "azurerm_public_ip" "elasticsearch": 13: data "azurerm_public_ip" "elasticsearch" { `
What OS are you using? I have confirmed this on WSLv2 running Ubuntu 20.04 and an Ubuntu 19.10 VPS.
Your
domain.yml
file? Have not changed from what's in the repo.Full Terraform / Ansible output? As above.