aztfmod / rover

The rover is a docker container in charge of the deployment of the Terraform platform engineering for Azure
MIT License
171 stars 142 forks source link

Add "terraform show" to rover command #248

Closed naeemdhby closed 1 year ago

arnaudlh commented 1 year ago

hi @naeemdhby, can you add syntax examples please? I always get

Terraform init return code 0
calling show
@calling show
running terraform show with -plan /home/vscode/.terraform.cache/contoso-sandpit/rover_jobs/20220727025455088189884/tfstates/level1/tfstate/d1s146-ddd1we.tfplan
 -TF_VAR_workspace: tfstate
 -state: /home/vscode/.terraform.cache/contoso-sandpit/rover_jobs/20220727025826081804675/tfstates/level0/tfstate/examples.tfstate
 -plan:  /home/vscode/.terraform.cache/contoso-sandpit/rover_jobs/20220727025826081804675/tfstates/level0/tfstate/examples.tfplan
null
Terraform show return code: 0
@calling clean_up_variables
cleanup variables
clean_up backend_files
naeemdhby commented 1 year ago

Hi @arnaudlh , rover show command will read tfstate file output, so first need to do rover apply, and then do rover show. @onlyillusion I think would be a good idea to rover show also read tfplan file as well, for example, have a condition to read plan file if passed on as argument, otherwise read from tfstate file.

florianow commented 1 year ago

Hey, we need this parameter to create json files out off the tfplan files for infracost. it also a good option to read tfplan file as well.

LaurentLesle commented 1 year ago

I have modified your PR to make it working. Here the steps:

  1. run a normal rover plan or apply (rover displays where the plan or tfstate got created.)
  2. rover -a show [-json] [path to plan or tfstate] -o [path to json output]
  3. cat [path to json output] | jq

With the json file:

rover \
  -lz /tf/caf/landingzones/caf_launchpad \
  -var-folder /tf/caf/configuration/level0/launchpad \
  -tfstate_subscription_id xxx \
  -target_subscription xxx \
  -tfstate caf_launchpad.tfstate \
  -launchpad \
  -level level0 \
  -p ${TF_DATA_DIR}/caf_launchpad.tfstate.tfplan \
  -o ${TF_DATA_DIR}/caf_launchpad.tfstate.tfplan.json \
  -a show -json ${TF_DATA_DIR}/caf_launchpad.tfstate.tfplan
image

Without:

rover \
  -lz /tf/caf/landingzones/caf_launchpad \
  -var-folder /tf/caf/configuration/level0/launchpad \
  -tfstate_subscription_id xxx \
  -target_subscription xxx \
  -tfstate caf_launchpad.tfstate \
  -launchpad \
  -level level0 \
  -p ${TF_DATA_DIR}/caf_launchpad.tfstate.tfplan \
  -a show ${TF_DATA_DIR}/caf_launchpad.tfstate.tfplan
image