provider/aws: Allow elb name to be generated
This commit is contained in:
parent
70b7243dd6
commit
676d490d40
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||||
"github.com/aws/aws-sdk-go/service/elb"
|
"github.com/aws/aws-sdk-go/service/elb"
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"github.com/hashicorp/terraform/helper/hashcode"
|
||||||
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,7 +25,8 @@ func resourceAwsElb() *schema.Resource {
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
|
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
|
||||||
value := v.(string)
|
value := v.(string)
|
||||||
|
@ -211,10 +213,18 @@ func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var elbName string
|
||||||
|
if v, ok := d.GetOk("name"); ok {
|
||||||
|
elbName = v.(string)
|
||||||
|
} else {
|
||||||
|
elbName = resource.PrefixedUniqueId("tf-lb-")
|
||||||
|
d.Set("name", elbName)
|
||||||
|
}
|
||||||
|
|
||||||
tags := tagsFromMapELB(d.Get("tags").(map[string]interface{}))
|
tags := tagsFromMapELB(d.Get("tags").(map[string]interface{}))
|
||||||
// Provision the elb
|
// Provision the elb
|
||||||
elbOpts := &elb.CreateLoadBalancerInput{
|
elbOpts := &elb.CreateLoadBalancerInput{
|
||||||
LoadBalancerName: aws.String(d.Get("name").(string)),
|
LoadBalancerName: aws.String(elbName),
|
||||||
Listeners: listeners,
|
Listeners: listeners,
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
}
|
}
|
||||||
|
@ -241,7 +251,7 @@ func resourceAwsElbCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign the elb's unique identifier for use later
|
// Assign the elb's unique identifier for use later
|
||||||
d.SetId(d.Get("name").(string))
|
d.SetId(elbName)
|
||||||
log.Printf("[INFO] ELB ID: %s", d.Id())
|
log.Printf("[INFO] ELB ID: %s", d.Id())
|
||||||
|
|
||||||
// Enable partial mode and record what we set
|
// Enable partial mode and record what we set
|
||||||
|
|
|
@ -57,7 +57,7 @@ resource "aws_elb" "bar" {
|
||||||
|
|
||||||
The following arguments are supported:
|
The following arguments are supported:
|
||||||
|
|
||||||
* `name` - (Required) The name of the ELB
|
* `name` - (Optional) The name of the ELB. By default generated by terraform.
|
||||||
* `availability_zones` - (Required for an EC2-classic ELB) The AZ's to serve traffic in.
|
* `availability_zones` - (Required for an EC2-classic ELB) The AZ's to serve traffic in.
|
||||||
* `security_groups` - (Optional) A list of security group IDs to assign to the ELB.
|
* `security_groups` - (Optional) A list of security group IDs to assign to the ELB.
|
||||||
* `subnets` - (Required for a VPC ELB) A list of subnet IDs to attach to the ELB.
|
* `subnets` - (Required for a VPC ELB) A list of subnet IDs to attach to the ELB.
|
||||||
|
|
Loading…
Reference in New Issue