JetBrains / package-search-gradle-plugins

Gradle plugins for Docker, Terraform and Liquibase.
Apache License 2.0
32 stars 7 forks source link

State file is not being created #14

Closed blundell closed 2 years ago

blundell commented 2 years ago

I ran terraformApply and I got a .lock.hcl file, but I did not get a state file? Should I have?

Also is this an error in the readme: image

Under the state file title it says:

The location of the lock file can be modified in the source set:

and the example says lockFile = .. should it be stateFile =?

blundell commented 2 years ago

Ah I have found a state file in my original root project.

i.e. I am running in a module in a composite project

/my-project/                      <<< 1 state file was found here
   /my-composite-build/           <<< 3 here would also be ok, its the root project I expect 
       /my-terraform-module/    <<< 2 was hoping for it here
lamba92 commented 2 years ago

The lock file is a dependency management mechanism to avoid installing unwanted upgrades during terraform init. On the other hand the plan file has it's own stateFile variable with a default in "src/$name/terraform/terraform.tfstate".

It is normally created by Terraform itself when you execute the plan.

blundell commented 2 years ago

ty

that's what I was trying to say, it's not being created in "src/$name/terraform/terraform.tfstate"

I'll see if I can make a simpler reproduction project (I use composite builds https://docs.gradle.org/current/userguide/composite_builds.html)

blundell commented 2 years ago

I made a simple reproduction project here: https://github.com/blundell/TerraformGradlePluginPlayground

Running

./gradlew :backend:backend-terraform:terraformPlan
export ENABLE_TF_APPLY=true
./gradlew :backend:backend-terraform:terraformApply && export ENABLE_TF_APPLY=false

The tfstate file is not generated.

Main TF File: https://github.com/blundell/TerraformGradlePluginPlayground/blob/master/backend/backend-terraform/src/main/terraform/main.tf Build file: https://github.com/blundell/TerraformGradlePluginPlayground/blob/master/backend/backend-terraform/build.gradle.kts

(I confirmed it should be generated with this setup here https://github.com/gruntwork-io/terratest/issues/1060)

blundell commented 2 years ago

Any thoughts on this? I'm stuck without a state file :-)

I can see the state is generated in build/terraform/main/runtimeExecution/terraform.tfstate

I guess a work around for now is if I copy that file back out the build folder manually after each apply?

blundell commented 2 years ago

💯