Change AWS ELB access_logs to list type.
There can only be a single access_log configuration per load balancer so choosing to use a list over a set is only relevant when comparing changes during a plan. A list makes it much easier to compare updates since the index is stable (0 vs. computed hash).
This commit is contained in:
parent
1e7f10d3a3
commit
f83c81dbb5
|
@ -106,7 +106,7 @@ func resourceAwsElb() *schema.Resource {
|
||||||
},
|
},
|
||||||
|
|
||||||
"access_logs": &schema.Schema{
|
"access_logs": &schema.Schema{
|
||||||
Type: schema.TypeSet,
|
Type: schema.TypeList,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Elem: &schema.Resource{
|
Elem: &schema.Resource{
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
|
@ -125,7 +125,6 @@ func resourceAwsElb() *schema.Resource {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Set: resourceAwsElbAccessLogsHash,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"listener": &schema.Schema{
|
"listener": &schema.Schema{
|
||||||
|
@ -493,7 +492,7 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
logs := d.Get("access_logs").(*schema.Set).List()
|
logs := d.Get("access_logs").([]interface{})
|
||||||
if len(logs) > 1 {
|
if len(logs) > 1 {
|
||||||
return fmt.Errorf("Only one access logs config per ELB is supported")
|
return fmt.Errorf("Only one access logs config per ELB is supported")
|
||||||
} else if len(logs) == 1 {
|
} else if len(logs) == 1 {
|
||||||
|
@ -713,19 +712,6 @@ func resourceAwsElbDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsElbAccessLogsHash(v interface{}) int {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
m := v.(map[string]interface{})
|
|
||||||
buf.WriteString(fmt.Sprintf("%d-", m["interval"].(int)))
|
|
||||||
buf.WriteString(fmt.Sprintf("%s-",
|
|
||||||
strings.ToLower(m["bucket"].(string))))
|
|
||||||
if v, ok := m["bucket_prefix"]; ok {
|
|
||||||
buf.WriteString(fmt.Sprintf("%s-", strings.ToLower(v.(string))))
|
|
||||||
}
|
|
||||||
|
|
||||||
return hashcode.String(buf.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func resourceAwsElbListenerHash(v interface{}) int {
|
func resourceAwsElbListenerHash(v interface{}) int {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
m := v.(map[string]interface{})
|
m := v.(map[string]interface{})
|
||||||
|
|
|
@ -102,9 +102,9 @@ func TestAccAWSELB_AccessLogs(t *testing.T) {
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_elb.foo", "access_logs.#", "1"),
|
"aws_elb.foo", "access_logs.#", "1"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_elb.foo", "access_logs.1713209538.bucket", "terraform-access-logs-bucket"),
|
"aws_elb.foo", "access_logs.0.bucket", "terraform-access-logs-bucket"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_elb.foo", "access_logs.1713209538.interval", "5"),
|
"aws_elb.foo", "access_logs.0.interval", "5"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue