boltops-tools / terraspace

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

Azure plugins error Net::HTTPConflict #220

Closed psyreactor closed 2 years ago

psyreactor commented 2 years ago

Checklist

My Environment

Software Version
Operating System Archlinux
Terraform v1.1.6
Terraspace 1.1.7
Ruby 3.0.3p157

Expected Behaviour

Current Behavior

I create the application account in azure, validate the configuration with azure_check.rb without errors. But when I run terraspace plan kuberntes getting the error # (Armrest::Error). Sorry for my English, I speak Spanish

Step-by-step reproduction instructions

export ARM_SUBSCRIPTION_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export ARM_CLIENT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export ARM_TENANT_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export ARM_CLIENT_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

git clone https://github.com/boltops-tools/azure_check
cd azure_check
bundle
bundle exec ruby azure_check.rb
Successfully connected to Azure with your ARM_CLIENT_ID and ARM_CLIENT_SECRET
TS_ENV=production bundle exec terraspace all plan
Running:
    terraspace plan kubernetes # batch 1
Batch Run 1:
Running: terraspace plan kubernetes Logs: log/plan/kubernetes.log
/home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/armrest-0.1.2/lib/armrest/api/base.rb:44:in `request': #<Net::HTTPConflict:0x000055db7ed75230> (Armrest::Error)
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/armrest-0.1.2/lib/armrest/api/base.rb:19:in `block (2 levels) in <class:Base>'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/armrest-0.1.2/lib/armrest/services/storage_account.rb:32:in `create'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace_plugin_azurerm-0.5.0/lib/terraspace_plugin_azurerm/interfaces/backend/storage_account.rb:38:in `save_storage_account'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace_plugin_azurerm-0.5.0/lib/terraspace_plugin_azurerm/interfaces/backend/storage_account.rb:11:in `create'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace_plugin_azurerm-0.5.0/lib/terraspace_plugin_azurerm/interfaces/backend.rb:10:in `call'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/terraform/runner/backend.rb:25:in `create'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/terraform/runner.rb:49:in `block in terraform'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/hooks/builder.rb:25:in `run_hooks'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/hooks/concern.rb:6:in `run_hooks'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/terraform/runner.rb:48:in `terraform'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/terraform/runner.rb:15:in `block in run'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/terraform/runner.rb:89:in `time_took'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/terraform/runner.rb:14:in `run'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/cli/init.rb:23:in `block in init'
    from /opt/terraspace/embedded/lib/ruby/3.0.0/timeout.rb:97:in `block in timeout'
    from /opt/terraspace/embedded/lib/ruby/3.0.0/timeout.rb:35:in `block in catch'
    from /opt/terraspace/embedded/lib/ruby/3.0.0/timeout.rb:35:in `catch'
    from /opt/terraspace/embedded/lib/ruby/3.0.0/timeout.rb:35:in `catch'
    from /opt/terraspace/embedded/lib/ruby/3.0.0/timeout.rb:112:in `timeout'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/cli/init.rb:22:in `init'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/cli/init.rb:12:in `run'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/cli/commander.rb:10:in `run'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:132:in `run_terraspace'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:62:in `deploy_stack'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:46:in `block (3 levels) in deploy_batch'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:45:in `fork'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:45:in `block (2 levels) in deploy_batch'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:43:in `each'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:43:in `block in deploy_batch'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:42:in `each'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:42:in `each_slice'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:42:in `deploy_batch'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:35:in `block in deploy_batches'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:33:in `each'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:33:in `each_with_index'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:33:in `deploy_batches'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:16:in `block in run'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:186:in `time_took'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/all/runner.rb:12:in `run'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/cli/all.rb:43:in `plan'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/command.rb:61:in `dispatch'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/thor-1.2.1/lib/thor/invocation.rb:116:in `invoke'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/thor-1.2.1/lib/thor.rb:243:in `block in subcommand'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/command.rb:61:in `dispatch'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/thor-1.2.1/lib/thor/base.rb:485:in `start'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/lib/terraspace/cli/concern.rb:65:in `start'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/gems/terraspace-1.1.7/exe/terraspace:14:in `<top (required)>'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/bin/terraspace:25:in `load'
    from /home/lmariani/Proyectos/Minando/Terraspace/Azure/vendor/bundle/ruby/3.0.0/bin/terraspace:25:in `<top (required)>'
    from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/bundler-2.3.7/lib/bundler/cli/exec.rb:58:in `load'
    from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/bundler-2.3.7/lib/bundler/cli/exec.rb:58:in `kernel_load'
    from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/bundler-2.3.7/lib/bundler/cli/exec.rb:23:in `run'
    from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/bundler-2.3.7/lib/bundler/cli.rb:484:in `exec'
    from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/bundler-2.3.7/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/bundler-2.3.7/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
    from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/bundler-2.3.7/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
    from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/bundler-2.3.7/lib/bundler/cli.rb:31:in `dispatch'
    from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/bundler-2.3.7/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
    from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/bundler-2.3.7/lib/bundler/cli.rb:25:in `start'
    from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/bundler-2.3.7/exe/bundle:48:in `block in <top (required)>'
    from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/bundler-2.3.7/lib/bundler/friendly_errors.rb:103:in `with_friendly_errors'
    from /opt/terraspace/embedded/lib/ruby/gems/3.0.0/gems/bundler-2.3.7/exe/bundle:36:in `<top (required)>'
    from /opt/terraspace/embedded/bin/bundle:23:in `load'
    from /opt/terraspace/embedded/bin/bundle:23:in `<main>'
Error running: terraspace plan kubernetes. Fix the error above or check logs for the error.

terraspace plan logs

# Logfile created on 2022-03-03 21:51:54 -0300 by logger.rb/v1.4.3
[2022-03-03T21:51:54 #834820 terraspace plan kubernetes]: Current directory: .terraspace-cache/eastus/production/stacks/kubernetes
[2022-03-03T21:51:55 #834820 terraspace plan kubernetes]: Creating Resource Group production-eastus...
[2022-03-03T21:52:02 #834820 terraspace plan kubernetes]: Creating Storage Account tsxxxdeastusproduction...
[2022-03-03T21:53:31 #836626 terraspace plan kubernetes]: Current directory: .terraspace-cache/eastus/production/stacks/kubernetes
[2022-03-03T21:53:36 #836626 terraspace plan kubernetes]: Creating Storage Account tsxxxdeastusproduction...
[2022-03-03T21:57:10 #841089 terraspace plan kubernetes]: Current directory: .terraspace-cache/eastus/production/stacks/kubernetes
[2022-03-03T21:57:14 #841089 terraspace plan kubernetes]: Creating Storage Account tsxxxdeastusproduction...
[2022-03-03T22:15:52 #861300 terraspace plan kubernetes]: Current directory: .terraspace-cache/eastus/production/stacks/kubernetes
[2022-03-03T22:15:53 #861300 terraspace plan kubernetes]: Creating Resource Group production-eastus...
[2022-03-03T22:16:36 #862153 terraspace plan kubernetes]: Current directory: .terraspace-cache/eastus/production/stacks/kubernetes
[2022-03-03T22:16:37 #862153 terraspace plan kubernetes]: Creating Resource Group production-eastus...
[2022-03-03T23:42:01 #954398 terraspace plan kubernetes]: Current directory: .terraspace-cache/eastus/production/stacks/kubernetes
[2022-03-03T23:42:07 #954398 terraspace plan kubernetes]: Creating Storage Account tsxxxdeastusproduction...
[2022-03-03T23:42:44 #955278 terraspace plan kubernetes]: Current directory: .terraspace-cache/eastus/production/stacks/kubernetes
[2022-03-03T23:42:47 #955278 terraspace plan kubernetes]: Creating Storage Account tsxxxdeastusproduction...
[2022-03-03T23:47:25 #960906 terraspace plan kubernetes]: Current directory: .terraspace-cache/eastus/production/stacks/kubernetes
[2022-03-03T23:47:29 #960906 terraspace plan kubernetes]: Creating Storage Account tsxxxdeastusproduction...
[2022-03-03T23:55:29 #970859 terraspace plan kubernetes]: Current directory: .terraspace-cache/eastus/production/stacks/kubernetes
[2022-03-03T23:55:34 #970859 terraspace plan kubernetes]: Creating Storage Account tsxxxdeastusproduction...
[2022-03-04T00:09:32 #987433 terraspace plan kubernetes]: Current directory: .terraspace-cache/eastus/production/stacks/kubernetes
[2022-03-04T00:09:36 #987433 terraspace plan kubernetes]: Creating Storage Account tsxxxdeastusproduction...
[2022-03-04T00:10:01 #987977 terraspace plan kubernetes]: Current directory: .terraspace-cache/eastus/production/stacks/kubernetes
[2022-03-04T00:10:05 #987977 terraspace plan kubernetes]: Creating Storage Account tsxxxdeastusproduction...
[2022-03-04T00:19:41 #1014348 terraspace plan kubernetes]: Current directory: .terraspace-cache/eastus/production/stacks/kubernetes
[2022-03-04T00:19:50 #1014348 terraspace plan kubernetes]: Creating Storage Account tsxxxdeastusproduction...
[2022-03-04T00:25:50 #1021320 terraspace plan kubernetes]: Current directory: .terraspace-cache/eastus/production/stacks/kubernetes
[2022-03-04T00:25:53 #1021320 terraspace plan kubernetes]: Creating Storage Account tsxxxdeastusproduction...
[2022-03-04T00:35:07 #1031477 terraspace plan kubernetes]: Current directory: .terraspace-cache/eastus/production/stacks/kubernetes
[2022-03-04T00:35:11 #1031477 terraspace plan kubernetes]: Creating Storage Account tsxxxdeastusproduction..

Code Sample

It fails before executing my terraform code, it fails when trying to create the storage of the tf_state

Solution Suggestion

tongueroo commented 2 years ago

From the stack trace. It looks like it’s erroring trying to create the storage account. When you get a chance, can you change the logger level to debug and run again.

Docs: https://terraspace.cloud/docs/config/app/

Wondering if there’s more info in the http response from the Azure API. Increasing the log level should show more info.

https://github.com/boltops-tools/armrest/blob/3bb38d3466556a7b77c6786fd252de02da533e10/lib/armrest/api/base.rb#L39

psyreactor commented 2 years ago

Hi, the terraspace debug does not provide any important information. But the armrest can be debugged with the following environment variable ARMREST_LOG_LEVEL

export ARMREST_LOG_LEVEL=debug

In the logs you can clearly see the error

D, [2022-03-04T07:57:31.499945 #1077405] DEBUG -- : PUT https://management.azure.com/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/production-eastus/providers/Microsoft.Storage/storageAccounts/tsxxxdeastusproduction?api-version=2021-04-01
D, [2022-03-04T07:57:32.822620 #1077405] DEBUG -- : resp #<Net::HTTPConflict:0x0000560f22ef4d18>
D, [2022-03-04T07:57:32.822705 #1077405] DEBUG -- : resp.code 409
D, [2022-03-04T07:57:32.822729 #1077405] DEBUG -- : resp.body {"error":{"code":"MissingSubscriptionRegistration","message":"The subscription is not registered to use namespace 'Microsoft.Storage'. See https://aka.ms/rps-not-found for how to register subscriptions.","details":[{"code":"MissingSubscriptionRegistration","target":"Microsoft.Storage","message":"The subscription is not registered to use namespace 'Microsoft.Storage'. See https://aka.ms/rps-not-found for how to register subscriptions."}]}}

To fix the issue run the following command from the azure cli

az provider register --namespace Microsoft.Storage

now it works perfect

Thanks for the help