Added option to attach an ELB to Opsworks layer

This commit is contained in:
Paulo Schreiner 2016-01-16 16:59:48 -02:00 committed by clint shryock
parent fe90cea9a1
commit 7293ab99d3
11 changed files with 73 additions and 0 deletions

View File

@ -67,6 +67,11 @@ func (lt *opsworksLayerType) SchemaResource() *schema.Resource {
Optional: true,
},
"elastic_load_balancer": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"custom_setup_recipes": &schema.Schema{
Type: schema.TypeList,
Optional: true,
@ -288,6 +293,29 @@ func (lt *opsworksLayerType) Read(d *schema.ResourceData, client *opsworks.OpsWo
lt.SetCustomRecipes(d, layer.CustomRecipes)
lt.SetVolumeConfigurations(d, layer.VolumeConfigurations)
/* get ELB */
ebsRequest := &opsworks.DescribeElasticLoadBalancersInput{
LayerIds: []*string{
aws.String(d.Id()),
},
}
loadBalancers, err := client.DescribeElasticLoadBalancers(ebsRequest)
fmt.Println(loadBalancers)
if err != nil {
return err
}
if loadBalancers.ElasticLoadBalancers == nil || len(loadBalancers.ElasticLoadBalancers) == 0 {
d.Set("elastic_load_balancer", "")
} else {
loadBalancer := loadBalancers.ElasticLoadBalancers[0]
if loadBalancer != nil {
d.Set("elastic_load_balancer", loadBalancer.ElasticLoadBalancerName)
}
}
return nil
}
@ -328,6 +356,15 @@ func (lt *opsworksLayerType) Create(d *schema.ResourceData, client *opsworks.Ops
d.SetId(layerId)
d.Set("id", layerId)
loadBalancer := aws.String(d.Get("elastic_load_balancer").(string))
if loadBalancer != nil && *loadBalancer != "" {
log.Printf("[DEBUG] Attaching load balancer: %s", *loadBalancer)
client.AttachElasticLoadBalancer(&opsworks.AttachElasticLoadBalancerInput{
ElasticLoadBalancerName: loadBalancer,
LayerId: &layerId,
})
}
return lt.Read(d, client)
}
@ -358,6 +395,32 @@ func (lt *opsworksLayerType) Update(d *schema.ResourceData, client *opsworks.Ops
log.Printf("[DEBUG] Updating OpsWorks layer: %s", d.Id())
if d.HasChange("elastic_load_balancer") {
lbo, lbn := d.GetChange("elastic_load_balancer")
loadBalancerOld := aws.String(lbo.(string))
loadBalancerNew := aws.String(lbn.(string))
if loadBalancerOld != nil && *loadBalancerOld != "" {
log.Printf("[DEBUG] Dettaching load balancer: %s", *loadBalancerOld)
_, err := client.DetachElasticLoadBalancer(&opsworks.DetachElasticLoadBalancerInput{
ElasticLoadBalancerName: loadBalancerOld,
LayerId: aws.String(d.Id()),
})
if err != nil {
return err
}
}
if loadBalancerNew != nil && *loadBalancerNew != "" {
log.Printf("[DEBUG] Attaching load balancer: %s", *loadBalancerNew)
client.AttachElasticLoadBalancer(&opsworks.AttachElasticLoadBalancerInput{
ElasticLoadBalancerName: loadBalancerNew,
LayerId: aws.String(d.Id()),
})
}
}
_, err := client.UpdateLayer(req)
if err != nil {
return err

View File

@ -34,6 +34,7 @@ The following arguments are supported:
* `auto_healing` - (Optional) Whether to enable auto-healing for the layer.
* `install_updates_on_boot` - (Optional) Whether to install OS and package updates on each instance when it boots.
* `instance_shutdown_timeout` - (Optional) The time, in seconds, that OpsWorks will wait for Chef to complete after triggering the Shutdown event.
* `elastic_load_balancer` - (Optional) Name of an Elastic Load Balancer to attach to this layer
* `drain_elb_on_shutdown` - (Optional) Whether to enable Elastic Load Balancing connection draining.
* `system_packages` - (Optional) Names of a set of system packages to install on the layer's instances.
* `use_ebs_optimized_instances` - (Optional) Whether to use EBS-optimized instances.

View File

@ -33,6 +33,7 @@ The following arguments are supported:
* `auto_healing` - (Optional) Whether to enable auto-healing for the layer.
* `install_updates_on_boot` - (Optional) Whether to install OS and package updates on each instance when it boots.
* `instance_shutdown_timeout` - (Optional) The time, in seconds, that OpsWorks will wait for Chef to complete after triggering the Shutdown event.
* `elastic_load_balancer` - (Optional) Name of an Elastic Load Balancer to attach to this layer
* `drain_elb_on_shutdown` - (Optional) Whether to enable Elastic Load Balancing connection draining.
* `system_packages` - (Optional) Names of a set of system packages to install on the layer's instances.
* `url` - (Optional) The URL path to use for Ganglia. Defaults to "/ganglia".

View File

@ -35,6 +35,7 @@ The following arguments are supported:
* `healthcheck_url` - (Optional) URL path to use for instance healthchecks. Defaults to "/".
* `install_updates_on_boot` - (Optional) Whether to install OS and package updates on each instance when it boots.
* `instance_shutdown_timeout` - (Optional) The time, in seconds, that OpsWorks will wait for Chef to complete after triggering the Shutdown event.
* `elastic_load_balancer` - (Optional) Name of an Elastic Load Balancer to attach to this layer
* `drain_elb_on_shutdown` - (Optional) Whether to enable Elastic Load Balancing connection draining.
* `stats_enabled` - (Optional) Whether to enable HAProxy stats.
* `stats_url` - (Optional) The HAProxy stats URL. Defaults to "/haproxy?stats".

View File

@ -36,6 +36,7 @@ The following arguments are supported:
* `jvm_type` - (Optional) Keyword for the type of JVM to use. Defaults to `openjdk`.
* `jvm_options` - (Optional) Options to set for the JVM.
* `jvm_version` - (Optional) Version of JVM to use. Defaults to "7".
* `elastic_load_balancer` - (Optional) Name of an Elastic Load Balancer to attach to this layer
* `drain_elb_on_shutdown` - (Optional) Whether to enable Elastic Load Balancing connection draining.
* `system_packages` - (Optional) Names of a set of system packages to install on the layer's instances.
* `use_ebs_optimized_instances` - (Optional) Whether to use EBS-optimized instances.

View File

@ -32,6 +32,7 @@ The following arguments are supported:
* `auto_healing` - (Optional) Whether to enable auto-healing for the layer.
* `install_updates_on_boot` - (Optional) Whether to install OS and package updates on each instance when it boots.
* `instance_shutdown_timeout` - (Optional) The time, in seconds, that OpsWorks will wait for Chef to complete after triggering the Shutdown event.
* `elastic_load_balancer` - (Optional) Name of an Elastic Load Balancer to attach to this layer
* `drain_elb_on_shutdown` - (Optional) Whether to enable Elastic Load Balancing connection draining.
* `system_packages` - (Optional) Names of a set of system packages to install on the layer's instances.
* `use_ebs_optimized_instances` - (Optional) Whether to use EBS-optimized instances.

View File

@ -31,6 +31,7 @@ The following arguments are supported:
* `auto_healing` - (Optional) Whether to enable auto-healing for the layer.
* `install_updates_on_boot` - (Optional) Whether to install OS and package updates on each instance when it boots.
* `instance_shutdown_timeout` - (Optional) The time, in seconds, that OpsWorks will wait for Chef to complete after triggering the Shutdown event.
* `elastic_load_balancer` - (Optional) Name of an Elastic Load Balancer to attach to this layer
* `drain_elb_on_shutdown` - (Optional) Whether to enable Elastic Load Balancing connection draining.
* `root_password` - (Optional) Root password to use for MySQL.
* `root_password_on_all_instances` - (Optional) Whether to set the root user password to all instances in the stack so they can access the instances in this layer.

View File

@ -31,6 +31,7 @@ The following arguments are supported:
* `auto_healing` - (Optional) Whether to enable auto-healing for the layer.
* `install_updates_on_boot` - (Optional) Whether to install OS and package updates on each instance when it boots.
* `instance_shutdown_timeout` - (Optional) The time, in seconds, that OpsWorks will wait for Chef to complete after triggering the Shutdown event.
* `elastic_load_balancer` - (Optional) Name of an Elastic Load Balancer to attach to this layer
* `drain_elb_on_shutdown` - (Optional) Whether to enable Elastic Load Balancing connection draining.
* `nodejs_version` - (Optional) The version of NodeJS to use. Defaults to "0.10.38".
* `system_packages` - (Optional) Names of a set of system packages to install on the layer's instances.

View File

@ -31,6 +31,7 @@ The following arguments are supported:
* `auto_healing` - (Optional) Whether to enable auto-healing for the layer.
* `install_updates_on_boot` - (Optional) Whether to install OS and package updates on each instance when it boots.
* `instance_shutdown_timeout` - (Optional) The time, in seconds, that OpsWorks will wait for Chef to complete after triggering the Shutdown event.
* `elastic_load_balancer` - (Optional) Name of an Elastic Load Balancer to attach to this layer
* `drain_elb_on_shutdown` - (Optional) Whether to enable Elastic Load Balancing connection draining.
* `system_packages` - (Optional) Names of a set of system packages to install on the layer's instances.
* `use_ebs_optimized_instances` - (Optional) Whether to use EBS-optimized instances.

View File

@ -33,6 +33,7 @@ The following arguments are supported:
* `auto_healing` - (Optional) Whether to enable auto-healing for the layer.
* `install_updates_on_boot` - (Optional) Whether to install OS and package updates on each instance when it boots.
* `instance_shutdown_timeout` - (Optional) The time, in seconds, that OpsWorks will wait for Chef to complete after triggering the Shutdown event.
* `elastic_load_balancer` - (Optional) Name of an Elastic Load Balancer to attach to this layer
* `drain_elb_on_shutdown` - (Optional) Whether to enable Elastic Load Balancing connection draining.
* `manage_bundler` - (Optional) Whether OpsWorks should manage bundler. On by default.
* `passenger_version` - (Optional) The version of Passenger to use. Defaults to "4.0.46".

View File

@ -31,6 +31,7 @@ The following arguments are supported:
* `auto_healing` - (Optional) Whether to enable auto-healing for the layer.
* `install_updates_on_boot` - (Optional) Whether to install OS and package updates on each instance when it boots.
* `instance_shutdown_timeout` - (Optional) The time, in seconds, that OpsWorks will wait for Chef to complete after triggering the Shutdown event.
* `elastic_load_balancer` - (Optional) Name of an Elastic Load Balancer to attach to this layer
* `drain_elb_on_shutdown` - (Optional) Whether to enable Elastic Load Balancing connection draining.
* `system_packages` - (Optional) Names of a set of system packages to install on the layer's instances.
* `use_ebs_optimized_instances` - (Optional) Whether to use EBS-optimized instances.