cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Terraform provider and (remote) module state

Dave_Huze
Observer

Hi.
I'm hoping that someone can help me out here.  Ideally, I'd like to raise a feature request to be able to have granular tfstate files, one per module, however I don't know if this would be possible.  In the meantime, there is an annoying naming issue with the terraform_json_dashboard, which I'll describe here.

The scenario using the following, and I have used the deprecated dynatrace_dashboard - https://registry.terraform.io/providers/dynatrace-oss/dynatrace/latest/docs/resources/dashboard in this example just to act as a comparison.

 

./terraform-provider-dynatrace -export -import-state -id -ref '*' dynatrace_dashboard dynatrace_json_dashboard

 

 results in a single state file, which is understandable...

What I am currently doing to get more granular state files is programmatically creating a backend.tf for each module, as well as moving the necessary state to each module using:

 

d=target_dir; for i in $d/modules/*;do m="$(basename $i)"; t="module.$m"; tf state mv -state=$d/terraform.tfstate -state-out=$i/$m.tfstate $t $t;done

 

which works fine for every module other than terraform_json_dashboard:

 

Move "module.activegate_updates" to "module.activegate_updates"
Successfully moved 1 object(s).
Move "module.alerting" to "module.alerting"
Successfully moved 1 object(s).
Move "module.api_detection" to "module.api_detection"
Successfully moved 1 object(s).
Move "module.application_detection_rule" to "module.application_detection_rule"
Successfully moved 1 object(s).
<snip>
Move "module.dashboard" to "module.dashboard"
Successfully moved 1 object(s).
<snip>
│ Error: Invalid source address
│ 
│ Cannot move module.json_dashboard: does not match anything in the current state.

 

 

I can work around this exception but would rather not have to.  Does anyone know if there are any plans to natively provide the ability to save the state files per module, also if the mismatch of the dynatrace_json_dashboard module is intentional, or a bug?

Cheers,

Dave.

 

0 REPLIES 0

Featured Posts