-
Notifications
You must be signed in to change notification settings - Fork 9k
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
Refactor Pinpoint application resource to use keyvaluetags package #11368
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -330,10 +330,23 @@ func testAccEC2VPCOnlyPreCheck(t *testing.T) { | |
} | ||
} | ||
|
||
func testAccHasServicePreCheck(service string, t *testing.T) { | ||
func testAccPartitionHasServicePreCheck(serviceId string, t *testing.T) { | ||
if partition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), testAccGetRegion()); ok { | ||
if _, ok := partition.Services()[service]; !ok { | ||
t.Skip(fmt.Sprintf("skipping tests; partition does not support %s service", service)) | ||
if _, ok := partition.Services()[serviceId]; !ok { | ||
t.Skip(fmt.Sprintf("skipping tests; partition %s does not support %s service", partition.ID(), serviceId)) | ||
} | ||
} | ||
} | ||
|
||
func testAccRegionHasServicePreCheck(serviceId string, t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checks that the acceptance test regions supports the specified service. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This addition is okay for this and other particular cases, but experience over time has shown the AWS Go SDK endpoints information continually being out of date for some services, which is why we do not use it in many places. We'll always want to prefer behavioral checks (attempting to call an API) over using the endpoint information. 👍 I will add a comment to this function on merge to note that preference. |
||
regionId := testAccGetRegion() | ||
if partition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), regionId); ok { | ||
service, ok := partition.Services()[serviceId] | ||
if !ok { | ||
t.Skip(fmt.Sprintf("skipping tests; partition %s does not support %s service", partition.ID(), serviceId)) | ||
} | ||
if _, ok := service.Regions()[regionId]; !ok { | ||
t.Skip(fmt.Sprintf("skipping tests; region %s does not support %s service", regionId, serviceId)) | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" | ||
) | ||
|
||
func resourceAwsPinpointApp() *schema.Resource { | ||
|
@@ -87,20 +88,24 @@ func resourceAwsPinpointApp() *schema.Resource { | |
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"daily": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Type: schema.TypeInt, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add validations as described here for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
Optional: true, | ||
ValidateFunc: validation.IntBetween(0, 100), | ||
}, | ||
"maximum_duration": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
ValidateFunc: validation.IntAtLeast(60), | ||
}, | ||
"messages_per_second": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
ValidateFunc: validation.IntBetween(50, 20000), | ||
}, | ||
"total": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
ValidateFunc: validation.IntBetween(0, 100), | ||
}, | ||
}, | ||
}, | ||
|
@@ -158,16 +163,16 @@ func resourceAwsPinpointAppCreate(d *schema.ResourceData, meta interface{}) erro | |
}, | ||
} | ||
|
||
if v, ok := d.GetOk("tags"); ok { | ||
req.CreateApplicationRequest.Tags = tagsFromMapPinPointApp(v.(map[string]interface{})) | ||
if v := d.Get("tags").(map[string]interface{}); len(v) > 0 { | ||
req.CreateApplicationRequest.Tags = keyvaluetags.New(v).IgnoreAws().PinpointTags() | ||
} | ||
|
||
output, err := pinpointconn.CreateApp(req) | ||
if err != nil { | ||
return fmt.Errorf("error creating Pinpoint app: %s", err) | ||
} | ||
|
||
d.SetId(*output.ApplicationResponse.Id) | ||
d.SetId(aws.StringValue(output.ApplicationResponse.Id)) | ||
d.Set("arn", output.ApplicationResponse.Arn) | ||
|
||
return resourceAwsPinpointAppUpdate(d, meta) | ||
|
@@ -204,8 +209,15 @@ func resourceAwsPinpointAppUpdate(d *schema.ResourceData, meta interface{}) erro | |
return err | ||
} | ||
|
||
if err := setTagsPinPointApp(conn, d); err != nil { | ||
return fmt.Errorf("error updating PinPoint Application (%s) tags: %s", d.Id(), err) | ||
if !d.IsNewResource() { | ||
arn := d.Get("arn").(string) | ||
if d.HasChange("tags") { | ||
o, n := d.GetChange("tags") | ||
|
||
if err := keyvaluetags.PinpointUpdateTags(conn, arn, o, n); err != nil { | ||
return fmt.Errorf("error updating PinPoint Application (%s) tags: %s", arn, err) | ||
} | ||
} | ||
} | ||
|
||
return resourceAwsPinpointAppRead(d, meta) | ||
|
@@ -242,9 +254,10 @@ func resourceAwsPinpointAppRead(d *schema.ResourceData, meta interface{}) error | |
return err | ||
} | ||
|
||
arn := aws.StringValue(app.ApplicationResponse.Arn) | ||
d.Set("name", app.ApplicationResponse.Name) | ||
d.Set("application_id", app.ApplicationResponse.Id) | ||
d.Set("arn", app.ApplicationResponse.Arn) | ||
d.Set("arn", arn) | ||
|
||
if err := d.Set("campaign_hook", flattenPinpointCampaignHook(settings.ApplicationSettingsResource.CampaignHook)); err != nil { | ||
return fmt.Errorf("error setting campaign_hook: %s", err) | ||
|
@@ -256,7 +269,13 @@ func resourceAwsPinpointAppRead(d *schema.ResourceData, meta interface{}) error | |
return fmt.Errorf("error setting quiet_time: %s", err) | ||
} | ||
|
||
if err := getTagsPinPointApp(conn, d); err != nil { | ||
tags, err := keyvaluetags.PinpointListTags(conn, arn) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error listing tags for PinPoint Application (%s): %s", arn, err) | ||
} | ||
|
||
if err := d.Set("tags", tags.IgnoreAws().Map()); err != nil { | ||
return fmt.Errorf("error setting tags: %s", err) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to better explain purpose.