Observation when using terraform all/init with dependent stacks for the first time

Hi BoltOps Community,

I have an observation that I wanted to share with you…

Imagine I have 2 stacks

  • vpc
  • subnet

where the subnet stack relies on the output from the vpc stack (referenced using the output helper).

After doing a cleanup of the cache folder (e.g. terraspace clean cache -y ), I get the following if I run e.g. terraspace all init

$ terraspace all init
Building one stack to build all stacks
Building .terraspace-cache/ap-southeast-2/dev/stacks/vpc
Downloading tfstate files for dependencies defined in tfvars...
│ Error: Backend initialization required, please run "terraform init"
│ Reason: Initial configuration of the requested backend "s3"
│ The "backend" is the interface that Terraform uses to store state,
│ perform operations, etc. If this message is showing up, it means that the
│ Terraform configuration you're using is using a custom configuration for
│ the Terraform backend.
│ Changes to backend configurations require reinitialization. This allows
│ Terraform to set up the new configuration, copy existing state, etc. Please run
│ "terraform init" with either the "-reconfigure" or "-migrate-state" flags to
│ use the current configuration.
│ If the change reason above is incorrect, please verify your configuration
│ hasn't changed and try again. At this point, no changes to your existing
│ configuration or state have been made.

Error running: cd /home/ubuntu/environment/mytest/.terraspace-cache/ap-southeast-2/dev/stacks/vpc && terraform state pull > /tmp/terraspace/remote_state/stacks/vpc/state.json
Please fix the error before continuing
Built in .terraspace-cache/ap-southeast-2/dev/stacks/vpc
    terraspace init vpc    # batch 1
    terraspace init subnet # batch 2
Batch Run 1:
Running: terraspace init vpc Logs: log/init/vpc.log
terraspace init vpc:  Terraform has been successfully initialized!
Batch Run 2:
Running: terraspace init subnet Logs: log/init/subnet.log
terraspace init subnet:  Terraform has been successfully initialized!
Time took: 16s

If you notice, it actually does the initialization eventually (i.e. as per the last 7 lines of the output above). It is just that the warning messages in the beginning was rather unexpected (as you’re getting a warning about not doing an init - while you are actually trying to do an init :slight_smile: ). I am guessing the warning message would be due to it trying to pull down the remote state file to work out the dependency (terraform state pull), perhaps before the initialization?

A similar behaviour can also be observed when the cache folder isn’t present and I try to do terraspace all graph --format text.

This behaviour is not observed when there is no cache folder, the stacks are independent of each other (i.e. no dependencies) and doing

  • terraspace all init, or
  • terraspace all graph --format text

This is not a show stopper and doesn’t prevent you from getting the end result from doing terraspace all init or terraspace all graph (when there is dependent stacks, and no cache folder) - just an observation that you need to watch out for :smiley:

Many thanks,

Thanks for the report and detailed steps to reproducing this. :+1: Thinking can remove those annoying warnings with improvements to the auto-init detection. Will consider PRs. No sweat either way of course. Hope to get to this in time.

1 Like

Thanks Tung,

Yup, it’s not urgent or a show-stopper, but thought it might be useful to share around with the community in case someone encountered something similar :slight_smile:


1 Like