Skip to content

Commit

Permalink
resource/aws_globalaccelerator_listener: Address PR #7003 feedback
Browse files Browse the repository at this point in the history
Output from acceptance testing:

```
--- PASS: TestAccAwsGlobalAcceleratorListener_basic (71.30s)
--- PASS: TestAccAwsGlobalAcceleratorListener_update (81.22s)
```
  • Loading branch information
bflad committed Mar 15, 2019
1 parent 890fca8 commit 32d6e68
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 36 deletions.
53 changes: 22 additions & 31 deletions aws/resource_aws_globalaccelerator_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ func resourceAwsGlobalAcceleratorListener() *schema.Resource {
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(5 * time.Minute),
Delete: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"accelerator_arn": {
Type: schema.TypeString,
Expand All @@ -40,7 +34,7 @@ func resourceAwsGlobalAcceleratorListener() *schema.Resource {
"client_affinity": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Default: globalaccelerator.ClientAffinityNone,
ValidateFunc: validation.StringInSlice([]string{
globalaccelerator.ClientAffinityNone,
globalaccelerator.ClientAffinitySourceIp,
Expand All @@ -55,19 +49,21 @@ func resourceAwsGlobalAcceleratorListener() *schema.Resource {
}, false),
},
"port_range": {
Type: schema.TypeList,
Type: schema.TypeSet,
Required: true,
MinItems: 1,
MaxItems: 10,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"from_port": {
Type: schema.TypeInt,
Optional: true,
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 65535),
},
"to_port": {
Type: schema.TypeInt,
Optional: true,
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 65535),
},
},
},
Expand All @@ -81,13 +77,10 @@ func resourceAwsGlobalAcceleratorListenerCreate(d *schema.ResourceData, meta int

opts := &globalaccelerator.CreateListenerInput{
AcceleratorArn: aws.String(d.Get("accelerator_arn").(string)),
ClientAffinity: aws.String(d.Get("client_affinity").(string)),
IdempotencyToken: aws.String(resource.UniqueId()),
Protocol: aws.String(d.Get("protocol").(string)),
PortRanges: resourceAwsGlobalAcceleratorListenerExpandPortRanges(d.Get("port_range").([]interface{})),
}

if v, ok := d.GetOk("client_affinity"); ok {
opts.ClientAffinity = aws.String(v.(string))
PortRanges: resourceAwsGlobalAcceleratorListenerExpandPortRanges(d.Get("port_range").(*schema.Set).List()),
}

log.Printf("[DEBUG] Create Global Accelerator listener: %s", opts)
Expand All @@ -104,7 +97,7 @@ func resourceAwsGlobalAcceleratorListenerCreate(d *schema.ResourceData, meta int
Pending: []string{globalaccelerator.AcceleratorStatusInProgress},
Target: []string{globalaccelerator.AcceleratorStatusDeployed},
Refresh: resourceAwsGlobalAcceleratorAcceleratorStateRefreshFunc(conn, d.Get("accelerator_arn").(string)),
Timeout: d.Timeout(schema.TimeoutCreate),
Timeout: 5 * time.Minute,
}

log.Printf("[DEBUG] Waiting for Global Accelerator listener (%s) availability", d.Id())
Expand Down Expand Up @@ -140,7 +133,9 @@ func resourceAwsGlobalAcceleratorListenerRead(d *schema.ResourceData, meta inter
d.Set("accelerator_arn", acceleratorArn)
d.Set("client_affinity", listener.ClientAffinity)
d.Set("protocol", listener.Protocol)
d.Set("port_range", resourceAwsGlobalAcceleratorListenerFlattenPortRanges(listener.PortRanges))
if err := d.Set("port_range", resourceAwsGlobalAcceleratorListenerFlattenPortRanges(listener.PortRanges)); err != nil {
return fmt.Errorf("error setting port_range: %s", err)
}

return nil
}
Expand Down Expand Up @@ -175,13 +170,12 @@ func resourceAwsGlobalAcceleratorListenerFlattenPortRanges(portRanges []*globala
for i, portRange := range portRanges {
m := make(map[string]interface{})

m["from_port"] = *portRange.FromPort
m["to_port"] = *portRange.ToPort
m["from_port"] = aws.Int64Value(portRange.FromPort)
m["to_port"] = aws.Int64Value(portRange.ToPort)

out[i] = m
}

log.Printf("[DEBUG] Flatten port_range: %s", out)
return out
}

Expand All @@ -204,13 +198,10 @@ func resourceAwsGlobalAcceleratorListenerUpdate(d *schema.ResourceData, meta int
conn := meta.(*AWSClient).globalacceleratorconn

opts := &globalaccelerator.UpdateListenerInput{
ListenerArn: aws.String(d.Id()),
Protocol: aws.String(d.Get("protocol").(string)),
PortRanges: resourceAwsGlobalAcceleratorListenerExpandPortRanges(d.Get("port_range").([]interface{})),
}

if v, ok := d.GetOk("client_affinity"); ok {
opts.ClientAffinity = aws.String(v.(string))
ClientAffinity: aws.String(d.Get("client_affinity").(string)),
ListenerArn: aws.String(d.Id()),
Protocol: aws.String(d.Get("protocol").(string)),
PortRanges: resourceAwsGlobalAcceleratorListenerExpandPortRanges(d.Get("port_range").(*schema.Set).List()),
}

log.Printf("[DEBUG] Update Global Accelerator listener: %s", opts)
Expand All @@ -225,7 +216,7 @@ func resourceAwsGlobalAcceleratorListenerUpdate(d *schema.ResourceData, meta int
Pending: []string{globalaccelerator.AcceleratorStatusInProgress},
Target: []string{globalaccelerator.AcceleratorStatusDeployed},
Refresh: resourceAwsGlobalAcceleratorAcceleratorStateRefreshFunc(conn, d.Get("accelerator_arn").(string)),
Timeout: d.Timeout(schema.TimeoutUpdate),
Timeout: 5 * time.Minute,
}

log.Printf("[DEBUG] Waiting for Global Accelerator listener (%s) availability", d.Id())
Expand Down Expand Up @@ -257,7 +248,7 @@ func resourceAwsGlobalAcceleratorListenerDelete(d *schema.ResourceData, meta int
Pending: []string{globalaccelerator.AcceleratorStatusInProgress},
Target: []string{globalaccelerator.AcceleratorStatusDeployed},
Refresh: resourceAwsGlobalAcceleratorAcceleratorStateRefreshFunc(conn, d.Get("accelerator_arn").(string)),
Timeout: d.Timeout(schema.TimeoutDelete),
Timeout: 5 * time.Minute,
}

log.Printf("[DEBUG] Waiting for Global Accelerator listener (%s) deletion", d.Id())
Expand Down
8 changes: 4 additions & 4 deletions aws/resource_aws_globalaccelerator_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestAccAwsGlobalAcceleratorListener_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "client_affinity", "NONE"),
resource.TestCheckResourceAttr(resourceName, "protocol", "TCP"),
resource.TestCheckResourceAttr(resourceName, "port_range.#", "1"),
resource.TestCheckResourceAttr(resourceName, "port_range.0.from_port", "80"),
resource.TestCheckResourceAttr(resourceName, "port_range.0.to_port", "81"),
resource.TestCheckResourceAttr(resourceName, "port_range.3309144275.from_port", "80"),
resource.TestCheckResourceAttr(resourceName, "port_range.3309144275.to_port", "81"),
),
},
{
Expand Down Expand Up @@ -57,8 +57,8 @@ func TestAccAwsGlobalAcceleratorListener_update(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "client_affinity", "SOURCE_IP"),
resource.TestCheckResourceAttr(resourceName, "protocol", "UDP"),
resource.TestCheckResourceAttr(resourceName, "port_range.#", "1"),
resource.TestCheckResourceAttr(resourceName, "port_range.0.from_port", "443"),
resource.TestCheckResourceAttr(resourceName, "port_range.0.to_port", "444"),
resource.TestCheckResourceAttr(resourceName, "port_range.3922064764.from_port", "443"),
resource.TestCheckResourceAttr(resourceName, "port_range.3922064764.to_port", "444"),
),
},
{
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/globalaccelerator_listener.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ resource "aws_globalaccelerator_listener" "example" {
The following arguments are supported:

* `accelerator_arn` - (Required) The Amazon Resource Name (ARN) of your accelerator.
* `client_affinity` - (Optional) The value for the address type must be `IPV4`. Valid values are `NONE`, `SOURCE_IP`.
* `client_affinity` - (Optional) Direct all requests from a user to the same endpoint. Valid values are `NONE`, `SOURCE_IP`. Default: `NONE`. If `NONE`, Global Accelerator uses the "five-tuple" properties of source IP address, source port, destination IP address, destination port, and protocol to select the hash value. If `SOURCE_IP`, Global Accelerator uses the "two-tuple" properties of source (client) IP address and destination IP address to select the hash value.
* `protocol` - (Optional) The protocol for the connections from clients to the accelerator. Valid values are `TCP`, `UDP`.
* `port_range` - (Optional) The list of port ranges for the connections from clients to the accelerator. Fields documented below.

Expand Down

0 comments on commit 32d6e68

Please sign in to comment.