Skip to content

Commit

Permalink
Merge pull request #7654 from terraform-providers/td-IsChinaCloud-rem…
Browse files Browse the repository at this point in the history
…oval

provider: Remove hardcoded AWS China handling
  • Loading branch information
bflad authored Feb 25, 2019
2 parents e567b2d + c20f630 commit f2129c3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 54 deletions.
5 changes: 0 additions & 5 deletions aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,6 @@ func (c *AWSClient) DynamoDB() *dynamodb.DynamoDB {
return c.dynamodbconn
}

func (c *AWSClient) IsChinaCloud() bool {
_, isChinaCloud := endpoints.PartitionForRegion([]endpoints.Partition{endpoints.AwsCnPartition()}, c.region)
return isChinaCloud
}

// Client configures and returns a fully initialized AWSClient
func (c *Config) Client() (interface{}, error) {
// Get the auth and region. This can fail if keys/regions were not
Expand Down
63 changes: 26 additions & 37 deletions aws/resource_aws_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,36 +555,32 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Only 1 of `ipv6_address_count` or `ipv6_addresses` can be specified")
}

restricted := meta.(*AWSClient).IsChinaCloud()
if !restricted {
tagsSpec := make([]*ec2.TagSpecification, 0)

tagsSpec := make([]*ec2.TagSpecification, 0)
if v, ok := d.GetOk("tags"); ok {
tags := tagsFromMap(v.(map[string]interface{}))

if v, ok := d.GetOk("tags"); ok {
tags := tagsFromMap(v.(map[string]interface{}))

spec := &ec2.TagSpecification{
ResourceType: aws.String("instance"),
Tags: tags,
}

tagsSpec = append(tagsSpec, spec)
spec := &ec2.TagSpecification{
ResourceType: aws.String("instance"),
Tags: tags,
}

if v, ok := d.GetOk("volume_tags"); ok {
tags := tagsFromMap(v.(map[string]interface{}))
tagsSpec = append(tagsSpec, spec)
}

spec := &ec2.TagSpecification{
ResourceType: aws.String("volume"),
Tags: tags,
}
if v, ok := d.GetOk("volume_tags"); ok {
tags := tagsFromMap(v.(map[string]interface{}))

tagsSpec = append(tagsSpec, spec)
spec := &ec2.TagSpecification{
ResourceType: aws.String("volume"),
Tags: tags,
}

if len(tagsSpec) > 0 {
runOpts.TagSpecifications = tagsSpec
}
tagsSpec = append(tagsSpec, spec)
}

if len(tagsSpec) > 0 {
runOpts.TagSpecifications = tagsSpec
}

// Create the instance
Expand Down Expand Up @@ -900,25 +896,18 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn

d.Partial(true)
restricted := meta.(*AWSClient).IsChinaCloud()

if d.HasChange("tags") {
if !d.IsNewResource() || restricted {
if err := setTags(conn, d); err != nil {
return err
} else {
d.SetPartial("tags")
}
if d.HasChange("tags") && !d.IsNewResource() {
if err := setTags(conn, d); err != nil {
return err
}
d.SetPartial("tags")
}
if d.HasChange("volume_tags") {
if !d.IsNewResource() || restricted {
if err := setVolumeTags(conn, d); err != nil {
return err
} else {
d.SetPartial("volume_tags")
}
if d.HasChange("volume_tags") && !d.IsNewResource() {
if err := setVolumeTags(conn, d); err != nil {
return err
}
d.SetPartial("volume_tags")
}

if d.HasChange("iam_instance_profile") && !d.IsNewResource() {
Expand Down
14 changes: 2 additions & 12 deletions aws/resource_aws_s3_bucket_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ func resourceAwsS3BucketObject() *schema.Resource {
func resourceAwsS3BucketObjectPut(d *schema.ResourceData, meta interface{}) error {
s3conn := meta.(*AWSClient).s3conn

restricted := meta.(*AWSClient).IsChinaCloud()

var body io.ReadSeeker

if v, ok := d.GetOk("source"); ok {
Expand Down Expand Up @@ -241,10 +239,6 @@ func resourceAwsS3BucketObjectPut(d *schema.ResourceData, meta interface{}) erro
}

if v, ok := d.GetOk("tags"); ok {
if restricted {
return fmt.Errorf("This region does not allow for tags on S3 objects")
}

// The tag-set must be encoded as URL Query parameters.
values := url.Values{}
for k, v := range v.(map[string]interface{}) {
Expand Down Expand Up @@ -272,8 +266,6 @@ func resourceAwsS3BucketObjectCreate(d *schema.ResourceData, meta interface{}) e
func resourceAwsS3BucketObjectRead(d *schema.ResourceData, meta interface{}) error {
s3conn := meta.(*AWSClient).s3conn

restricted := meta.(*AWSClient).IsChinaCloud()

bucket := d.Get("bucket").(string)
key := d.Get("key").(string)

Expand Down Expand Up @@ -329,10 +321,8 @@ func resourceAwsS3BucketObjectRead(d *schema.ResourceData, meta interface{}) err
d.Set("storage_class", resp.StorageClass)
}

if !restricted {
if err := getTagsS3Object(s3conn, d); err != nil {
return fmt.Errorf("error getting S3 object tags (bucket: %s, key: %s): %s", bucket, key, err)
}
if err := getTagsS3Object(s3conn, d); err != nil {
return fmt.Errorf("error getting S3 object tags (bucket: %s, key: %s): %s", bucket, key, err)
}

return nil
Expand Down

0 comments on commit f2129c3

Please sign in to comment.