provider/aws: Exclude aws_instance volume tagging for China and Gov Clouds (#14055)
Fixes: #14049 The China and Gov regions do not support the new way of tagging instances and volumes on creation. Therefore, we need to hack this to make sure we don't try and set these on instance creation
This commit is contained in:
parent
eeecf5183c
commit
93e5d573ce
|
@ -171,6 +171,20 @@ func (c *AWSClient) DynamoDB() *dynamodb.DynamoDB {
|
||||||
return c.dynamodbconn
|
return c.dynamodbconn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *AWSClient) IsGovCloud() bool {
|
||||||
|
if c.region == "us-gov-west-1" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *AWSClient) IsChinaCloud() bool {
|
||||||
|
if c.region == "cn-north-1" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// Client configures and returns a fully initialized AWSClient
|
// Client configures and returns a fully initialized AWSClient
|
||||||
func (c *Config) Client() (interface{}, error) {
|
func (c *Config) Client() (interface{}, error) {
|
||||||
// Get the auth and region. This can fail if keys/regions were not
|
// Get the auth and region. This can fail if keys/regions were not
|
||||||
|
|
|
@ -432,32 +432,35 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
runOpts.Ipv6Addresses = ipv6Addresses
|
runOpts.Ipv6Addresses = ipv6Addresses
|
||||||
}
|
}
|
||||||
|
|
||||||
tagsSpec := make([]*ec2.TagSpecification, 0)
|
restricted := meta.(*AWSClient).IsGovCloud() || meta.(*AWSClient).IsChinaCloud()
|
||||||
|
if !restricted {
|
||||||
|
tagsSpec := make([]*ec2.TagSpecification, 0)
|
||||||
|
|
||||||
if v, ok := d.GetOk("tags"); ok {
|
if v, ok := d.GetOk("tags"); ok {
|
||||||
tags := tagsFromMap(v.(map[string]interface{}))
|
tags := tagsFromMap(v.(map[string]interface{}))
|
||||||
|
|
||||||
spec := &ec2.TagSpecification{
|
spec := &ec2.TagSpecification{
|
||||||
ResourceType: aws.String("instance"),
|
ResourceType: aws.String("instance"),
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
|
}
|
||||||
|
|
||||||
|
tagsSpec = append(tagsSpec, spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
tagsSpec = append(tagsSpec, spec)
|
if v, ok := d.GetOk("volume_tags"); ok {
|
||||||
}
|
tags := tagsFromMap(v.(map[string]interface{}))
|
||||||
|
|
||||||
if v, ok := d.GetOk("volume_tags"); ok {
|
spec := &ec2.TagSpecification{
|
||||||
tags := tagsFromMap(v.(map[string]interface{}))
|
ResourceType: aws.String("volume"),
|
||||||
|
Tags: tags,
|
||||||
|
}
|
||||||
|
|
||||||
spec := &ec2.TagSpecification{
|
tagsSpec = append(tagsSpec, spec)
|
||||||
ResourceType: aws.String("volume"),
|
|
||||||
Tags: tags,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tagsSpec = append(tagsSpec, spec)
|
if len(tagsSpec) > 0 {
|
||||||
}
|
runOpts.TagSpecifications = tagsSpec
|
||||||
|
}
|
||||||
if len(tagsSpec) > 0 {
|
|
||||||
runOpts.TagSpecifications = tagsSpec
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the instance
|
// Create the instance
|
||||||
|
@ -713,19 +716,24 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
d.Partial(true)
|
d.Partial(true)
|
||||||
|
|
||||||
if d.HasChange("tags") && !d.IsNewResource() {
|
restricted := meta.(*AWSClient).IsGovCloud() || meta.(*AWSClient).IsChinaCloud()
|
||||||
if err := setTags(conn, d); err != nil {
|
|
||||||
return err
|
if d.HasChange("tags") {
|
||||||
} else {
|
if !d.IsNewResource() || !restricted {
|
||||||
d.SetPartial("tags")
|
if err := setTags(conn, d); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
d.SetPartial("tags")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if d.HasChange("volume_tags") {
|
||||||
if d.HasChange("volume_tags") && !d.IsNewResource() {
|
if !d.IsNewResource() || !restricted {
|
||||||
if err := setVolumeTags(conn, d); err != nil {
|
if err := setVolumeTags(conn, d); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
d.SetPartial("volume_tags")
|
d.SetPartial("volume_tags")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue