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

[WIP] r/aws_opsworks_stack: Use correct region for ARN when updating tags #11849

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions aws/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"strings"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/organizations"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -359,6 +361,43 @@ func testAccOrganizationsAccountPreCheck(t *testing.T) {
t.Skip("skipping tests; this AWS account must not be an existing member of an AWS Organization")
}

// testAccPreCheckHasDefaultVpc checks that the test region has a default VPC.
func testAccPreCheckHasDefaultVpc(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from #11126.

if !testAccHasDefaultVpc(t) {
region := testAccProvider.Meta().(*AWSClient).region
t.Skipf("skipping tests; %s does not have a default VPC", region)
}
}

// testAccPreCheckHasDefaultVpcOrEc2Classic checks that the test region has a default VPC or has the EC2-Classic platform.
// This check is useful to ensure that an instance can be launched without specifying a subnet.
func testAccPreCheckHasDefaultVpcOrEc2Classic(t *testing.T) {
client := testAccProvider.Meta().(*AWSClient)

if !testAccHasDefaultVpc(t) && !hasEc2Classic(client.supportedplatforms) {
t.Skipf("skipping tests; %s does not have a default VPC or EC2-Classic", client.region)
}
}

func testAccHasDefaultVpc(t *testing.T) bool {
conn := testAccProvider.Meta().(*AWSClient).ec2conn

resp, err := conn.DescribeAccountAttributes(&ec2.DescribeAccountAttributesInput{
AttributeNames: aws.StringSlice([]string{ec2.AccountAttributeNameDefaultVpc}),
})
if testAccPreCheckSkipError(err) ||
len(resp.AccountAttributes) == 0 ||
len(resp.AccountAttributes[0].AttributeValues) == 0 ||
aws.StringValue(resp.AccountAttributes[0].AttributeValues[0].AttributeValue) == "none" {
return false
}
if err != nil {
t.Fatalf("error describing EC2 account attributes: %s", err)
}

return true
}

func testAccAlternateAccountProviderConfig() string {
return fmt.Sprintf(`
provider "aws" {
Expand Down
8 changes: 2 additions & 6 deletions aws/resource_aws_opsworks_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/opsworks"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down Expand Up @@ -391,7 +390,7 @@ func opsworksConnForRegion(region string, meta interface{}) (*opsworks.OpsWorks,
originalConn := meta.(*AWSClient).opsworksconn

// Regions are the same, no need to reconfigure
if originalConn.Config.Region != nil && *originalConn.Config.Region == region {
if aws.StringValue(originalConn.Config.Region) == region {
return originalConn, nil
}

Expand All @@ -401,8 +400,6 @@ func opsworksConnForRegion(region string, meta interface{}) (*opsworks.OpsWorks,
return nil, fmt.Errorf("Error creating AWS session: %s", err)
}

sess.Handlers.Build.PushBack(request.MakeAddToUserAgentHandler("APN/1.0 HashiCorp/1.0 Terraform", meta.(*AWSClient).terraformVersion))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User agent configuration is in originalConn.Config.


newSession := sess.Copy(&aws.Config{Region: aws.String(region)})
newOpsworksconn := opsworks.New(newSession)

Expand Down Expand Up @@ -476,8 +473,7 @@ func resourceAwsOpsworksStackCreate(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("Error creating Opsworks stack: %s", err)
}

stackId := *resp.StackId
d.SetId(stackId)
d.SetId(aws.StringValue(resp.StackId))

if inVpc && *req.UseOpsworksSecurityGroups {
// For VPC-based stacks, OpsWorks asynchronously creates some default
Expand Down
Loading