Merge pull request #14685 from hashicorp/f-open-lightsail-regions

provider/aws: Allow lightsail resources to work in other regions
This commit is contained in:
Jake Champlin 2017-05-19 17:16:13 -04:00 committed by GitHub
commit 90b5d81933
2 changed files with 45 additions and 8 deletions

View File

@ -269,12 +269,11 @@ func (c *Config) Client() (interface{}, error) {
sess.Handlers.UnmarshalError.PushFrontNamed(debugAuthFailure) sess.Handlers.UnmarshalError.PushFrontNamed(debugAuthFailure)
} }
// Some services exist only in us-east-1, e.g. because they manage // This restriction should only be used for Route53 sessions.
// resources that can span across multiple regions, or because // Other resources that have restrictions should allow the API to fail, rather
// signature format v4 requires region to be us-east-1 for global // than Terraform abstracting the region for the user. This can lead to breaking
// endpoints: // changes if that resource is ever opened up to more regions.
// http://docs.aws.amazon.com/general/latest/gr/sigv4_changes.html r53Sess := sess.Copy(&aws.Config{Region: aws.String("us-east-1")})
usEast1Sess := sess.Copy(&aws.Config{Region: aws.String("us-east-1")})
// Some services have user-configurable endpoints // Some services have user-configurable endpoints
awsCfSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.CloudFormationEndpoint)}) awsCfSess := sess.Copy(&aws.Config{Endpoint: aws.String(c.CloudFormationEndpoint)})
@ -368,9 +367,9 @@ func (c *Config) Client() (interface{}, error) {
client.kinesisconn = kinesis.New(awsKinesisSess) client.kinesisconn = kinesis.New(awsKinesisSess)
client.kmsconn = kms.New(awsKmsSess) client.kmsconn = kms.New(awsKmsSess)
client.lambdaconn = lambda.New(sess) client.lambdaconn = lambda.New(sess)
client.lightsailconn = lightsail.New(usEast1Sess) client.lightsailconn = lightsail.New(sess)
client.opsworksconn = opsworks.New(sess) client.opsworksconn = opsworks.New(sess)
client.r53conn = route53.New(usEast1Sess) client.r53conn = route53.New(r53Sess)
client.rdsconn = rds.New(awsRdsSess) client.rdsconn = rds.New(awsRdsSess)
client.redshiftconn = redshift.New(sess) client.redshiftconn = redshift.New(sess)
client.simpledbconn = simpledb.New(sess) client.simpledbconn = simpledb.New(sess)

View File

@ -38,6 +38,30 @@ func TestAccAWSLightsailInstance_basic(t *testing.T) {
}) })
} }
func TestAccAWSLightsailInstance_euRegion(t *testing.T) {
var conf lightsail.Instance
lightsailName := fmt.Sprintf("tf-test-lightsail-%d", acctest.RandInt())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_lightsail_instance.lightsail_instance_test",
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLightsailInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLightsailInstanceConfig_euRegion(lightsailName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSLightsailInstanceExists("aws_lightsail_instance.lightsail_instance_test", &conf),
resource.TestCheckResourceAttrSet("aws_lightsail_instance.lightsail_instance_test", "availability_zone"),
resource.TestCheckResourceAttrSet("aws_lightsail_instance.lightsail_instance_test", "blueprint_id"),
resource.TestCheckResourceAttrSet("aws_lightsail_instance.lightsail_instance_test", "bundle_id"),
resource.TestCheckResourceAttrSet("aws_lightsail_instance.lightsail_instance_test", "key_pair_name"),
),
},
},
})
}
func TestAccAWSLightsailInstance_disapear(t *testing.T) { func TestAccAWSLightsailInstance_disapear(t *testing.T) {
var conf lightsail.Instance var conf lightsail.Instance
lightsailName := fmt.Sprintf("tf-test-lightsail-%d", acctest.RandInt()) lightsailName := fmt.Sprintf("tf-test-lightsail-%d", acctest.RandInt())
@ -149,3 +173,17 @@ resource "aws_lightsail_instance" "lightsail_instance_test" {
} }
`, lightsailName) `, lightsailName)
} }
func testAccAWSLightsailInstanceConfig_euRegion(lightsailName string) string {
return fmt.Sprintf(`
provider "aws" {
region = "eu-west-1"
}
resource "aws_lightsail_instance" "lightsail_instance_test" {
name = "%s"
availability_zone = "eu-west-1a"
blueprint_id = "joomla_3_6_5"
bundle_id = "nano_1_0"
}
`, lightsailName)
}