rover icon indicating copy to clipboard operation
rover copied to clipboard

Add "terraform show" to rover command

Open naeemdhby opened this issue 2 years ago • 3 comments

naeemdhby avatar Mar 31 '22 10:03 naeemdhby

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

arnaudlh avatar Jul 27 '22 03:07 arnaudlh

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.

naeemdhby avatar Aug 03 '22 02:08 naeemdhby

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.

florianow avatar Sep 05 '22 13:09 florianow

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

LaurentLesle avatar Jun 01 '23 09:06 LaurentLesle