Added option to attach an ELB to Opsworks layer
This commit is contained in:
parent
fe90cea9a1
commit
7293ab99d3
|
@ -67,6 +67,11 @@ func (lt *opsworksLayerType) SchemaResource() *schema.Resource {
|
||||||
Optional: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"elastic_load_balancer": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
|
|
||||||
"custom_setup_recipes": &schema.Schema{
|
"custom_setup_recipes": &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
@ -288,6 +293,29 @@ func (lt *opsworksLayerType) Read(d *schema.ResourceData, client *opsworks.OpsWo
|
||||||
lt.SetCustomRecipes(d, layer.CustomRecipes)
|
lt.SetCustomRecipes(d, layer.CustomRecipes)
|
||||||
lt.SetVolumeConfigurations(d, layer.VolumeConfigurations)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,6 +356,15 @@ func (lt *opsworksLayerType) Create(d *schema.ResourceData, client *opsworks.Ops
|
||||||
d.SetId(layerId)
|
d.SetId(layerId)
|
||||||
d.Set("id", 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)
|
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())
|
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)
|
_, err := client.UpdateLayer(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -34,6 +34,7 @@ The following arguments are supported:
|
||||||
* `auto_healing` - (Optional) Whether to enable auto-healing for the layer.
|
* `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.
|
* `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.
|
* `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.
|
* `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.
|
* `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.
|
* `use_ebs_optimized_instances` - (Optional) Whether to use EBS-optimized instances.
|
||||||
|
|
|
@ -33,6 +33,7 @@ The following arguments are supported:
|
||||||
* `auto_healing` - (Optional) Whether to enable auto-healing for the layer.
|
* `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.
|
* `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.
|
* `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.
|
* `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.
|
* `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".
|
* `url` - (Optional) The URL path to use for Ganglia. Defaults to "/ganglia".
|
||||||
|
|
|
@ -35,6 +35,7 @@ The following arguments are supported:
|
||||||
* `healthcheck_url` - (Optional) URL path to use for instance healthchecks. Defaults to "/".
|
* `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.
|
* `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.
|
* `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.
|
* `drain_elb_on_shutdown` - (Optional) Whether to enable Elastic Load Balancing connection draining.
|
||||||
* `stats_enabled` - (Optional) Whether to enable HAProxy stats.
|
* `stats_enabled` - (Optional) Whether to enable HAProxy stats.
|
||||||
* `stats_url` - (Optional) The HAProxy stats URL. Defaults to "/haproxy?stats".
|
* `stats_url` - (Optional) The HAProxy stats URL. Defaults to "/haproxy?stats".
|
||||||
|
|
|
@ -36,6 +36,7 @@ The following arguments are supported:
|
||||||
* `jvm_type` - (Optional) Keyword for the type of JVM to use. Defaults to `openjdk`.
|
* `jvm_type` - (Optional) Keyword for the type of JVM to use. Defaults to `openjdk`.
|
||||||
* `jvm_options` - (Optional) Options to set for the JVM.
|
* `jvm_options` - (Optional) Options to set for the JVM.
|
||||||
* `jvm_version` - (Optional) Version of JVM to use. Defaults to "7".
|
* `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.
|
* `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.
|
* `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.
|
* `use_ebs_optimized_instances` - (Optional) Whether to use EBS-optimized instances.
|
||||||
|
|
|
@ -32,6 +32,7 @@ The following arguments are supported:
|
||||||
* `auto_healing` - (Optional) Whether to enable auto-healing for the layer.
|
* `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.
|
* `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.
|
* `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.
|
* `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.
|
* `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.
|
* `use_ebs_optimized_instances` - (Optional) Whether to use EBS-optimized instances.
|
||||||
|
|
|
@ -31,6 +31,7 @@ The following arguments are supported:
|
||||||
* `auto_healing` - (Optional) Whether to enable auto-healing for the layer.
|
* `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.
|
* `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.
|
* `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.
|
* `drain_elb_on_shutdown` - (Optional) Whether to enable Elastic Load Balancing connection draining.
|
||||||
* `root_password` - (Optional) Root password to use for MySQL.
|
* `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.
|
* `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.
|
||||||
|
|
|
@ -31,6 +31,7 @@ The following arguments are supported:
|
||||||
* `auto_healing` - (Optional) Whether to enable auto-healing for the layer.
|
* `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.
|
* `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.
|
* `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.
|
* `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".
|
* `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.
|
* `system_packages` - (Optional) Names of a set of system packages to install on the layer's instances.
|
||||||
|
|
|
@ -31,6 +31,7 @@ The following arguments are supported:
|
||||||
* `auto_healing` - (Optional) Whether to enable auto-healing for the layer.
|
* `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.
|
* `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.
|
* `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.
|
* `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.
|
* `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.
|
* `use_ebs_optimized_instances` - (Optional) Whether to use EBS-optimized instances.
|
||||||
|
|
|
@ -33,6 +33,7 @@ The following arguments are supported:
|
||||||
* `auto_healing` - (Optional) Whether to enable auto-healing for the layer.
|
* `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.
|
* `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.
|
* `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.
|
* `drain_elb_on_shutdown` - (Optional) Whether to enable Elastic Load Balancing connection draining.
|
||||||
* `manage_bundler` - (Optional) Whether OpsWorks should manage bundler. On by default.
|
* `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".
|
* `passenger_version` - (Optional) The version of Passenger to use. Defaults to "4.0.46".
|
||||||
|
|
|
@ -31,6 +31,7 @@ The following arguments are supported:
|
||||||
* `auto_healing` - (Optional) Whether to enable auto-healing for the layer.
|
* `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.
|
* `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.
|
* `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.
|
* `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.
|
* `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.
|
* `use_ebs_optimized_instances` - (Optional) Whether to use EBS-optimized instances.
|
||||||
|
|
Loading…
Reference in New Issue