provider/aws: Add `arn` fields to ALB resources

This commit adds an `arn` field to `aws_alb` and `aws_alb_target_group`
resources, in order to present a more coherant user experience to people
using resource variables in fields suffixed "arn".
This commit is contained in:
James Nugent 2016-08-18 18:54:39 +01:00
parent 59f66eca02
commit e38d41b7a7
7 changed files with 24 additions and 4 deletions

View File

@ -22,6 +22,11 @@ func resourceAwsAlb() *schema.Resource {
}, },
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"name": { "name": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
@ -164,6 +169,7 @@ func resourceAwsAlbRead(d *schema.ResourceData, meta interface{}) error {
alb := describeResp.LoadBalancers[0] alb := describeResp.LoadBalancers[0]
d.Set("arn", alb.LoadBalancerArn)
d.Set("name", alb.LoadBalancerName) d.Set("name", alb.LoadBalancerName)
d.Set("internal", (alb.Scheme != nil && *alb.Scheme == "internal")) d.Set("internal", (alb.Scheme != nil && *alb.Scheme == "internal"))
d.Set("security_groups", flattenStringList(alb.SecurityGroups)) d.Set("security_groups", flattenStringList(alb.SecurityGroups))

View File

@ -25,6 +25,11 @@ func resourceAwsAlbTargetGroup() *schema.Resource {
}, },
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"name": { "name": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
@ -206,6 +211,7 @@ func resourceAwsAlbTargetGroupRead(d *schema.ResourceData, meta interface{}) err
targetGroup := resp.TargetGroups[0] targetGroup := resp.TargetGroups[0]
d.Set("arn", targetGroup.TargetGroupArn)
d.Set("name", targetGroup.TargetGroupName) d.Set("name", targetGroup.TargetGroupName)
d.Set("port", targetGroup.Port) d.Set("port", targetGroup.Port)
d.Set("protocol", targetGroup.Protocol) d.Set("protocol", targetGroup.Protocol)

View File

@ -27,6 +27,7 @@ func TestAccAWSALBTargetGroup_basic(t *testing.T) {
Config: testAccAWSALBTargetGroupConfig_basic(targetGroupName), Config: testAccAWSALBTargetGroupConfig_basic(targetGroupName),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &conf), testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &conf),
resource.TestCheckResourceAttrSet("aws_alb_target_group.test", "arn"),
resource.TestCheckResourceAttr("aws_alb_target_group.test", "name", targetGroupName), 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", "port", "443"),
resource.TestCheckResourceAttr("aws_alb_target_group.test", "protocol", "HTTPS"), resource.TestCheckResourceAttr("aws_alb_target_group.test", "protocol", "HTTPS"),
@ -64,6 +65,7 @@ func TestAccAWSALBTargetGroup_updateHealthCheck(t *testing.T) {
Config: testAccAWSALBTargetGroupConfig_basic(targetGroupName), Config: testAccAWSALBTargetGroupConfig_basic(targetGroupName),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &conf), testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &conf),
resource.TestCheckResourceAttrSet("aws_alb_target_group.test", "arn"),
resource.TestCheckResourceAttr("aws_alb_target_group.test", "name", targetGroupName), 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", "port", "443"),
resource.TestCheckResourceAttr("aws_alb_target_group.test", "protocol", "HTTPS"), resource.TestCheckResourceAttr("aws_alb_target_group.test", "protocol", "HTTPS"),
@ -87,6 +89,7 @@ func TestAccAWSALBTargetGroup_updateHealthCheck(t *testing.T) {
Config: testAccAWSALBTargetGroupConfig_updateHealthCheck(targetGroupName), Config: testAccAWSALBTargetGroupConfig_updateHealthCheck(targetGroupName),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &conf), testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &conf),
resource.TestCheckResourceAttrSet("aws_alb_target_group.test", "arn"),
resource.TestCheckResourceAttr("aws_alb_target_group.test", "name", targetGroupName), 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", "port", "443"),
resource.TestCheckResourceAttr("aws_alb_target_group.test", "protocol", "HTTPS"), resource.TestCheckResourceAttr("aws_alb_target_group.test", "protocol", "HTTPS"),

View File

@ -38,6 +38,7 @@ func TestAccAWSALB_basic(t *testing.T) {
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "vpc_id"), resource.TestCheckResourceAttrSet("aws_alb.alb_test", "vpc_id"),
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "zone_id"), resource.TestCheckResourceAttrSet("aws_alb.alb_test", "zone_id"),
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "dns_name"), resource.TestCheckResourceAttrSet("aws_alb.alb_test", "dns_name"),
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "arn"),
), ),
}, },
}, },
@ -70,6 +71,7 @@ func TestAccAWSALB_accesslogs(t *testing.T) {
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "vpc_id"), resource.TestCheckResourceAttrSet("aws_alb.alb_test", "vpc_id"),
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "zone_id"), resource.TestCheckResourceAttrSet("aws_alb.alb_test", "zone_id"),
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "dns_name"), resource.TestCheckResourceAttrSet("aws_alb.alb_test", "dns_name"),
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "arn"),
), ),
}, },
@ -91,6 +93,7 @@ func TestAccAWSALB_accesslogs(t *testing.T) {
resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.#", "1"), 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.bucket", bucketName),
resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.0.prefix", "testAccAWSALBConfig_accessLogs"), resource.TestCheckResourceAttr("aws_alb.alb_test", "access_logs.0.prefix", "testAccAWSALBConfig_accessLogs"),
resource.TestCheckResourceAttrSet("aws_alb.alb_test", "arn"),
), ),
}, },
}, },

View File

@ -56,7 +56,8 @@ Access Logs (`access_logs`) support the following:
The following attributes are exported in addition to the arguments listed above: The following attributes are exported in addition to the arguments listed above:
* `id` - The ARN of the load balancer * `id` - The ARN of the load balancer (matches `arn`)
* `arn` - The ARN of the load balancer (matches `id`)
* `dns_name` - The DNS name 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. * `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) * `zone_id` - The canonical hosted zone ID of the load balancer (to be used in a Route 53 Alias record)

View File

@ -23,14 +23,14 @@ resource "aws_alb_target_group" "front_end" {
} }
resource "aws_alb_listener" "front_end" { resource "aws_alb_listener" "front_end" {
load_balancer_arn = "${aws_alb.front_end.id}" load_balancer_arn = "${aws_alb.front_end.arn}"
port = "443" port = "443"
protocol = "HTTPS" protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-2015-05" ssl_policy = "ELBSecurityPolicy-2015-05"
certificate_arn = "arn:aws:iam::187416307283:server-certificate/test_cert_rab3wuqwgja25ct3n4jdj2tzu4" certificate_arn = "arn:aws:iam::187416307283:server-certificate/test_cert_rab3wuqwgja25ct3n4jdj2tzu4"
default_action { default_action {
target_group_arn = "${aws_alb_target_group.front_end.id}" target_group_arn = "${aws_alb_target_group.front_end.arn}"
type = "forward" type = "forward"
} }
} }

View File

@ -49,7 +49,8 @@ Health Check Blocks (`health_check`) support the following:
The following attributes are exported in addition to the arguments listed above: The following attributes are exported in addition to the arguments listed above:
* `id` - The ARN of the target group. * `id` - The ARN of the Target Group (matches `arn`)
* `arn` - The ARN of the Target Group (matches `id`)
## Import ## Import