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

Allow to specify AWS.Region endpoint to support Eucalyptus flavor of EC2 #416

Closed
elyast opened this issue Oct 16, 2014 · 18 comments
Closed

Comments

@elyast
Copy link

elyast commented Oct 16, 2014

Feature request, allow to specify endpoint as following:

    region "region x" {
      ec2_endpoint = "http://eucalyptus.escloc57.eecloud.nsn-net.net:8773/services/Eucalyptus"
      s3_endpoint = "..."
    }

How to use goamz with euca: https://www.eucalyptus.com/blog/2014/04/24/using-golang-eucalyptus

@mitchellh
Copy link
Contributor

Good feature request. Tagged.

@elyast
Copy link
Author

elyast commented Oct 20, 2014

As far as I checked it could be done in super simple way, but a bit hacky (so allow to pass name as region name or endpoint) and I have verified it works with eucalyptus 3.4.3+

sample config:

provider "aws" {
    access_key = "xxx"
    secret_key = "xxx"
    region = "http://euca-ip:8773/services/Eucalyptus"
}

resource "aws_instance" "web" {
  instance_type = "m1.small"
  ami = "emi-00E03519"
  count = 1
}

and required changes:

diff --git a/builtin/providers/aws/config.go b/builtin/providers/aws/config.go
index 8479cb9..c7f2f06 100644
--- a/builtin/providers/aws/config.go
+++ b/builtin/providers/aws/config.go
@@ -33,15 +33,18 @@ func (c *Config) AWSAuth() (aws.Auth, error) {
 // IsValidRegion returns true if the configured region is a valid AWS
 // region and false if it's not
 func (c *Config) IsValidRegion() bool {
-       var regions = [8]string{"us-east-1", "us-west-2", "us-west-1", "eu-west-1",
-               "ap-southeast-1", "ap-southeast-2", "ap-northeast-1", "sa-east-1"}
+       return true
+}

-       for _, valid := range regions {
-               if c.Region == valid {
-                       return true
+func (c *Config) createRegion() aws.Region {
+  var regions = [8]string{"us-east-1", "us-west-2", "us-west-1", "eu-west-1",
+               "ap-southeast-1", "ap-southeast-2", "ap-northeast-1", "sa-east-1"}
+  for _, valid := range regions {
+    if c.Region == valid {
+                 return aws.Regions[c.Region]
                }
-       }
-       return false
+  }
+  return aws.Region{EC2Endpoint: c.Region}
 }

 // AWSRegion returns the configured region.
@@ -50,7 +53,7 @@ func (c *Config) IsValidRegion() bool {
 func (c *Config) AWSRegion() (aws.Region, error) {
        if c.Region != "" {
                if c.IsValidRegion() {
-                       return aws.Regions[c.Region], nil
+                       return c.createRegion(), nil
                } else {
                        return aws.Region{}, fmt.Errorf("Not a valid region: %s", c.Region)
                }

@wolfspyre
Copy link

+1 for this.

@neongazer
Copy link

+1 for this

@phinze
Copy link
Contributor

phinze commented May 12, 2015

We've had recent users reporting success in using Terraform with Eucalyptus, so I'm going to mark this as closed. Feel free to lobby for reopening if there's still something we're missing in the latest version.

@phinze phinze closed this as completed May 12, 2015
@elyast
Copy link
Author

elyast commented May 13, 2015

care to share sample config?

@phinze
Copy link
Contributor

phinze commented May 13, 2015

@elyast sure! Here's the issue where working config was being tossed around: #1752 (comment)

@elyast
Copy link
Author

elyast commented May 14, 2015

@phinze looking at the config I am not sure how do u specify region url, additionally looking at: https://github.com/hashicorp/terraform/blob/master/builtin/providers/aws/config.go#L127 its hard to believe "eucalyptus" is proper region name...

but if you want to track this feature in #1752 fine with me

@phinze
Copy link
Contributor

phinze commented May 14, 2015

Hmm good point @elyast, I wonder if @jeevanullas was working with a custom local build. Your logic makes perfect sense - reopening to track here. Sorry for the mixup!

@phinze phinze reopened this May 14, 2015
@jeevanullas
Copy link

Hi All,

Thanks @phinze for the ping here. @elyast as terraform uses AWS SDK for Go we just modified the relevant endpoint maps in SDK for Go. This helps us because we also use AWS SDK for Go outside of Terraform. In case you are wondering this is how we did it: jeevanullas/aws-sdk-go@a35daa3

By the way this code in terraform here https://github.com/hashicorp/terraform/blob/master/builtin/providers/aws/config.go#L125-L138 can be removed because it is an extra check on the valid regions. Terraform is using AWS SDK for Go so it should rely IMHO on AWS SDK for Go to do the validation.

Please let me know if you have any questions.

Cheers,
Deependra

@lwade
Copy link

lwade commented May 15, 2015

@catsby
Copy link
Contributor

catsby commented May 18, 2015

An advantage of ValidateRegion is that we can validate the region in the plan phase of things. Without it, using an invalid region will generate an error at apply time.

@catsby
Copy link
Contributor

catsby commented Feb 12, 2016

Hey friends – I've merged #4263 which allows you to set a custom endpoint for ELB, EC2 and such, so I'm going to close this. Let us know if you need anything else.

@catsby catsby closed this as completed Feb 12, 2016
@iamfuzz
Copy link

iamfuzz commented Jul 7, 2016

Hi, I tried running the asg aws example against a Euca 4.2.2 cloud but it bails out due to "eucalyptus" being an invalid region name. Can you patch the provided go sdk to allow for it as a region name? Thanks!

@gad0lin
Copy link

gad0lin commented Aug 3, 2016

+1, without ability to pass region validation it can't be used with eucalyptus clouds

@zkorinek
Copy link

+1 without the possibility to define custom region, the custom endpoints not working.

@gad0lin
Copy link

gad0lin commented Nov 13, 2016

Any chance to remove check against hardcoded endpoint. I have been using terraform on ec2 but can't use it against internal Eucalyptus clouds .

@ghost
Copy link

ghost commented Apr 20, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests