From 41a8220e0fa821b748fb1fdfaa513d73f4f2f13c Mon Sep 17 00:00:00 2001 From: Jeff Tang Date: Fri, 11 Dec 2015 15:14:11 -0500 Subject: [PATCH] add custom_json for opsworks layers --- builtin/providers/aws/opsworks_layers.go | 22 +++++++++++++++++++ ...resource_aws_opsworks_custom_layer_test.go | 4 ++++ .../aws/r/opsworks_custom_layer.html.markdown | 1 + .../r/opsworks_ganglia_layer.html.markdown | 1 + .../r/opsworks_haproxy_layer.html.markdown | 1 + .../r/opsworks_java_app_layer.html.markdown | 1 + .../r/opsworks_memcached_layer.html.markdown | 1 + .../aws/r/opsworks_mysql_layer.html.markdown | 1 + .../r/opsworks_nodejs_app_layer.html.markdown | 1 + .../r/opsworks_php_app_layer.html.markdown | 1 + .../r/opsworks_rails_app_layer.html.markdown | 1 + .../aws/r/opsworks_stack.html.markdown | 1 + 12 files changed, 36 insertions(+) diff --git a/builtin/providers/aws/opsworks_layers.go b/builtin/providers/aws/opsworks_layers.go index 6eb6d1bdd..1b0800348 100644 --- a/builtin/providers/aws/opsworks_layers.go +++ b/builtin/providers/aws/opsworks_layers.go @@ -109,6 +109,12 @@ func (lt *opsworksLayerType) SchemaResource() *schema.Resource { Set: schema.HashString, }, + "custom_json": &schema.Schema{ + Type: schema.TypeString, + StateFunc: normalizeJson, + Optional: true, + }, + "auto_healing": &schema.Schema{ Type: schema.TypeBool, Optional: true, @@ -288,6 +294,14 @@ func (lt *opsworksLayerType) Read(d *schema.ResourceData, client *opsworks.OpsWo d.Set("short_name", layer.Shortname) } + if v := layer.CustomJson; v == nil { + if err := d.Set("custom_json", ""); err != nil { + return err + } + } else if err := d.Set("custom_json", normalizeJson(*v)); err != nil { + return err + } + lt.SetAttributeMap(d, layer.Attributes) lt.SetLifecycleEventConfiguration(d, layer.LifecycleEventConfiguration) lt.SetCustomRecipes(d, layer.CustomRecipes) @@ -342,6 +356,10 @@ func (lt *opsworksLayerType) Create(d *schema.ResourceData, client *opsworks.Ops req.Shortname = aws.String(lt.TypeName) } + if customJson, ok := d.GetOk("custom_json"); ok { + req.CustomJson = aws.String(customJson.(string)) + } + log.Printf("[DEBUG] Creating OpsWorks layer: %s", d.Id()) resp, err := client.CreateLayer(req) @@ -393,6 +411,10 @@ func (lt *opsworksLayerType) Update(d *schema.ResourceData, client *opsworks.Ops req.Shortname = aws.String(lt.TypeName) } + if customJson, ok := d.GetOk("custom_json"); ok { + req.CustomJson = aws.String(customJson.(string)) + } + log.Printf("[DEBUG] Updating OpsWorks layer: %s", d.Id()) if d.HasChange("elastic_load_balancer") { diff --git a/builtin/providers/aws/resource_aws_opsworks_custom_layer_test.go b/builtin/providers/aws/resource_aws_opsworks_custom_layer_test.go index 7dcff04ff..4df719484 100644 --- a/builtin/providers/aws/resource_aws_opsworks_custom_layer_test.go +++ b/builtin/providers/aws/resource_aws_opsworks_custom_layer_test.go @@ -129,6 +129,9 @@ func TestAccAWSOpsworksCustomLayer(t *testing.T) { resource.TestCheckResourceAttr( "aws_opsworks_custom_layer.tf-acc", "ebs_volume.1266957920.iops", "3000", ), + resource.TestCheckResourceAttr( + "aws_opsworks_custom_layer.tf-acc", "custom_json", `{"layer_key":"layer_value2"}`, + ), ), }, }, @@ -268,6 +271,7 @@ resource "aws_opsworks_custom_layer" "tf-acc" { raid_level = 1 iops = 3000 } + custom_json = "{\"layer_key\": \"layer_value2\"}" } %s diff --git a/website/source/docs/providers/aws/r/opsworks_custom_layer.html.markdown b/website/source/docs/providers/aws/r/opsworks_custom_layer.html.markdown index 7f04202d4..b43ce8a2d 100644 --- a/website/source/docs/providers/aws/r/opsworks_custom_layer.html.markdown +++ b/website/source/docs/providers/aws/r/opsworks_custom_layer.html.markdown @@ -39,6 +39,7 @@ The following arguments are supported: * `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. * `ebs_volume` - (Optional) `ebs_volume` blocks, as described below, will each create an EBS volume and connect it to the layer's instances. +* `custom_json` - (Optional) Custom JSON attributes to apply to the layer. The following extra optional arguments, all lists of Chef recipe names, allow custom Chef recipes to be applied to layer instances at the five different diff --git a/website/source/docs/providers/aws/r/opsworks_ganglia_layer.html.markdown b/website/source/docs/providers/aws/r/opsworks_ganglia_layer.html.markdown index 29c8fc68e..3425eb196 100644 --- a/website/source/docs/providers/aws/r/opsworks_ganglia_layer.html.markdown +++ b/website/source/docs/providers/aws/r/opsworks_ganglia_layer.html.markdown @@ -40,6 +40,7 @@ The following arguments are supported: * `username` - (Optiona) The username to use for Ganglia. Defaults to "opsworks". * `use_ebs_optimized_instances` - (Optional) Whether to use EBS-optimized instances. * `ebs_volume` - (Optional) `ebs_volume` blocks, as described below, will each create an EBS volume and connect it to the layer's instances. +* `custom_json` - (Optional) Custom JSON attributes to apply to the layer. The following extra optional arguments, all lists of Chef recipe names, allow custom Chef recipes to be applied to layer instances at the five different diff --git a/website/source/docs/providers/aws/r/opsworks_haproxy_layer.html.markdown b/website/source/docs/providers/aws/r/opsworks_haproxy_layer.html.markdown index 68b54a646..baeff6172 100644 --- a/website/source/docs/providers/aws/r/opsworks_haproxy_layer.html.markdown +++ b/website/source/docs/providers/aws/r/opsworks_haproxy_layer.html.markdown @@ -43,6 +43,7 @@ The following arguments are supported: * `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. * `ebs_volume` - (Optional) `ebs_volume` blocks, as described below, will each create an EBS volume and connect it to the layer's instances. +* `custom_json` - (Optional) Custom JSON attributes to apply to the layer. The following extra optional arguments, all lists of Chef recipe names, allow custom Chef recipes to be applied to layer instances at the five different diff --git a/website/source/docs/providers/aws/r/opsworks_java_app_layer.html.markdown b/website/source/docs/providers/aws/r/opsworks_java_app_layer.html.markdown index 0463fbba7..7d4b3eb23 100644 --- a/website/source/docs/providers/aws/r/opsworks_java_app_layer.html.markdown +++ b/website/source/docs/providers/aws/r/opsworks_java_app_layer.html.markdown @@ -41,6 +41,7 @@ The following arguments are supported: * `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. * `ebs_volume` - (Optional) `ebs_volume` blocks, as described below, will each create an EBS volume and connect it to the layer's instances. +* `custom_json` - (Optional) Custom JSON attributes to apply to the layer. The following extra optional arguments, all lists of Chef recipe names, allow custom Chef recipes to be applied to layer instances at the five different diff --git a/website/source/docs/providers/aws/r/opsworks_memcached_layer.html.markdown b/website/source/docs/providers/aws/r/opsworks_memcached_layer.html.markdown index 31d472806..fcbcf16f8 100644 --- a/website/source/docs/providers/aws/r/opsworks_memcached_layer.html.markdown +++ b/website/source/docs/providers/aws/r/opsworks_memcached_layer.html.markdown @@ -37,6 +37,7 @@ The following arguments are supported: * `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. * `ebs_volume` - (Optional) `ebs_volume` blocks, as described below, will each create an EBS volume and connect it to the layer's instances. +* `custom_json` - (Optional) Custom JSON attributes to apply to the layer. The following extra optional arguments, all lists of Chef recipe names, allow custom Chef recipes to be applied to layer instances at the five different diff --git a/website/source/docs/providers/aws/r/opsworks_mysql_layer.html.markdown b/website/source/docs/providers/aws/r/opsworks_mysql_layer.html.markdown index 0cc11b73f..850338686 100644 --- a/website/source/docs/providers/aws/r/opsworks_mysql_layer.html.markdown +++ b/website/source/docs/providers/aws/r/opsworks_mysql_layer.html.markdown @@ -38,6 +38,7 @@ The following arguments are supported: * `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. * `ebs_volume` - (Optional) `ebs_volume` blocks, as described below, will each create an EBS volume and connect it to the layer's instances. +* `custom_json` - (Optional) Custom JSON attributes to apply to the layer. The following extra optional arguments, all lists of Chef recipe names, allow custom Chef recipes to be applied to layer instances at the five different diff --git a/website/source/docs/providers/aws/r/opsworks_nodejs_app_layer.html.markdown b/website/source/docs/providers/aws/r/opsworks_nodejs_app_layer.html.markdown index ea0fdeb9b..e9ab9d597 100644 --- a/website/source/docs/providers/aws/r/opsworks_nodejs_app_layer.html.markdown +++ b/website/source/docs/providers/aws/r/opsworks_nodejs_app_layer.html.markdown @@ -37,6 +37,7 @@ The following arguments are supported: * `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. * `ebs_volume` - (Optional) `ebs_volume` blocks, as described below, will each create an EBS volume and connect it to the layer's instances. +* `custom_json` - (Optional) Custom JSON attributes to apply to the layer. The following extra optional arguments, all lists of Chef recipe names, allow custom Chef recipes to be applied to layer instances at the five different diff --git a/website/source/docs/providers/aws/r/opsworks_php_app_layer.html.markdown b/website/source/docs/providers/aws/r/opsworks_php_app_layer.html.markdown index 7d5d8ab8f..8335c4154 100644 --- a/website/source/docs/providers/aws/r/opsworks_php_app_layer.html.markdown +++ b/website/source/docs/providers/aws/r/opsworks_php_app_layer.html.markdown @@ -36,6 +36,7 @@ The following arguments are supported: * `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. * `ebs_volume` - (Optional) `ebs_volume` blocks, as described below, will each create an EBS volume and connect it to the layer's instances. +* `custom_json` - (Optional) Custom JSON attributes to apply to the layer. The following extra optional arguments, all lists of Chef recipe names, allow custom Chef recipes to be applied to layer instances at the five different diff --git a/website/source/docs/providers/aws/r/opsworks_rails_app_layer.html.markdown b/website/source/docs/providers/aws/r/opsworks_rails_app_layer.html.markdown index 27ea7a979..3d2c10fb5 100644 --- a/website/source/docs/providers/aws/r/opsworks_rails_app_layer.html.markdown +++ b/website/source/docs/providers/aws/r/opsworks_rails_app_layer.html.markdown @@ -42,6 +42,7 @@ The following arguments are supported: * `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. * `ebs_volume` - (Optional) `ebs_volume` blocks, as described below, will each create an EBS volume and connect it to the layer's instances. +* `custom_json` - (Optional) Custom JSON attributes to apply to the layer. The following extra optional arguments, all lists of Chef recipe names, allow custom Chef recipes to be applied to layer instances at the five different diff --git a/website/source/docs/providers/aws/r/opsworks_stack.html.markdown b/website/source/docs/providers/aws/r/opsworks_stack.html.markdown index d664ca1a9..b55fa9dff 100644 --- a/website/source/docs/providers/aws/r/opsworks_stack.html.markdown +++ b/website/source/docs/providers/aws/r/opsworks_stack.html.markdown @@ -51,6 +51,7 @@ The following arguments are supported: * `use_opsworks_security_groups` - (Optional) Boolean value controlling whether the standard OpsWorks security groups apply to created instances. * `vpc_id` - (Optional) The id of the VPC that this stack belongs to. +* `custom_json` - (Optional) Custom JSON attributes to apply to the entire stack. The `custom_cookbooks_source` block supports the following arguments: