Merge pull request #8254 from hashicorp/f-aws-application-lb
provider/aws: Initial support for Application Load Balancers
This commit is contained in:
commit
f5f31542bb
|
@ -33,6 +33,7 @@ import (
|
|||
elasticsearch "github.com/aws/aws-sdk-go/service/elasticsearchservice"
|
||||
"github.com/aws/aws-sdk-go/service/elastictranscoder"
|
||||
"github.com/aws/aws-sdk-go/service/elb"
|
||||
"github.com/aws/aws-sdk-go/service/elbv2"
|
||||
"github.com/aws/aws-sdk-go/service/emr"
|
||||
"github.com/aws/aws-sdk-go/service/firehose"
|
||||
"github.com/aws/aws-sdk-go/service/glacier"
|
||||
|
@ -97,6 +98,7 @@ type AWSClient struct {
|
|||
ecsconn *ecs.ECS
|
||||
efsconn *efs.EFS
|
||||
elbconn *elb.ELB
|
||||
elbv2conn *elbv2.ELBV2
|
||||
emrconn *emr.EMR
|
||||
esconn *elasticsearch.ElasticsearchService
|
||||
apigateway *apigateway.APIGateway
|
||||
|
@ -250,6 +252,7 @@ func (c *Config) Client() (interface{}, error) {
|
|||
client.elasticbeanstalkconn = elasticbeanstalk.New(sess)
|
||||
client.elastictranscoderconn = elastictranscoder.New(sess)
|
||||
client.elbconn = elb.New(awsElbSess)
|
||||
client.elbv2conn = elbv2.New(awsElbSess)
|
||||
client.emrconn = emr.New(sess)
|
||||
client.esconn = elasticsearch.New(sess)
|
||||
client.firehoseconn = firehose.New(sess)
|
||||
|
|
|
@ -152,6 +152,8 @@ func Provider() terraform.ResourceProvider {
|
|||
},
|
||||
|
||||
ResourcesMap: map[string]*schema.Resource{
|
||||
"aws_alb": resourceAwsAlb(),
|
||||
"aws_alb_target_group": resourceAwsAlbTargetGroup(),
|
||||
"aws_ami": resourceAwsAmi(),
|
||||
"aws_ami_copy": resourceAwsAmiCopy(),
|
||||
"aws_ami_from_instance": resourceAwsAmiFromInstance(),
|
||||
|
|
|
@ -0,0 +1,337 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/elbv2"
|
||||
"github.com/hashicorp/errwrap"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
func resourceAwsAlb() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceAwsAlbCreate,
|
||||
Read: resourceAwsAlbRead,
|
||||
Update: resourceAwsAlbUpdate,
|
||||
Delete: resourceAwsAlbDelete,
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
ValidateFunc: validateElbName,
|
||||
},
|
||||
|
||||
"internal": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"security_groups": {
|
||||
Type: schema.TypeSet,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
ForceNew: true,
|
||||
Optional: true,
|
||||
Set: schema.HashString,
|
||||
},
|
||||
|
||||
"subnets": {
|
||||
Type: schema.TypeSet,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
ForceNew: true,
|
||||
Required: true,
|
||||
Set: schema.HashString,
|
||||
},
|
||||
|
||||
"access_logs": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"bucket": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"prefix": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
"enable_deletion_protection": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
},
|
||||
|
||||
"idle_timeout": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Default: 60,
|
||||
},
|
||||
|
||||
"vpc_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"zone_id": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"dns_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"tags": tagsSchema(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceAwsAlbCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
elbconn := meta.(*AWSClient).elbv2conn
|
||||
|
||||
elbOpts := &elbv2.CreateLoadBalancerInput{
|
||||
Name: aws.String(d.Get("name").(string)),
|
||||
Tags: tagsFromMapELBv2(d.Get("tags").(map[string]interface{})),
|
||||
}
|
||||
|
||||
if scheme, ok := d.GetOk("internal"); ok && scheme.(bool) {
|
||||
elbOpts.Scheme = aws.String("internal")
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("security_groups"); ok {
|
||||
elbOpts.SecurityGroups = expandStringList(v.(*schema.Set).List())
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("subnets"); ok {
|
||||
elbOpts.Subnets = expandStringList(v.(*schema.Set).List())
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] ALB create configuration: %#v", elbOpts)
|
||||
|
||||
resp, err := elbconn.CreateLoadBalancer(elbOpts)
|
||||
if err != nil {
|
||||
return errwrap.Wrapf("Error creating Application Load Balancer: {{err}}", err)
|
||||
}
|
||||
|
||||
if len(resp.LoadBalancers) != 1 {
|
||||
return fmt.Errorf("No load balancers returned following creation of %s", d.Get("name").(string))
|
||||
}
|
||||
|
||||
d.SetId(*resp.LoadBalancers[0].LoadBalancerArn)
|
||||
log.Printf("[INFO] ALB ID: %s", d.Id())
|
||||
|
||||
return resourceAwsAlbUpdate(d, meta)
|
||||
}
|
||||
|
||||
func resourceAwsAlbRead(d *schema.ResourceData, meta interface{}) error {
|
||||
elbconn := meta.(*AWSClient).elbv2conn
|
||||
albArn := d.Id()
|
||||
|
||||
describeAlbOpts := &elbv2.DescribeLoadBalancersInput{
|
||||
LoadBalancerArns: []*string{aws.String(albArn)},
|
||||
}
|
||||
|
||||
describeResp, err := elbconn.DescribeLoadBalancers(describeAlbOpts)
|
||||
if err != nil {
|
||||
if isLoadBalancerNotFound(err) {
|
||||
// The ALB is gone now, so just remove it from the state
|
||||
log.Printf("[WARN] ALB %s not found in AWS, removing from state", d.Id())
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
|
||||
return errwrap.Wrapf("Error retrieving ALB: {{err}}", err)
|
||||
}
|
||||
if len(describeResp.LoadBalancers) != 1 {
|
||||
return fmt.Errorf("Unable to find ALB: %#v", describeResp.LoadBalancers)
|
||||
}
|
||||
|
||||
alb := describeResp.LoadBalancers[0]
|
||||
|
||||
d.Set("name", alb.LoadBalancerName)
|
||||
d.Set("internal", (alb.Scheme != nil && *alb.Scheme == "internal"))
|
||||
d.Set("security_groups", flattenStringList(alb.SecurityGroups))
|
||||
d.Set("subnets", flattenSubnetsFromAvailabilityZones(alb.AvailabilityZones))
|
||||
d.Set("vpc_id", alb.VpcId)
|
||||
d.Set("zone_id", alb.CanonicalHostedZoneId)
|
||||
d.Set("dns_name", alb.DNSName)
|
||||
|
||||
respTags, err := elbconn.DescribeTags(&elbv2.DescribeTagsInput{
|
||||
ResourceArns: []*string{alb.LoadBalancerArn},
|
||||
})
|
||||
if err != nil {
|
||||
return errwrap.Wrapf("Error retrieving ALB Tags: {{err}}", err)
|
||||
}
|
||||
|
||||
var et []*elbv2.Tag
|
||||
if len(respTags.TagDescriptions) > 0 {
|
||||
et = respTags.TagDescriptions[0].Tags
|
||||
}
|
||||
d.Set("tags", tagsToMapELBv2(et))
|
||||
|
||||
attributesResp, err := elbconn.DescribeLoadBalancerAttributes(&elbv2.DescribeLoadBalancerAttributesInput{
|
||||
LoadBalancerArn: aws.String(d.Id()),
|
||||
})
|
||||
if err != nil {
|
||||
return errwrap.Wrapf("Error retrieving ALB Attributes: {{err}}", err)
|
||||
}
|
||||
|
||||
accessLogMap := map[string]interface{}{}
|
||||
for _, attr := range attributesResp.Attributes {
|
||||
switch *attr.Key {
|
||||
case "access_logs.s3.bucket":
|
||||
accessLogMap["bucket"] = *attr.Value
|
||||
case "access_logs.s3.prefix":
|
||||
accessLogMap["prefix"] = *attr.Value
|
||||
case "idle_timeout.timeout_seconds":
|
||||
timeout, err := strconv.Atoi(*attr.Value)
|
||||
if err != nil {
|
||||
return errwrap.Wrapf("Error parsing ALB timeout: {{err}}", err)
|
||||
}
|
||||
log.Printf("[DEBUG] Setting ALB Timeout Seconds: %d", timeout)
|
||||
d.Set("idle_timeout", timeout)
|
||||
case "deletion_protection.enabled":
|
||||
protectionEnabled := (*attr.Value) == "true"
|
||||
log.Printf("[DEBUG] Setting ALB Deletion Protection Enabled: %t", protectionEnabled)
|
||||
d.Set("enable_deletion_protection", protectionEnabled)
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Setting ALB Access Logs: %#v", accessLogMap)
|
||||
if accessLogMap["bucket"] != "" || accessLogMap["prefix"] != "" {
|
||||
d.Set("access_logs", []interface{}{accessLogMap})
|
||||
} else {
|
||||
d.Set("access_logs", []interface{}{})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceAwsAlbUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
elbconn := meta.(*AWSClient).elbv2conn
|
||||
|
||||
attributes := make([]*elbv2.LoadBalancerAttribute, 0)
|
||||
|
||||
if d.HasChange("access_logs") {
|
||||
logs := d.Get("access_logs").([]interface{})
|
||||
if len(logs) == 1 {
|
||||
log := logs[0].(map[string]interface{})
|
||||
|
||||
attributes = append(attributes,
|
||||
&elbv2.LoadBalancerAttribute{
|
||||
Key: aws.String("access_logs.s3.enabled"),
|
||||
Value: aws.String("true"),
|
||||
},
|
||||
&elbv2.LoadBalancerAttribute{
|
||||
Key: aws.String("access_logs.s3.bucket"),
|
||||
Value: aws.String(log["bucket"].(string)),
|
||||
})
|
||||
|
||||
if prefix, ok := log["prefix"]; ok {
|
||||
attributes = append(attributes, &elbv2.LoadBalancerAttribute{
|
||||
Key: aws.String("access_logs.s3.prefix"),
|
||||
Value: aws.String(prefix.(string)),
|
||||
})
|
||||
}
|
||||
} else if len(logs) == 0 {
|
||||
attributes = append(attributes, &elbv2.LoadBalancerAttribute{
|
||||
Key: aws.String("access_logs.s3.enabled"),
|
||||
Value: aws.String("false"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if d.HasChange("enable_deletion_protection") {
|
||||
attributes = append(attributes, &elbv2.LoadBalancerAttribute{
|
||||
Key: aws.String("deletion_protection.enabled"),
|
||||
Value: aws.String(fmt.Sprintf("%t", d.Get("enable_deletion_protection").(bool))),
|
||||
})
|
||||
}
|
||||
|
||||
if d.HasChange("idle_timeout") {
|
||||
attributes = append(attributes, &elbv2.LoadBalancerAttribute{
|
||||
Key: aws.String("idle_timeout.timeout_seconds"),
|
||||
Value: aws.String(fmt.Sprintf("%d", d.Get("idle_timeout").(int))),
|
||||
})
|
||||
}
|
||||
|
||||
if len(attributes) != 0 {
|
||||
input := &elbv2.ModifyLoadBalancerAttributesInput{
|
||||
LoadBalancerArn: aws.String(d.Id()),
|
||||
Attributes: attributes,
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] ALB Modify Load Balancer Attributes Request: %#v", input)
|
||||
_, err := elbconn.ModifyLoadBalancerAttributes(input)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failure configuring ALB attributes: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
return resourceAwsAlbRead(d, meta)
|
||||
}
|
||||
|
||||
func resourceAwsAlbDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
albconn := meta.(*AWSClient).elbv2conn
|
||||
|
||||
log.Printf("[INFO] Deleting ALB: %s", d.Id())
|
||||
|
||||
// Destroy the load balancer
|
||||
deleteElbOpts := elbv2.DeleteLoadBalancerInput{
|
||||
LoadBalancerArn: aws.String(d.Id()),
|
||||
}
|
||||
if _, err := albconn.DeleteLoadBalancer(&deleteElbOpts); err != nil {
|
||||
return fmt.Errorf("Error deleting ALB: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// tagsToMapELBv2 turns the list of tags into a map.
|
||||
func tagsToMapELBv2(ts []*elbv2.Tag) map[string]string {
|
||||
result := make(map[string]string)
|
||||
for _, t := range ts {
|
||||
result[*t.Key] = *t.Value
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// tagsFromMapELBv2 returns the tags for the given map of data.
|
||||
func tagsFromMapELBv2(m map[string]interface{}) []*elbv2.Tag {
|
||||
var result []*elbv2.Tag
|
||||
for k, v := range m {
|
||||
result = append(result, &elbv2.Tag{
|
||||
Key: aws.String(k),
|
||||
Value: aws.String(v.(string)),
|
||||
})
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// flattenSubnetsFromAvailabilityZones creates a slice of strings containing the subnet IDs
|
||||
// for the ALB based on the AvailabilityZones structure returned by the API.
|
||||
func flattenSubnetsFromAvailabilityZones(availabilityZones []*elbv2.AvailabilityZone) []string {
|
||||
var result []string
|
||||
for _, az := range availabilityZones {
|
||||
result = append(result, *az.SubnetId)
|
||||
}
|
||||
return result
|
||||
}
|
|
@ -0,0 +1,449 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/elbv2"
|
||||
"github.com/hashicorp/errwrap"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
func resourceAwsAlbTargetGroup() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceAwsAlbTargetGroupCreate,
|
||||
Read: resourceAwsAlbTargetGroupRead,
|
||||
Update: resourceAwsAlbTargetGroupUpdate,
|
||||
Delete: resourceAwsAlbTargetGroupDelete,
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"port": {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ValidateFunc: validateAwsAlbTargetGroupPort,
|
||||
},
|
||||
|
||||
"protocol": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validateAwsAlbTargetGroupProtocol,
|
||||
},
|
||||
|
||||
"vpc_id": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"deregistration_delay": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Default: 300,
|
||||
ValidateFunc: validateAwsAlbTargetGroupDeregistrationDelay,
|
||||
},
|
||||
|
||||
"stickiness": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"type": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ValidateFunc: validateAwsAlbTargetGroupStickinessType,
|
||||
},
|
||||
"cookie_duration": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Default: 86400,
|
||||
ValidateFunc: validateAwsAlbTargetGroupStickinessCookieDuration,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
"health_check": {
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"interval": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Default: 30,
|
||||
},
|
||||
|
||||
"path": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Default: "/",
|
||||
ValidateFunc: validateAwsAlbTargetGroupHealthCheckPath,
|
||||
},
|
||||
|
||||
"port": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Default: "traffic-port",
|
||||
ValidateFunc: validateAwsAlbTargetGroupHealthCheckPort,
|
||||
},
|
||||
|
||||
"protocol": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Default: "HTTP",
|
||||
StateFunc: func(v interface{}) string {
|
||||
return strings.ToUpper(v.(string))
|
||||
},
|
||||
ValidateFunc: validateAwsAlbTargetGroupHealthCheckProtocol,
|
||||
},
|
||||
|
||||
"timeout": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Default: 5,
|
||||
ValidateFunc: validateAwsAlbTargetGroupHealthCheckTimeout,
|
||||
},
|
||||
|
||||
"healthy_threshold": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Default: 5,
|
||||
ValidateFunc: validateAwsAlbTargetGroupHealthCheckHealthyThreshold,
|
||||
},
|
||||
|
||||
"matcher": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Default: "200",
|
||||
},
|
||||
|
||||
"unhealthy_threshold": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Default: 2,
|
||||
ValidateFunc: validateAwsAlbTargetGroupHealthCheckHealthyThreshold,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceAwsAlbTargetGroupCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
elbconn := meta.(*AWSClient).elbv2conn
|
||||
|
||||
params := &elbv2.CreateTargetGroupInput{
|
||||
Name: aws.String(d.Get("name").(string)),
|
||||
Port: aws.Int64(int64(d.Get("port").(int))),
|
||||
Protocol: aws.String(d.Get("protocol").(string)),
|
||||
VpcId: aws.String(d.Get("vpc_id").(string)),
|
||||
}
|
||||
|
||||
if healthChecks := d.Get("health_check").([]interface{}); len(healthChecks) == 1 {
|
||||
healthCheck := healthChecks[0].(map[string]interface{})
|
||||
|
||||
params.HealthCheckIntervalSeconds = aws.Int64(int64(healthCheck["interval"].(int)))
|
||||
params.HealthCheckPath = aws.String(healthCheck["path"].(string))
|
||||
params.HealthCheckPort = aws.String(healthCheck["port"].(string))
|
||||
params.HealthCheckProtocol = aws.String(healthCheck["protocol"].(string))
|
||||
params.HealthCheckTimeoutSeconds = aws.Int64(int64(healthCheck["timeout"].(int)))
|
||||
params.HealthyThresholdCount = aws.Int64(int64(healthCheck["healthy_threshold"].(int)))
|
||||
params.UnhealthyThresholdCount = aws.Int64(int64(healthCheck["unhealthy_threshold"].(int)))
|
||||
params.Matcher = &elbv2.Matcher{
|
||||
HttpCode: aws.String(healthCheck["matcher"].(string)),
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := elbconn.CreateTargetGroup(params)
|
||||
if err != nil {
|
||||
return errwrap.Wrapf("Error creating ALB Target Group: {{err}}", err)
|
||||
}
|
||||
|
||||
if len(resp.TargetGroups) == 0 {
|
||||
return errors.New("Error creating ALB Target Group: no groups returned in response")
|
||||
}
|
||||
|
||||
targetGroupArn := resp.TargetGroups[0].TargetGroupArn
|
||||
d.SetId(*targetGroupArn)
|
||||
|
||||
return resourceAwsAlbTargetGroupUpdate(d, meta)
|
||||
}
|
||||
|
||||
func resourceAwsAlbTargetGroupRead(d *schema.ResourceData, meta interface{}) error {
|
||||
elbconn := meta.(*AWSClient).elbv2conn
|
||||
|
||||
resp, err := elbconn.DescribeTargetGroups(&elbv2.DescribeTargetGroupsInput{
|
||||
TargetGroupArns: []*string{aws.String(d.Id())},
|
||||
})
|
||||
if err != nil {
|
||||
if isTargetGroupNotFound(err) {
|
||||
log.Printf("[DEBUG] DescribeTargetGroups - removing %s from state", d.Id())
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
return errwrap.Wrapf("Error retrieving Target Group: {{err}}", err)
|
||||
}
|
||||
|
||||
if len(resp.TargetGroups) != 1 {
|
||||
return fmt.Errorf("Error retrieving Target Group %q", d.Id())
|
||||
}
|
||||
|
||||
targetGroup := resp.TargetGroups[0]
|
||||
|
||||
d.Set("name", targetGroup.TargetGroupName)
|
||||
d.Set("port", targetGroup.Port)
|
||||
d.Set("protocol", targetGroup.Protocol)
|
||||
d.Set("vpc_id", targetGroup.VpcId)
|
||||
|
||||
healthCheck := make(map[string]interface{})
|
||||
healthCheck["interval"] = *targetGroup.HealthCheckIntervalSeconds
|
||||
healthCheck["path"] = *targetGroup.HealthCheckPath
|
||||
healthCheck["port"] = *targetGroup.HealthCheckPort
|
||||
healthCheck["protocol"] = *targetGroup.HealthCheckProtocol
|
||||
healthCheck["timeout"] = *targetGroup.HealthCheckTimeoutSeconds
|
||||
healthCheck["healthy_threshold"] = *targetGroup.HealthyThresholdCount
|
||||
healthCheck["unhealthy_threshold"] = *targetGroup.UnhealthyThresholdCount
|
||||
healthCheck["matcher"] = *targetGroup.Matcher.HttpCode
|
||||
d.Set("health_check", []interface{}{healthCheck})
|
||||
|
||||
attrResp, err := elbconn.DescribeTargetGroupAttributes(&elbv2.DescribeTargetGroupAttributesInput{
|
||||
TargetGroupArn: aws.String(d.Id()),
|
||||
})
|
||||
if err != nil {
|
||||
return errwrap.Wrapf("Error retrieving Target Group Attributes: {{err}}", err)
|
||||
}
|
||||
|
||||
stickinessMap := map[string]interface{}{}
|
||||
for _, attr := range attrResp.Attributes {
|
||||
switch *attr.Key {
|
||||
case "stickiness.type":
|
||||
stickinessMap["type"] = *attr.Value
|
||||
case "stickiness.lb_cookie.duration_seconds":
|
||||
stickinessMap["cookie_duration"] = *attr.Value
|
||||
case "deregistration_delay.timeout_seconds":
|
||||
timeout, err := strconv.Atoi(*attr.Value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error converting deregistration_delay.timeout_seconds to int: %s", *attr.Value)
|
||||
}
|
||||
d.Set("deregistration_delay", timeout)
|
||||
}
|
||||
}
|
||||
d.Set("stickiness", []interface{}{stickinessMap})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceAwsAlbTargetGroupUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
elbconn := meta.(*AWSClient).elbv2conn
|
||||
|
||||
if d.HasChange("health_check") {
|
||||
healthChecks := d.Get("health_check").([]interface{})
|
||||
|
||||
var params *elbv2.ModifyTargetGroupInput
|
||||
if len(healthChecks) == 1 {
|
||||
healthCheck := healthChecks[0].(map[string]interface{})
|
||||
|
||||
params = &elbv2.ModifyTargetGroupInput{
|
||||
TargetGroupArn: aws.String(d.Id()),
|
||||
HealthCheckIntervalSeconds: aws.Int64(int64(healthCheck["interval"].(int))),
|
||||
HealthCheckPath: aws.String(healthCheck["path"].(string)),
|
||||
HealthCheckPort: aws.String(healthCheck["port"].(string)),
|
||||
HealthCheckProtocol: aws.String(healthCheck["protocol"].(string)),
|
||||
HealthCheckTimeoutSeconds: aws.Int64(int64(healthCheck["timeout"].(int))),
|
||||
HealthyThresholdCount: aws.Int64(int64(healthCheck["healthy_threshold"].(int))),
|
||||
UnhealthyThresholdCount: aws.Int64(int64(healthCheck["unhealthy_threshold"].(int))),
|
||||
Matcher: &elbv2.Matcher{
|
||||
HttpCode: aws.String(healthCheck["matcher"].(string)),
|
||||
},
|
||||
}
|
||||
} else {
|
||||
params = &elbv2.ModifyTargetGroupInput{
|
||||
TargetGroupArn: aws.String(d.Id()),
|
||||
}
|
||||
}
|
||||
|
||||
_, err := elbconn.ModifyTargetGroup(params)
|
||||
if err != nil {
|
||||
return errwrap.Wrapf("Error modifying Target Group: {{err}}", err)
|
||||
}
|
||||
}
|
||||
|
||||
var attrs []*elbv2.TargetGroupAttribute
|
||||
|
||||
if d.HasChange("deregistration_delay") {
|
||||
attrs = append(attrs, &elbv2.TargetGroupAttribute{
|
||||
Key: aws.String("deregistration_delay.timeout_seconds"),
|
||||
Value: aws.String(fmt.Sprintf("%d", d.Get("deregistration_delay").(int))),
|
||||
})
|
||||
}
|
||||
|
||||
if d.HasChange("stickiness") {
|
||||
stickinessBlocks := d.Get("stickiness").([]interface{})
|
||||
if len(stickinessBlocks) == 1 {
|
||||
stickiness := stickinessBlocks[0].(map[string]interface{})
|
||||
|
||||
attrs = append(attrs,
|
||||
&elbv2.TargetGroupAttribute{
|
||||
Key: aws.String("stickiness.enabled"),
|
||||
Value: aws.String("true"),
|
||||
},
|
||||
&elbv2.TargetGroupAttribute{
|
||||
Key: aws.String("stickiness.type"),
|
||||
Value: aws.String(stickiness["type"].(string)),
|
||||
},
|
||||
&elbv2.TargetGroupAttribute{
|
||||
Key: aws.String("stickiness.lb_cookie.duration_seconds"),
|
||||
Value: aws.String(fmt.Sprintf("%d", stickiness["cookie_duration"].(int))),
|
||||
})
|
||||
} else if len(stickinessBlocks) == 0 {
|
||||
attrs = append(attrs, &elbv2.TargetGroupAttribute{
|
||||
Key: aws.String("stickiness.enabled"),
|
||||
Value: aws.String("false"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if len(attrs) > 0 {
|
||||
params := &elbv2.ModifyTargetGroupAttributesInput{
|
||||
TargetGroupArn: aws.String(d.Id()),
|
||||
Attributes: attrs,
|
||||
}
|
||||
|
||||
_, err := elbconn.ModifyTargetGroupAttributes(params)
|
||||
if err != nil {
|
||||
return errwrap.Wrapf("Error modifying Target Group Attributes: {{err}}", err)
|
||||
}
|
||||
}
|
||||
|
||||
return resourceAwsAlbTargetGroupRead(d, meta)
|
||||
}
|
||||
|
||||
func resourceAwsAlbTargetGroupDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
elbconn := meta.(*AWSClient).elbv2conn
|
||||
|
||||
_, err := elbconn.DeleteTargetGroup(&elbv2.DeleteTargetGroupInput{
|
||||
TargetGroupArn: aws.String(d.Id()),
|
||||
})
|
||||
if err != nil {
|
||||
return errwrap.Wrapf("Error deleting Target Group: {{err}}", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func isTargetGroupNotFound(err error) bool {
|
||||
elberr, ok := err.(awserr.Error)
|
||||
return ok && elberr.Code() == "TargetGroupNotFound"
|
||||
}
|
||||
|
||||
func validateAwsAlbTargetGroupHealthCheckPath(v interface{}, k string) (ws []string, errors []error) {
|
||||
value := v.(string)
|
||||
if len(value) > 1024 {
|
||||
errors = append(errors, fmt.Errorf(
|
||||
"%q cannot be longer than 1024 characters: %q", k, value))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func validateAwsAlbTargetGroupHealthCheckPort(v interface{}, k string) (ws []string, errors []error) {
|
||||
value := v.(string)
|
||||
|
||||
if value == "traffic-port" {
|
||||
return
|
||||
}
|
||||
|
||||
port, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
errors = append(errors, fmt.Errorf("%q must be a valid port number (1-65536) or %q", k, "traffic-port"))
|
||||
}
|
||||
|
||||
if port < 1 || port > 65536 {
|
||||
errors = append(errors, fmt.Errorf("%q must be a valid port number (1-65536) or %q", k, "traffic-port"))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func validateAwsAlbTargetGroupHealthCheckHealthyThreshold(v interface{}, k string) (ws []string, errors []error) {
|
||||
value := v.(int)
|
||||
if value < 2 || value > 10 {
|
||||
errors = append(errors, fmt.Errorf("%q must be an integer between 2 and 10", k))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func validateAwsAlbTargetGroupHealthCheckTimeout(v interface{}, k string) (ws []string, errors []error) {
|
||||
value := v.(int)
|
||||
if value < 2 || value > 60 {
|
||||
errors = append(errors, fmt.Errorf("%q must be an integer between 2 and 60", k))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func validateAwsAlbTargetGroupHealthCheckProtocol(v interface{}, k string) (ws []string, errors []error) {
|
||||
value := strings.ToLower(v.(string))
|
||||
if value == "http" || value == "https" {
|
||||
return
|
||||
}
|
||||
|
||||
errors = append(errors, fmt.Errorf("%q must be either %q or %q", k, "HTTP", "HTTPS"))
|
||||
return
|
||||
}
|
||||
|
||||
func validateAwsAlbTargetGroupPort(v interface{}, k string) (ws []string, errors []error) {
|
||||
port := v.(int)
|
||||
if port < 1 || port > 65536 {
|
||||
errors = append(errors, fmt.Errorf("%q must be a valid port number (1-65536)", k))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func validateAwsAlbTargetGroupProtocol(v interface{}, k string) (ws []string, errors []error) {
|
||||
protocol := strings.ToLower(v.(string))
|
||||
if protocol == "http" || protocol == "https" {
|
||||
return
|
||||
}
|
||||
|
||||
errors = append(errors, fmt.Errorf("%q must be either %q or %q", k, "HTTP", "HTTPS"))
|
||||
return
|
||||
}
|
||||
|
||||
func validateAwsAlbTargetGroupDeregistrationDelay(v interface{}, k string) (ws []string, errors []error) {
|
||||
delay := v.(int)
|
||||
if delay < 0 || delay > 3600 {
|
||||
errors = append(errors, fmt.Errorf("%q must be in the range 0-3600 seconds", k))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func validateAwsAlbTargetGroupStickinessType(v interface{}, k string) (ws []string, errors []error) {
|
||||
stickinessType := v.(string)
|
||||
if stickinessType != "lb_cookie" {
|
||||
errors = append(errors, fmt.Errorf("%q must have the value %q", k, "lb_cookie"))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func validateAwsAlbTargetGroupStickinessCookieDuration(v interface{}, k string) (ws []string, errors []error) {
|
||||
duration := v.(int)
|
||||
if duration < 1 || duration > 604800 {
|
||||
errors = append(errors, fmt.Errorf("%q must be a between 1 second and 1 week (1-604800 seconds))", k))
|
||||
}
|
||||
return
|
||||
}
|
|
@ -0,0 +1,242 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/elbv2"
|
||||
"github.com/hashicorp/errwrap"
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestAccAWSALBTargetGroup_basic(t *testing.T) {
|
||||
var conf elbv2.TargetGroup
|
||||
targetGroupName := fmt.Sprintf("test-target-group-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
IDRefreshName: "aws_alb_target_group.test",
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckAWSALBTargetGroupDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccAWSALBTargetGroupConfig_basic(targetGroupName),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &conf),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "name", targetGroupName),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "port", "443"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "protocol", "HTTPS"),
|
||||
resource.TestCheckResourceAttrSet("aws_alb_target_group.test", "vpc_id"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "deregistration_delay", "200"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "stickiness.#", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "stickiness.0.type", "lb_cookie"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "stickiness.0.cookie_duration", "10000"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.#", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.path", "/health"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.interval", "60"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.port", "8081"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.protocol", "HTTP"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.timeout", "3"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.healthy_threshold", "3"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.unhealthy_threshold", "3"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.matcher", "200-299"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAWSALBTargetGroup_updateHealthCheck(t *testing.T) {
|
||||
var conf elbv2.TargetGroup
|
||||
targetGroupName := fmt.Sprintf("test-target-group-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
IDRefreshName: "aws_alb_target_group.test",
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckAWSALBTargetGroupDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccAWSALBTargetGroupConfig_basic(targetGroupName),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &conf),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "name", targetGroupName),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "port", "443"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "protocol", "HTTPS"),
|
||||
resource.TestCheckResourceAttrSet("aws_alb_target_group.test", "vpc_id"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "deregistration_delay", "200"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "stickiness.#", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "stickiness.0.type", "lb_cookie"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "stickiness.0.cookie_duration", "10000"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.#", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.path", "/health"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.interval", "60"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.port", "8081"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.protocol", "HTTP"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.timeout", "3"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.healthy_threshold", "3"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.unhealthy_threshold", "3"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.matcher", "200-299"),
|
||||
),
|
||||
},
|
||||
{
|
||||
Config: testAccAWSALBTargetGroupConfig_updateHealthCheck(targetGroupName),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &conf),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "name", targetGroupName),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "port", "443"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "protocol", "HTTPS"),
|
||||
resource.TestCheckResourceAttrSet("aws_alb_target_group.test", "vpc_id"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "deregistration_delay", "200"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "stickiness.#", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "stickiness.0.type", "lb_cookie"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "stickiness.0.cookie_duration", "10000"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.#", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.path", "/health2"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.interval", "30"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.port", "8082"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.protocol", "HTTPS"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.timeout", "4"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.healthy_threshold", "4"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.unhealthy_threshold", "4"),
|
||||
resource.TestCheckResourceAttr("aws_alb_target_group.test", "health_check.0.matcher", "200"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckAWSALBTargetGroupExists(n string, res *elbv2.TargetGroup) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.RootModule().Resources[n]
|
||||
if !ok {
|
||||
return fmt.Errorf("Not found: %s", n)
|
||||
}
|
||||
|
||||
if rs.Primary.ID == "" {
|
||||
return errors.New("No Target Group ID is set")
|
||||
}
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).elbv2conn
|
||||
|
||||
describe, err := conn.DescribeTargetGroups(&elbv2.DescribeTargetGroupsInput{
|
||||
TargetGroupArns: []*string{aws.String(rs.Primary.ID)},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(describe.TargetGroups) != 1 ||
|
||||
*describe.TargetGroups[0].TargetGroupArn != rs.Primary.ID {
|
||||
return errors.New("Target Group not found")
|
||||
}
|
||||
|
||||
*res = *describe.TargetGroups[0]
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testAccCheckAWSALBTargetGroupDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).elbv2conn
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_alb_target_group" {
|
||||
continue
|
||||
}
|
||||
|
||||
describe, err := conn.DescribeTargetGroups(&elbv2.DescribeTargetGroupsInput{
|
||||
TargetGroupArns: []*string{aws.String(rs.Primary.ID)},
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
if len(describe.TargetGroups) != 0 &&
|
||||
*describe.TargetGroups[0].TargetGroupArn == rs.Primary.ID {
|
||||
return fmt.Errorf("Target Group %q still exists", rs.Primary.ID)
|
||||
}
|
||||
}
|
||||
|
||||
// Verify the error
|
||||
if isTargetGroupNotFound(err) {
|
||||
return nil
|
||||
} else {
|
||||
return errwrap.Wrapf("Unexpected error checking ALB destroyed: {{err}}", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func testAccAWSALBTargetGroupConfig_basic(targetGroupName string) string {
|
||||
return fmt.Sprintf(`resource "aws_alb_target_group" "test" {
|
||||
name = "%s"
|
||||
port = 443
|
||||
protocol = "HTTPS"
|
||||
vpc_id = "${aws_vpc.test.id}"
|
||||
|
||||
deregistration_delay = 200
|
||||
|
||||
stickiness {
|
||||
type = "lb_cookie"
|
||||
cookie_duration = 10000
|
||||
}
|
||||
|
||||
health_check {
|
||||
path = "/health"
|
||||
interval = 60
|
||||
port = 8081
|
||||
protocol = "HTTP"
|
||||
timeout = 3
|
||||
healthy_threshold = 3
|
||||
unhealthy_threshold = 3
|
||||
matcher = "200-299"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_vpc" "test" {
|
||||
cidr_block = "10.0.0.0/16"
|
||||
|
||||
tags {
|
||||
TestName = "TestAccAWSALBTargetGroup_basic"
|
||||
}
|
||||
}`, targetGroupName)
|
||||
}
|
||||
|
||||
func testAccAWSALBTargetGroupConfig_updateHealthCheck(targetGroupName string) string {
|
||||
return fmt.Sprintf(`resource "aws_alb_target_group" "test" {
|
||||
name = "%s"
|
||||
port = 443
|
||||
protocol = "HTTPS"
|
||||
vpc_id = "${aws_vpc.test.id}"
|
||||
|
||||
deregistration_delay = 200
|
||||
|
||||
stickiness {
|
||||
type = "lb_cookie"
|
||||
cookie_duration = 10000
|
||||
}
|
||||
|
||||
health_check {
|
||||
path = "/health2"
|
||||
interval = 30
|
||||
port = 8082
|
||||
protocol = "HTTPS"
|
||||
timeout = 4
|
||||
healthy_threshold = 4
|
||||
unhealthy_threshold = 4
|
||||
matcher = "200"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_vpc" "test" {
|
||||
cidr_block = "10.0.0.0/16"
|
||||
|
||||
tags {
|
||||
TestName = "TestAccAWSALBTargetGroup_basic"
|
||||
}
|
||||
}`, targetGroupName)
|
||||
}
|
|
@ -0,0 +1,336 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/elbv2"
|
||||
"github.com/hashicorp/errwrap"
|
||||
"github.com/hashicorp/terraform/helper/acctest"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestAccAWSALB_basic(t *testing.T) {
|
||||
var conf elbv2.LoadBalancer
|
||||
albName := fmt.Sprintf("testaccawsalb-basic-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
IDRefreshName: "aws_alb.alb_test",
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckAWSALBDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccAWSALBConfig_basic(albName),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
testAccCheckAWSALBExists("aws_alb.alb_test", &conf),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "name", albName),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "internal", "false"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "subnets.#", "2"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "security_groups.#", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.%", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.TestName", "TestAccAWSALB_basic"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "enable_deletion_protection", "false"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "idle_timeout", "30"),
|
||||
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "vpc_id"),
|
||||
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "zone_id"),
|
||||
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "dns_name"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAWSALB_accesslogs(t *testing.T) {
|
||||
var conf elbv2.LoadBalancer
|
||||
bucketName := fmt.Sprintf("testaccawsalbaccesslogs-%s", acctest.RandStringFromCharSet(6, acctest.CharSetAlphaNum))
|
||||
albName := fmt.Sprintf("testaccawsalbaccesslog-%s", acctest.RandStringFromCharSet(4, acctest.CharSetAlpha))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
IDRefreshName: "aws_alb.alb_test",
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckAWSALBDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccAWSALBConfig_basic(albName),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
testAccCheckAWSALBExists("aws_alb.alb_test", &conf),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "name", albName),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "internal", "false"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "subnets.#", "2"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "security_groups.#", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.%", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.TestName", "TestAccAWSALB_basic"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "enable_deletion_protection", "false"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "idle_timeout", "30"),
|
||||
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "vpc_id"),
|
||||
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "zone_id"),
|
||||
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "dns_name"),
|
||||
),
|
||||
},
|
||||
|
||||
{
|
||||
Config: testAccAWSALBConfig_accessLogs(albName, bucketName),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
testAccCheckAWSALBExists("aws_alb.alb_test", &conf),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "name", albName),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "internal", "false"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "subnets.#", "2"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "security_groups.#", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.%", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.TestName", "TestAccAWSALB_basic"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "enable_deletion_protection", "false"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "idle_timeout", "50"),
|
||||
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "vpc_id"),
|
||||
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "zone_id"),
|
||||
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "dns_name"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.#", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.0.bucket", bucketName),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.0.prefix", "testAccAWSALBConfig_accessLogs"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckAWSALBExists(n string, res *elbv2.LoadBalancer) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.RootModule().Resources[n]
|
||||
if !ok {
|
||||
return fmt.Errorf("Not found: %s", n)
|
||||
}
|
||||
|
||||
if rs.Primary.ID == "" {
|
||||
return errors.New("No ALB ID is set")
|
||||
}
|
||||
|
||||
conn := testAccProvider.Meta().(*AWSClient).elbv2conn
|
||||
|
||||
describe, err := conn.DescribeLoadBalancers(&elbv2.DescribeLoadBalancersInput{
|
||||
LoadBalancerArns: []*string{aws.String(rs.Primary.ID)},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(describe.LoadBalancers) != 1 ||
|
||||
*describe.LoadBalancers[0].LoadBalancerArn != rs.Primary.ID {
|
||||
return errors.New("ALB not found")
|
||||
}
|
||||
|
||||
*res = *describe.LoadBalancers[0]
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testAccCheckAWSALBDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).elbv2conn
|
||||
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_alb" {
|
||||
continue
|
||||
}
|
||||
|
||||
describe, err := conn.DescribeLoadBalancers(&elbv2.DescribeLoadBalancersInput{
|
||||
LoadBalancerArns: []*string{aws.String(rs.Primary.ID)},
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
if len(describe.LoadBalancers) != 0 &&
|
||||
*describe.LoadBalancers[0].LoadBalancerArn == rs.Primary.ID {
|
||||
return fmt.Errorf("ALB %q still exists", rs.Primary.ID)
|
||||
}
|
||||
}
|
||||
|
||||
// Verify the error
|
||||
if isLoadBalancerNotFound(err) {
|
||||
return nil
|
||||
} else {
|
||||
return errwrap.Wrapf("Unexpected error checking ALB destroyed: {{err}}", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func testAccAWSALBConfig_basic(albName string) string {
|
||||
return fmt.Sprintf(`resource "aws_alb" "alb_test" {
|
||||
name = "%s"
|
||||
internal = false
|
||||
security_groups = ["${aws_security_group.alb_test.id}"]
|
||||
subnets = ["${aws_subnet.alb_test.*.id}"]
|
||||
|
||||
idle_timeout = 30
|
||||
enable_deletion_protection = false
|
||||
|
||||
tags {
|
||||
TestName = "TestAccAWSALB_basic"
|
||||
}
|
||||
}
|
||||
|
||||
variable "subnets" {
|
||||
default = ["10.0.1.0/24", "10.0.2.0/24"]
|
||||
type = "list"
|
||||
}
|
||||
|
||||
data "aws_availability_zones" "available" {}
|
||||
|
||||
resource "aws_vpc" "alb_test" {
|
||||
cidr_block = "10.0.0.0/16"
|
||||
|
||||
tags {
|
||||
TestName = "TestAccAWSALB_basic"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_subnet" "alb_test" {
|
||||
count = 2
|
||||
vpc_id = "${aws_vpc.alb_test.id}"
|
||||
cidr_block = "${element(var.subnets, count.index)}"
|
||||
map_public_ip_on_launch = true
|
||||
availability_zone = "${element(data.aws_availability_zones.available.names, count.index)}"
|
||||
|
||||
tags {
|
||||
TestName = "TestAccAWSALB_basic"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_security_group" "alb_test" {
|
||||
name = "allow_all_alb_test"
|
||||
description = "Used for ALB Testing"
|
||||
vpc_id = "${aws_vpc.alb_test.id}"
|
||||
|
||||
ingress {
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
protocol = "-1"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
egress {
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
protocol = "-1"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
tags {
|
||||
TestName = "TestAccAWSALB_basic"
|
||||
}
|
||||
}`, albName)
|
||||
}
|
||||
|
||||
func testAccAWSALBConfig_accessLogs(albName, bucketName string) string {
|
||||
return fmt.Sprintf(`resource "aws_alb" "alb_test" {
|
||||
name = "%s"
|
||||
internal = false
|
||||
security_groups = ["${aws_security_group.alb_test.id}"]
|
||||
subnets = ["${aws_subnet.alb_test.*.id}"]
|
||||
|
||||
idle_timeout = 50
|
||||
enable_deletion_protection = false
|
||||
|
||||
access_logs {
|
||||
bucket = "${aws_s3_bucket.logs.bucket}"
|
||||
prefix = "${var.bucket_prefix}"
|
||||
}
|
||||
|
||||
tags {
|
||||
TestName = "TestAccAWSALB_basic"
|
||||
}
|
||||
}
|
||||
|
||||
variable "bucket_name" {
|
||||
type = "string"
|
||||
default = "%s"
|
||||
}
|
||||
|
||||
variable "bucket_prefix" {
|
||||
type = "string"
|
||||
default = "testAccAWSALBConfig_accessLogs"
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket" "logs" {
|
||||
bucket = "${var.bucket_name}"
|
||||
policy = "${data.aws_iam_policy_document.logs_bucket.json}"
|
||||
# dangerous, only here for the test...
|
||||
force_destroy = true
|
||||
|
||||
tags {
|
||||
Name = "ALB Logs Bucket Test"
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_caller_identity" "current" {}
|
||||
|
||||
data "aws_elb_service_account" "current" {}
|
||||
|
||||
data "aws_iam_policy_document" "logs_bucket" {
|
||||
statement {
|
||||
actions = ["s3:PutObject"]
|
||||
effect = "Allow"
|
||||
resources = ["arn:aws:s3:::${var.bucket_name}/${var.bucket_prefix}/AWSLogs/${data.aws_caller_identity.current.account_id}/*"]
|
||||
|
||||
principals = {
|
||||
type = "AWS"
|
||||
identifiers = ["arn:aws:iam::${data.aws_elb_service_account.current.id}:root"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
variable "subnets" {
|
||||
default = ["10.0.1.0/24", "10.0.2.0/24"]
|
||||
type = "list"
|
||||
}
|
||||
|
||||
data "aws_availability_zones" "available" {}
|
||||
|
||||
resource "aws_vpc" "alb_test" {
|
||||
cidr_block = "10.0.0.0/16"
|
||||
|
||||
tags {
|
||||
TestName = "TestAccAWSALB_basic"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_subnet" "alb_test" {
|
||||
count = 2
|
||||
vpc_id = "${aws_vpc.alb_test.id}"
|
||||
cidr_block = "${element(var.subnets, count.index)}"
|
||||
map_public_ip_on_launch = true
|
||||
availability_zone = "${element(data.aws_availability_zones.available.names, count.index)}"
|
||||
|
||||
tags {
|
||||
TestName = "TestAccAWSALB_basic"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_security_group" "alb_test" {
|
||||
name = "allow_all_alb_test"
|
||||
description = "Used for ALB Testing"
|
||||
vpc_id = "${aws_vpc.alb_test.id}"
|
||||
|
||||
ingress {
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
protocol = "-1"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
egress {
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
protocol = "-1"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
tags {
|
||||
TestName = "TestAccAWSALB_basic"
|
||||
}
|
||||
}`, albName, bucketName)
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,132 @@
|
|||
// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
|
||||
|
||||
package elbv2
|
||||
|
||||
import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/client"
|
||||
"github.com/aws/aws-sdk-go/aws/client/metadata"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/aws/signer/v4"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/query"
|
||||
)
|
||||
|
||||
// A load balancer distributes incoming traffic across targets, such as your
|
||||
// EC2 instances. This enables you to increase the availability of your application.
|
||||
// The load balancer also monitors the health of its registered targets and
|
||||
// ensures that it routes traffic only to healthy targets. You configure your
|
||||
// load balancer to accept incoming traffic by specifying one or more listeners,
|
||||
// which are configured with a protocol and port number for connections from
|
||||
// clients to the load balancer. You configure a target group with a protocol
|
||||
// and port number for connections from the load balancer to the targets, and
|
||||
// with health check settings to be used when checking the health status of
|
||||
// the targets.
|
||||
//
|
||||
// Elastic Load Balancing supports two types of load balancers: Classic load
|
||||
// balancers and Application load balancers (new). A Classic load balancer makes
|
||||
// routing and load balancing decisions either at the transport layer (TCP/SSL)
|
||||
// or the application layer (HTTP/HTTPS), and supports either EC2-Classic or
|
||||
// a VPC. An Application load balancer makes routing and load balancing decisions
|
||||
// at the application layer (HTTP/HTTPS), supports path-based routing, and can
|
||||
// route requests to one or more ports on each EC2 instance or container instance
|
||||
// in your virtual private cloud (VPC). For more information, see the Elastic
|
||||
// Load Balancing User Guide (http://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/).
|
||||
//
|
||||
// This reference covers the 2015-12-01 API, which supports Application load
|
||||
// balancers. The 2012-06-01 API supports Classic load balancers.
|
||||
//
|
||||
// To get started with an Application load balancer, complete the following
|
||||
// tasks:
|
||||
//
|
||||
// Create a load balancer using CreateLoadBalancer.
|
||||
//
|
||||
// Create a target group using CreateTargetGroup.
|
||||
//
|
||||
// Register targets for the target group using RegisterTargets.
|
||||
//
|
||||
// Create one or more listeners for your load balancer using CreateListener.
|
||||
//
|
||||
// (Optional) Create one or more rules for content routing based on URL using
|
||||
// CreateRule.
|
||||
//
|
||||
// To delete an Application load balancer and its related resources, complete
|
||||
// the following tasks:
|
||||
//
|
||||
// Delete the load balancer using DeleteLoadBalancer.
|
||||
//
|
||||
// Delete the target group using DeleteTargetGroup.
|
||||
//
|
||||
// All Elastic Load Balancing operations are idempotent, which means that
|
||||
// they complete at most one time. If you repeat an operation, it succeeds.
|
||||
//The service client's operations are safe to be used concurrently.
|
||||
// It is not safe to mutate any of the client's properties though.
|
||||
type ELBV2 struct {
|
||||
*client.Client
|
||||
}
|
||||
|
||||
// Used for custom client initialization logic
|
||||
var initClient func(*client.Client)
|
||||
|
||||
// Used for custom request initialization logic
|
||||
var initRequest func(*request.Request)
|
||||
|
||||
// A ServiceName is the name of the service the client will make API calls to.
|
||||
const ServiceName = "elasticloadbalancing"
|
||||
|
||||
// New creates a new instance of the ELBV2 client with a session.
|
||||
// If additional configuration is needed for the client instance use the optional
|
||||
// aws.Config parameter to add your extra config.
|
||||
//
|
||||
// Example:
|
||||
// // Create a ELBV2 client from just a session.
|
||||
// svc := elbv2.New(mySession)
|
||||
//
|
||||
// // Create a ELBV2 client with additional configuration
|
||||
// svc := elbv2.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
|
||||
func New(p client.ConfigProvider, cfgs ...*aws.Config) *ELBV2 {
|
||||
c := p.ClientConfig(ServiceName, cfgs...)
|
||||
return newClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion)
|
||||
}
|
||||
|
||||
// newClient creates, initializes and returns a new service client instance.
|
||||
func newClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion string) *ELBV2 {
|
||||
svc := &ELBV2{
|
||||
Client: client.New(
|
||||
cfg,
|
||||
metadata.ClientInfo{
|
||||
ServiceName: ServiceName,
|
||||
SigningRegion: signingRegion,
|
||||
Endpoint: endpoint,
|
||||
APIVersion: "2015-12-01",
|
||||
},
|
||||
handlers,
|
||||
),
|
||||
}
|
||||
|
||||
// Handlers
|
||||
svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
|
||||
svc.Handlers.Build.PushBackNamed(query.BuildHandler)
|
||||
svc.Handlers.Unmarshal.PushBackNamed(query.UnmarshalHandler)
|
||||
svc.Handlers.UnmarshalMeta.PushBackNamed(query.UnmarshalMetaHandler)
|
||||
svc.Handlers.UnmarshalError.PushBackNamed(query.UnmarshalErrorHandler)
|
||||
|
||||
// Run custom client initialization if present
|
||||
if initClient != nil {
|
||||
initClient(svc.Client)
|
||||
}
|
||||
|
||||
return svc
|
||||
}
|
||||
|
||||
// newRequest creates a new request for a ELBV2 operation and runs any
|
||||
// custom request initialization.
|
||||
func (c *ELBV2) newRequest(op *request.Operation, params, data interface{}) *request.Request {
|
||||
req := c.NewRequest(op, params, data)
|
||||
|
||||
// Run custom request initialization if present
|
||||
if initRequest != nil {
|
||||
initRequest(req)
|
||||
}
|
||||
|
||||
return req
|
||||
}
|
|
@ -595,6 +595,12 @@
|
|||
"revision": "f80e7d0182a463dff0c0da6bbed57f21369d4346",
|
||||
"revisionTime": "2016-08-11T16:24:59Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "DLD6/EwnTkIR6HGaYKYs96lCD+Q=",
|
||||
"path": "github.com/aws/aws-sdk-go/service/elbv2",
|
||||
"revision": "f80e7d0182a463dff0c0da6bbed57f21369d4346",
|
||||
"revisionTime": "2016-08-11T16:24:59Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "MA6U/Vj0D00yihMHD6bXKyjtfeE=",
|
||||
"path": "github.com/aws/aws-sdk-go/service/emr",
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
---
|
||||
layout: "aws"
|
||||
page_title: "AWS: aws_alb"
|
||||
sidebar_current: "docs-aws-resource-alb"
|
||||
description: |-
|
||||
Provides an Application Load Balancer resource.
|
||||
---
|
||||
|
||||
# aws\_alb
|
||||
|
||||
Provides an Application Load Balancer resource.
|
||||
|
||||
## Example Usage
|
||||
|
||||
```
|
||||
# Create a new load balancer
|
||||
resource "aws_alb" "test" {
|
||||
name = "test-alb-tf"
|
||||
internal = false
|
||||
security_groups = ["${aws_security_group.alb_sg.id}"]
|
||||
subnets = ["${aws_subnet.public.*.id}"]
|
||||
|
||||
enable_deletion_protection = true
|
||||
|
||||
access_logs {
|
||||
bucket = "${aws_s3_bucket.alb_logs.bucket}"
|
||||
prefix = "test-alb"
|
||||
}
|
||||
|
||||
tags {
|
||||
Environment = "production"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Argument Reference
|
||||
|
||||
The following arguments are supported:
|
||||
|
||||
* `name` - (Optional) The name of the ALB. By default generated by Terraform.
|
||||
* `internal` - (Optional) If true, the ALB will be internal.
|
||||
* `security_groups` - (Optional) A list of security group IDs to assign to the ELB.
|
||||
* `access_logs` - (Optional) An Access Logs block. Access Logs documented below.
|
||||
* `subnets` - (Required) A list of subnet IDs to attach to the ELB.
|
||||
* `idle_timeout` - (Optional) The time in seconds that the connection is allowed to be idle. Default: 60.
|
||||
* `enable_deletion_protection` - (Optional) If true, deletion of the load balancer will be disabled via
|
||||
the AWS API. This will prevent Terraform from deleting the load balancer.
|
||||
* `tags` - (Optional) A mapping of tags to assign to the resource.
|
||||
|
||||
Access Logs (`access_logs`) support the following:
|
||||
|
||||
* `bucket` - (Required) The S3 bucket name to store the logs in.
|
||||
* `prefix` - (Optional) The S3 bucket prefix. Logs are stored in the root if not configured.
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
The following attributes are exported in addition to the arguments listed above:
|
||||
|
||||
* `id` - The ARN of the load balancer
|
||||
* `dns_name` - The DNS name of the load balancer
|
||||
* `canonical_hosted_zone_id` - The canonical hosted zone ID of the load balancer.
|
||||
* `zone_id` - The canonical hosted zone ID of the load balancer (to be used in a Route 53 Alias record)
|
||||
|
||||
## Import
|
||||
|
||||
ALBs can be imported using their ARN, e.g.
|
||||
|
||||
```
|
||||
$ terraform import aws_alb.bar arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188
|
||||
```
|
|
@ -0,0 +1,60 @@
|
|||
---
|
||||
layout: "aws"
|
||||
page_title: "AWS: aws_alb_target_group"
|
||||
sidebar_current: "docs-aws-resource-alb-target-group"
|
||||
description: |-
|
||||
Provides a Target Group resource for use with Application Load
|
||||
Balancers.
|
||||
---
|
||||
|
||||
# aws\_alb\_target\_group
|
||||
|
||||
Provides a Target Group resource for use with Application Load Balancer
|
||||
resources.
|
||||
|
||||
## Example Usage
|
||||
|
||||
```
|
||||
```
|
||||
|
||||
## Argument Reference
|
||||
|
||||
The following arguments are supported:
|
||||
|
||||
* `name` - (Required) The name of the target group.
|
||||
* `port` - (Required) The port on which targets receive traffic, unless overriden when registering a specific target.
|
||||
* `protocol` - (Required) The protocol to use for routing traffic to the targets.
|
||||
* `vpc_id` - (Required) The identifier of the VPC in which to create the target group.
|
||||
* `deregistration_delay` - (Optional) The amount time for Elastic Load Balancing to wait before changing the state of a deregistering target from draining to unused. The range is 0-3600 seconds. The default value is 300 seconds.
|
||||
* `stickiness` - (Optional) A Stickiness block. Stickiness blocks are documented below.
|
||||
* `health_check` - (Optional) A Health Check block. Health Check blocks are documented below.
|
||||
|
||||
Stickiness Blocks (`stickiness`) support the following:
|
||||
|
||||
* `type` - (Required) The type of sticky sessions. The only current possible value is `lb_cookie`.
|
||||
* `cookie_duration` - (Optional) The time period, in seconds, during which requests from a client should be routed to the same target. After this time period expires, the load balancer-generated cookie is considered stale. The range is 1 second to 1 week (604800 seconds). The default value is 1 day (86400 seconds).
|
||||
|
||||
Health Check Blocks (`health_check`) support the following:
|
||||
|
||||
* `interval` - (Optional) The approximate amount of time, in seconds, between health checks of an individual target. Minimum value 5 seconds, Maximum value 300 seconds. Default 30 seconds.
|
||||
* `path` - (Optional) The destination for the health check request. Default `/`.
|
||||
* `port` - (Optional) The port to use to connect with the target. Valid values are either ports 1-65536, or `traffic-port`. Defaults to `traffic-port`.
|
||||
* `protocol` - (Optional) The protocol to use to connect with the target. Defaults to `HTTP`.
|
||||
* `timeout` - (Optional) The amount of time, in seconds, during which no response means a failed health check. Defaults to 5 seconds.
|
||||
* `healthy_threshold` - (Optional) The number of consecutive health checks successes required before considering an unhealthy target healthy. Defaults to 5.
|
||||
* `unhealthy_threshold` - (Optional) The number of consecutive health check failures required before considering the target unhealthy. Defaults to 2.
|
||||
* `matcher` (Optional) The HTTP codes to use when checking for a successful response from a target. Defaults to `200`. You can specify multiple values (for example, "200,202") or a range of values (for example, "200-299").
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
The following attributes are exported in addition to the arguments listed above:
|
||||
|
||||
* `id` - The ARN of the target group.
|
||||
|
||||
## Import
|
||||
|
||||
Target Groups can be imported using their ARN, e.g.
|
||||
|
||||
```
|
||||
$ terraform import aws_alb_target_group.app_front_end arn:aws:elasticloadbalancing:us-west-2:187416307283:targetgroup/app-front-end/20cfe21448b66314
|
||||
```
|
|
@ -206,10 +206,18 @@
|
|||
</li>
|
||||
|
||||
|
||||
<li<%= sidebar_current(/^docs-aws-resource-(ami|app|autoscaling|ebs|elb|eip|instance|launch|lb|proxy|spot|volume|placement|key-pair|elb_attachment|load-balancer)/) %>>
|
||||
<li<%= sidebar_current(/^docs-aws-resource-(alb|ami|app|autoscaling|ebs|elb|eip|instance|launch|lb|proxy|spot|volume|placement|key-pair|elb_attachment|load-balancer)/) %>>
|
||||
<a href="#">EC2 Resources</a>
|
||||
<ul class="nav nav-visible">
|
||||
|
||||
<li<%= sidebar_current("docs-aws-resource-alb") %>>
|
||||
<a href="/docs/providers/aws/r/alb.html">aws_alb</a>
|
||||
</li>
|
||||
|
||||
<li<%= sidebar_current("docs-aws-resource-alb-target-group") %>>
|
||||
<a href="/docs/providers/aws/r/alb_target_group.html">aws_alb_target_group</a>
|
||||
</li>
|
||||
|
||||
<li<%= sidebar_current("docs-aws-resource-ami") %>>
|
||||
<a href="/docs/providers/aws/r/ami.html">aws_ami</a>
|
||||
</li>
|
||||
|
|
Loading…
Reference in New Issue