boltops-tools / terraspace

Terraspace: The Terraform Framework
https://terraspace.cloud
Apache License 2.0
678 stars 46 forks source link

Terraspace isn't ready to save state in another Azure subscription #352

Open Grigoriy0 opened 4 months ago

Grigoriy0 commented 4 months ago

Checklist

My Environment

I've created new storage account for the backend in another subscription, manually moved terraform state, but now terraspace can't access the storage account in another subscription.

Software Version
Operating System WSL ubuntu 22.04 x64
Terraform 1.4.0
Terraspace 2.2.15
Ruby 3.3.0

Expected Behaviour

Terraspace works with resources in one subscription, specified in ARM_SUBSCRIPTION_ID variable, and successfully stores the terraform state in the storage account of another subscription without errors.

Current Behavior

Terraspace doesn't care about subscription_id in backend config,
TS tries to find resource group in the wrong subscription and of cause can't find. Then TS creates new resource group in the wrong subscription. Then TS tries to create storage account(which already exists in another subscription). Then TS tries to create container in the storage account and fails with 404 Not Found error:

logs Creating Storage Blob Container terraform-state... Exception Armrest::Error: # /usr/local/bundle/gems/armrest-0.1.3/lib/armrest/api/base.rb:43:in `request' /usr/local/bundle/gems/armrest-0.1.3/lib/armrest/api/base.rb:18:in `block (2 levels) in ' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/terraform/runner.rb:51:in `block in terraform' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/hooks/builder.rb:25:in `run_hooks' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/hooks/concern.rb:6:in `run_hooks' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/terraform/runner.rb:50:in `terraform' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/terraform/runner.rb:15:in `block in run' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/terraform/runner.rb:97:in `time_took' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/terraform/runner.rb:14:in `run' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/cli/init.rb:23:in `block in init' /usr/local/lib/ruby/3.3.0/timeout.rb:186:in `block in timeout' /usr/local/lib/ruby/3.3.0/timeout.rb:41:in `handle_timeout' /usr/local/lib/ruby/3.3.0/timeout.rb:195:in `timeout' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/cli/init.rb:22:in `init' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/cli/init.rb:12:in `run' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/cli/commander.rb:10:in `run' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/cli/plan.rb:43:in `plan_only' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/cli/plan.rb:17:in `perform' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/cli/plan.rb:11:in `run' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/cli.rb:165:in `plan' /usr/local/bundle/gems/thor-1.3.0/lib/thor/command.rb:28:in `run' /usr/local/bundle/gems/thor-1.3.0/lib/thor/invocation.rb:127:in `invoke_command' /usr/local/bundle/gems/thor-1.3.0/lib/thor.rb:527:in `dispatch' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/command.rb:76:in `dispatch' /usr/local/bundle/gems/thor-1.3.0/lib/thor/base.rb:584:in `start' /usr/local/bundle/gems/terraspace-2.2.15/lib/terraspace/cli/concern.rb:65:in `start' /usr/local/bundle/gems/terraspace-2.2.15/exe/terraspace:7:in `' /usr/local/bundle/bin/terraspace:25:in `load' /usr/local/bundle/bin/terraspace:25:in `
'

Step-by-step reproduction instructions

terraspace plan

Code Sample

# config/terraform/backend.tf
terraform {
  backend "azurerm" {
    subscription_id = "my-another-subscription-id"
   ...
  }
}

Solution Suggestion

Configure azurerm backend plugin to be able to access storage account in another subscription