Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows support #202

Merged
merged 3 commits into from
Feb 16, 2022
Merged

Windows support #202

merged 3 commits into from
Feb 16, 2022

Conversation

tongueroo
Copy link
Contributor

@tongueroo tongueroo commented Feb 16, 2022

This is a 🐞 bug fix.
This is a πŸ™‹β€β™‚οΈ feature or enhancement.

  • I've added tests (if it's a bug, feature or enhancement)
  • I've adjusted the documentation (if it's a feature or enhancement)
  • The test suite passes (run bundle exec rspec to verify this)

Summary

Add support for windows. Note: would like to test this some more but this seems to be enough to support windows.

Context

Related conversation #84

How to Test

Go through one of the getting started guides on Windows

https://terraspace.cloud/getting-started/

Version Changes

Patch

@CumpsD
Copy link
Contributor

CumpsD commented Feb 16, 2022

bundle exec terraspace up demo 
Building .terraspace-cache/eu-central-1/dev/stacks/demo
Built in .terraspace-cache/eu-central-1/dev/stacks/demo
Current directory: .terraspace-cache/eu-central-1/dev/stacks/demo
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/aws-sdk-core/plugins/regional_endpoint.rb:61:in `block in <class:RegionalEndpoint>': Invalid `:region` option was provided. (Aws::Errors::InvalidRegionError)

* Not every service is available in every region.

* Never suffix region names with availability zones.
  Use "us-east-1", not "us-east-1a"

Known AWS regions include (not specific to this service):

af-south-1
ap-east-1
ap-northeast-1
ap-northeast-2
ap-northeast-3
ap-south-1
ap-southeast-1
ap-southeast-2
ap-southeast-3
ca-central-1
eu-central-1
eu-north-1
eu-south-1
eu-west-1
eu-west-2
eu-west-3
me-south-1
sa-east-1
us-east-1
us-east-2
us-west-1
us-west-2
cn-north-1
cn-northwest-1
us-gov-east-1
us-gov-west-1
us-iso-east-1
us-iso-west-1
us-isob-east-1
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/configuration.rb:72:in `call'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/configuration.rb:219:in `block in resolve_defaults'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/configuration.rb:59:in `each'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/configuration.rb:59:in `each'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/configuration.rb:218:in `resolve_defaults'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/configuration.rb:211:in `value_at'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/configuration.rb:191:in `block in resolve'
        from C:/Ruby31-x64/lib/ruby/3.1.0/set.rb:511:in `each_key'
        from C:/Ruby31-x64/lib/ruby/3.1.0/set.rb:511:in `each'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/configuration.rb:191:in `resolve'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/configuration.rb:179:in `apply_defaults'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/configuration.rb:152:in `build!'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/base.rb:65:in `build_config'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/base.rb:22:in `initialize'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/aws-sdk-sts/client.rb:354:in `initialize'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/base.rb:102:in `new'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/terraspace_plugin_aws-0.3.7/lib/terraspace_plugin_aws/clients.rb:27:in `sts'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/memoist-0.16.2/lib/memoist.rb:169:in `sts'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/terraspace_plugin_aws-0.3.7/lib/terraspace_plugin_aws/interfaces/backend/setup.rb:4:in `check!'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/terraspace_plugin_aws-0.3.7/lib/terraspace_plugin_aws/interfaces/backend.rb:9:in `call'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/terraform/runner/backend.rb:25:in `create'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/terraform/runner.rb:49:in `block in terraform'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/hooks/builder.rb:25:in `run_hooks'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/hooks/concern.rb:6:in `run_hooks'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/terraform/runner.rb:48:in `terraform'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/terraform/runner.rb:15:in `block in run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/terraform/runner.rb:89:in `time_took'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/terraform/runner.rb:14:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/cli/init.rb:23:in `block in init'
        from C:/Ruby31-x64/lib/ruby/3.1.0/timeout.rb:107:in `block in timeout'
        from C:/Ruby31-x64/lib/ruby/3.1.0/timeout.rb:36:in `block in catch'
        from C:/Ruby31-x64/lib/ruby/3.1.0/timeout.rb:36:in `catch'
        from C:/Ruby31-x64/lib/ruby/3.1.0/timeout.rb:36:in `catch'
        from C:/Ruby31-x64/lib/ruby/3.1.0/timeout.rb:123:in `timeout'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/cli/init.rb:22:in `init'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/cli/init.rb:12:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/cli/commander.rb:10:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/cli/up.rb:13:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/cli.rb:230:in `up'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/command.rb:61:in `dispatch'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/base.rb:485:in `start'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/cli/concern.rb:65:in `start'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/exe/terraspace:14:in `<top (required)>'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bin/terraspace:25:in `load'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bin/terraspace:25:in `<main>'

Not sure where it's coming from, since I use eu-central-1

@tongueroo
Copy link
Contributor Author

tongueroo commented Feb 16, 2022

Weird that it was working on the other thread. Wondering what region is being passed.

https://github.com/boltops-tools/terraspace_plugin_aws/blob/199bbcec4ad89bb48e05ce7af1774ced07d2bc5d/lib/terraspace_plugin_aws/clients/options.rb#L91

Try adding this and seeing what the region is set to:

    def client_options
      return {} unless @info # aws_secret helper wont have @info
      x = if @info['role_arn']
        client_assume_role_options
      else
        client_default_options
      end
      puts "client_options:"
      pp client_options
      x
    end

The terrraspace_plugin_aws uses the aws_data library to detect region here: https://github.com/boltops-tools/aws_data/blob/master/lib/aws_data.rb#L10

So that could be related.

Maybe in the other terminal the AWS_REGION env was set. Though, still would like to fix the aws region detection either way. πŸ‘

@CumpsD
Copy link
Contributor

CumpsD commented Feb 16, 2022

Nah, it's the same terminal, and no env var is used. I configured the default AWS profile.

Not sure if your snippet is correct, because it goes in an endless loop on pp client_options

If I change it to:

    def client_options
      return {} unless @info # aws_secret helper wont have @info
      x = if @info['role_arn']
        client_assume_role_options
      else
        client_default_options
      end
      puts "client_options:"
      puts x
      x
    end

It prints

client_options:
{:region=>"<%= expansion(':REGION') %>"}
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/aws-sdk-core/plugins/regional_endpoint.rb:61:in `block in <class:RegionalEndpoint>': Invalid `:region` option was provided. (Aws::Errors::InvalidRegionError)

@CumpsD
Copy link
Contributor

CumpsD commented Feb 16, 2022

To be sure, I changed the version in my local copy and ran

bundle exec terraspace -v      
1.1.1-win

So I'm on the correct branch for sure :)

@CumpsD
Copy link
Contributor

CumpsD commented Feb 16, 2022

The incorrect region is coming from infra\config\terraform\backend.tf

    region         = "<%= expansion(':REGION') %>"

If I change it to

    region         = "eu-central-1"

I get:

bundle exec terraspace up demo 
Building .terraspace-cache/eu-central-1/dev/stacks/demo
Built in .terraspace-cache/eu-central-1/dev/stacks/demo
Current directory: .terraspace-cache/eu-central-1/dev/stacks/demo
client_options:
{:region=>"eu-central-1"}
client_options:
{:region=>"eu-central-1"}
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/plugins/raise_response_errors.rb:17:in `call': Aws::S3::Errors::BadRequest (Aws::S3::Errors::BadRequest)
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-s3-1.112.0/lib/aws-sdk-s3/plugins/sse_cpk.rb:24:in `call'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-s3-1.112.0/lib/aws-sdk-s3/plugins/dualstack.rb:27:in `call'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-s3-1.112.0/lib/aws-sdk-s3/plugins/accelerate.rb:56:in `call'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/aws-sdk-core/plugins/jsonvalue_converter.rb:22:in `call'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/aws-sdk-core/plugins/idempotency_token.rb:19:in `call'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/aws-sdk-core/plugins/param_converter.rb:26:in `call'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/plugins/request_callback.rb:71:in `call'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/aws-sdk-core/plugins/response_paging.rb:12:in `call'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/plugins/response_target.rb:24:in `call'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-core-3.126.2/lib/seahorse/client/request.rb:72:in `send_request'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/aws-sdk-s3-1.112.0/lib/aws-sdk-s3/client.rb:6472:in `head_bucket'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/terraspace_plugin_aws-0.3.7/lib/terraspace_plugin_aws/interfaces/backend/bucket.rb:25:in `exist?'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/terraspace_plugin_aws-0.3.7/lib/terraspace_plugin_aws/interfaces/backend/bucket.rb:11:in `create'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/terraspace_plugin_aws-0.3.7/lib/terraspace_plugin_aws/interfaces/backend.rb:10:in `call'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/terraform/runner/backend.rb:25:in `create'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/terraform/runner.rb:49:in `block in terraform'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/hooks/builder.rb:25:in `run_hooks'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/hooks/concern.rb:6:in `run_hooks'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/terraform/runner.rb:48:in `terraform'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/terraform/runner.rb:15:in `block in run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/terraform/runner.rb:89:in `time_took'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/terraform/runner.rb:14:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/cli/init.rb:23:in `block in init'
        from C:/Ruby31-x64/lib/ruby/3.1.0/timeout.rb:107:in `block in timeout'
        from C:/Ruby31-x64/lib/ruby/3.1.0/timeout.rb:36:in `block in catch'
        from C:/Ruby31-x64/lib/ruby/3.1.0/timeout.rb:36:in `catch'
        from C:/Ruby31-x64/lib/ruby/3.1.0/timeout.rb:36:in `catch'
        from C:/Ruby31-x64/lib/ruby/3.1.0/timeout.rb:123:in `timeout'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/cli/init.rb:22:in `init'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/cli/init.rb:12:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/cli/commander.rb:10:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/cli/up.rb:13:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/cli.rb:230:in `up'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/command.rb:61:in `dispatch'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/base.rb:485:in `start'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/lib/terraspace/cli/concern.rb:65:in `start'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bundler/gems/terraspace-ff72d812d3ce/exe/terraspace:14:in `<top (required)>'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bin/terraspace:25:in `load'
        from C:/Ruby31-x64/lib/ruby/gems/3.1.0/bin/terraspace:25:in `<main>'

@CumpsD
Copy link
Contributor

CumpsD commented Feb 16, 2022

If I remove all ERB templates from backend.tf it works!

bundle exec terraspace up demo 
Building .terraspace-cache/eu-central-1/dev/stacks/demo
Built in .terraspace-cache/eu-central-1/dev/stacks/demo
Current directory: .terraspace-cache/eu-central-1/dev/stacks/demo
client_options:
{:region=>"eu-central-1"}
client_options:
{:region=>"eu-central-1"}
client_options:
{:region=>"eu-central-1"}
=> terraform init -get -input=false >> /tmp/terraspace/log/init/demo.log
=> terraform apply -input=false
random_pet.this: Refreshing state... [id=adapted-piranha]
module.bucket.aws_s3_bucket.this: Refreshing state... [id=bucket-adapted-piranha]
module.bucket.aws_s3_bucket_acl.this: Refreshing state... [id=bucket-adapted-piranha,public-read]

Note: Objects have changed outside of Terraform


Terraform detected the following changes made outside of Terraform since the
last "terraform apply":
  # module.bucket.aws_s3_bucket.this has changed
..........

Unless you have made equivalent changes to your configuration, or ignored the
relevant attributes using ignore_changes, the following plan may include
actions to undo or respond to these changes.

─────────────────────────────────────────────────────────────────────────────

No changes. Your infrastructure matches the configuration.

Your configuration already matches the changes detected above. If you'd like
to update the Terraform state to match, create and apply a refresh-only plan:
  terraform apply -refresh-only

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.


Outputs:

bucket_name = "bucket-adapted-piranha"
Time took: 6s

@CumpsD
Copy link
Contributor

CumpsD commented Feb 16, 2022

So I think this PR can be merged as a way to support Windows, even without the ERB support right now (maybe a future fix?)

πŸ‘πŸ» πŸ‘πŸ»

@tongueroo tongueroo merged commit a759682 into master Feb 16, 2022
@tongueroo tongueroo deleted the windows branch February 16, 2022 22:02
@tongueroo
Copy link
Contributor Author

tongueroo commented Feb 16, 2022

Merged. On the road now. Will release once get back to a computer. πŸ’»

Note: For the error above. For some reason it looks like the ERB is not being rendered. Unsure.

@CumpsD
Copy link
Contributor

CumpsD commented Feb 16, 2022

Yeah, looks like that.

Thanks! Looking forward for the release :)

@tongueroo tongueroo mentioned this pull request Feb 16, 2022
3 tasks
@tongueroo
Copy link
Contributor Author

tongueroo commented Feb 16, 2022

Can you test again when you get a chance. This time on the master branch. Test with ERB. It was a simple fix in #203 Actually created the entire PR on my phone πŸ“±while in the car πŸš™ lol 🀣

@CumpsD
Copy link
Contributor

CumpsD commented Feb 16, 2022

Can you test again when you get a chance. This time on the master branch. Test with ERB. It was a simple fix in #203 Actually created the entire PR on my phone πŸ“±while in the car πŸš™ lol 🀣

Master works, with ERB :) πŸ‘πŸ»

@tongueroo
Copy link
Contributor Author

Released in 1.1.2

@CumpsD
Copy link
Contributor

CumpsD commented Feb 17, 2022

Awesome, thanks for the support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants