rover 'state rm': state file not found
- Dominant language
- Shell
- Stars
- 176
- Forks
- 147
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I'm facing an issue when trying to make a `state rm` in rover command:
```
rover -lz /tf/caf/.solution/caf/caf_solution \
-var-folder /tf/caf/my_var_folder \
-a 'state rm' \
-p ${PLAN_FILE_NAME} \
-level level4 \
-env ${LZ_PREFIX} \
-tfstate ${TFSTATE_FILE} \
-tfstate_subscription_id ${TFSTATE_SUB_ID} \
-parallelism 30 \
-target_subscription ${SUB_NAME} \
-id "module.solution.module.network_something[\"blabal\"].azurecaf_name.networksomething"`
```
And the result is a `state file was found!` error message::
```
@calling verify_azure_session
Checking existing Azure session
@calling process_target_subscription
Set subscription to -target_subscription SXXXXX01
caf_command landingzone
target_subscription_id 8XXXXXe
TF_VAR_tfstate_subscription_id 8XXXXXe
Resources from this landing zone are going to be deployed in the following subscription:
{
"environmentName": "AzureCloud",
"homeTenantId": "axxxxxx",
"id": "xxxxxf",
"isDefault": true,
"managedByTenants": [],
"name": "XXXXXX",
"state": "Enabled",
"tenantId": "xxxxxx",
"user": {
"name": "hey@you.onmicrosoft.com",
"type": "user"
}
}
debug: 6XXXXXXX
Tfstates subscription set to XXXX (XXXXXXXXXXX)
mode : 'landingzone'
terraform command output file : ''
terraform plan output file : 'foobar_tfplan'
directory cache : '/home/vscode/.terraform.cache/foobar_launchpad/rover_jobs/20221124112354655979305'
tf_action : 'state list'
command and parameters : '-var-file=/tf/caf/environements/vxxxxx/landingzone.tfvars -var-file=/tf/caf/environements/xxxx/rgs.tfvars -var-file=/tf/caf/environements/xxxxx/resource.tfvars -parallelism 30'
level (current) : 'level4'
environment : 'foobar_launchpad'
workspace : 'tfstate'
tfstate : 'foobar.tfstate'
tfstate subscription id : 'XXXXX'
target subscription : 'XXXXX'
CI/CD enabled : 'false'
Symphony Yaml file path : ''
Run all tasks : 'true'
TF_IN_AUTOMATION : 'true'
@calling process_actions
@calling verify_parameters
landingzone : '/tf/caf/landingzone'
@calling_deploy
@calling get_storage_id
@calling_get_logged_user_object_id
- AZURE_ENVIRONMENT: AzureCloud
- ARM_ENVIRONMENT: public
Initalizing az cloud variables
- logged in user objectId: xxxxxx (hey@you.onmicrosoft.com)
Initializing state with user: hey@you.onmicrosoft.com
launchpad already installed
@calling deploy_from_remote_state
Connecting to the launchpad
@calling login_as_launchpad
Getting launchpad coordinates from subscription: 8xxxx9e
- keyvault_name: vxxxxx-level4
- tenant_id : axxxxxx8
- storage_account_name (current): xxx4
- storage_account_name (lower): xxx3
- resource_group (current): xxxxlaunchpad-level4
- resource_group (lower): xxxlaunchpad-level3
@calling deploy_landingzone
Deploying '/tf/caf/landingzone'
Terraform version 0.15 or greater
Upgrading modules...
Downloading aztfmod/caf/azurerm 5.4.8 for dynamic_keyvault_secrets...
- dynamic_keyvault_secrets in /home/vscode/.terraform.cache/foobar_launchpad/rover_jobs/20221112345679305/modules/dynamic_keyvault_secrets/modules/security/dynamic_keyvault_secrets
- dynamic_keyvault_secrets.secret in /home/vscode/.terraform.cache/foobar_launchpad/rover_jobs/20221112345679305/modules/dynamic_keyvault_secrets/modules/security/dynamic_keyvault_secrets/secret
Initializing the backend...
Successfully configured the backend "azurerm"! Terraform will automatically
use this backend unless the backend configuration changes.
Initializing provider plugins...
- terraform.io/builtin/terraform is built in to Terraform
- Finding hashicorp/azurerm versions matching "~> 2.81.0"...
- Finding latest version of hashicorp/local...
[...]
- Using hashicorp/tls v2.2.0 from the shared cache directory
- Using aztfmod/azurecaf v1.2.22 from the shared cache directory
Terraform has been successfully initialized!
Terraform init return code 0
calling other
@calling other
running terraform state rm -state=/home/vscode/.terraform.cache/foobar_launchpad/rover_jobs/20221112345679305/tfstates/levelX/tfstate/'foobar.tfstate module.solution.module.network_something[\"blabal\"].azurecaf_name.networksomething"
Terraform state rm return code: 0
Terraform returned errors:
No state file was found!
State management commands require a state file. Run this command
in a directory where Terraform has been run or use the -state flag
to point the command to a specific state location.
Error on or near line 555: Error running terraform state rm; exiting with status 2003
@calling clean_up_variables
cleanup variables
clean_up backend_files
```
But a `state show` is working fine:
```
rover -lz /tf/caf/.solution/caf/caf_solution \
-var-folder /tf/caf/my_var_folder \
-a 'state show' \
-p ${PLAN_FILE_NAME} \
-level level4 \
-env ${LZ_PREFIX} \
-tfstate ${TFSTATE_FILE} \
-tfstate_subscription_id ${TFSTATE_SUB_ID} \
-parallelism 30 \
-target_subscription ${SUB_NAME} \
-id "module.solution.module.network_something[\"blabal\"].azurecaf_name.networksomething"`
```
And the result is:
```
Terraform has been successfully initialized!
Terraform init return code 0
calling other
@calling other
running terraform state list -state=/home/vscode/.terraform.cache/foobar_launchapd/rover_jobs/2022114158234788/tfstates/level4/tfstate/foobar.tfstate module.solution.module.network_something["blabal"].azurecaf_name.networksomething
module.solution.module.network_something[\"blabal\"].azurecaf_name.networksomething"`
Terraform state list return code: 0
@calling clean_up_variables
cleanup variables
clean_up backend_files
real 0m39.992s
user 0m20.880s
sys 0m8.836s
```
My questions are:
- Is the `state rm` a rover's bug?
- Why `state list` or `state show` are working?
- When is downloaded the tfsate for `state show/list`?
My environment
- aztfmod/rover:1.0.7-2109.2410
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.