From 7bc7a8e8fea13edaf0f877f6d644ed3604de8387 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Wed, 14 Feb 2018 09:54:29 +0000 Subject: [PATCH] resource/aws_dx_lag: Deprecate number_of_connections --- ...ource_aws_dx_connection_association_test.go | 2 -- aws/resource_aws_dx_lag.go | 18 +++++++++++++++--- aws/resource_aws_dx_lag_test.go | 5 ----- website/docs/r/dx_lag.html.markdown | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/aws/resource_aws_dx_connection_association_test.go b/aws/resource_aws_dx_connection_association_test.go index 504d43b4b39..f502640be16 100644 --- a/aws/resource_aws_dx_connection_association_test.go +++ b/aws/resource_aws_dx_connection_association_test.go @@ -92,7 +92,6 @@ resource "aws_dx_lag" "test" { name = "tf-dx-%s" connections_bandwidth = "1Gbps" location = "EqSe2" - number_of_connections = 1 force_destroy = true } @@ -121,7 +120,6 @@ resource "aws_dx_lag" "test" { name = "tf-dx-%s" connections_bandwidth = "1Gbps" location = "EqSe2" - number_of_connections = 1 force_destroy = true } diff --git a/aws/resource_aws_dx_lag.go b/aws/resource_aws_dx_lag.go index 7aba3410405..e0e6bd3861c 100644 --- a/aws/resource_aws_dx_lag.go +++ b/aws/resource_aws_dx_lag.go @@ -41,8 +41,11 @@ func resourceAwsDxLag() *schema.Resource { }, "number_of_connections": { Type: schema.TypeInt, - Required: true, + Optional: true, + Computed: true, ForceNew: true, + Deprecated: "Use aws_dx_connection and aws_dx_connection_association resources instead. " + + "Default connections will be removed as part of LAG creation automatically in future versions.", }, "force_destroy": { Type: schema.TypeBool, @@ -57,11 +60,18 @@ func resourceAwsDxLag() *schema.Resource { func resourceAwsDxLagCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).dxconn + var noOfConnections int + if v, ok := d.GetOk("number_of_connections"); ok { + noOfConnections = v.(int) + } else { + noOfConnections = 1 + } + req := &directconnect.CreateLagInput{ ConnectionsBandwidth: aws.String(d.Get("connections_bandwidth").(string)), LagName: aws.String(d.Get("name").(string)), Location: aws.String(d.Get("location").(string)), - NumberOfConnections: aws.Int64(int64(d.Get("number_of_connections").(int))), + NumberOfConnections: aws.Int64(int64(noOfConnections)), } log.Printf("[DEBUG] Creating Direct Connect LAG: %#v", req) @@ -70,6 +80,9 @@ func resourceAwsDxLagCreate(d *schema.ResourceData, meta interface{}) error { return err } + // TODO: Remove default connection(s) automatically provisioned by AWS + // per NumberOfConnections + d.SetId(aws.StringValue(resp.LagId)) return resourceAwsDxLagUpdate(d, meta) } @@ -119,7 +132,6 @@ func resourceAwsDxLagRead(d *schema.ResourceData, meta interface{}) error { d.Set("name", lag.LagName) d.Set("connections_bandwidth", lag.ConnectionsBandwidth) d.Set("location", lag.Location) - d.Set("number_of_connections", lag.NumberOfConnections) if err := getTagsDX(conn, d, arn); err != nil { return err diff --git a/aws/resource_aws_dx_lag_test.go b/aws/resource_aws_dx_lag_test.go index 54f4581647f..981e64f6f60 100644 --- a/aws/resource_aws_dx_lag_test.go +++ b/aws/resource_aws_dx_lag_test.go @@ -27,7 +27,6 @@ func TestAccAwsDxLag_basic(t *testing.T) { resource.TestCheckResourceAttr("aws_dx_lag.hoge", "name", lagName1), resource.TestCheckResourceAttr("aws_dx_lag.hoge", "connections_bandwidth", "1Gbps"), resource.TestCheckResourceAttr("aws_dx_lag.hoge", "location", "EqSe2"), - resource.TestCheckResourceAttr("aws_dx_lag.hoge", "number_of_connections", "2"), resource.TestCheckResourceAttr("aws_dx_lag.hoge", "tags.%", "0"), ), }, @@ -38,7 +37,6 @@ func TestAccAwsDxLag_basic(t *testing.T) { resource.TestCheckResourceAttr("aws_dx_lag.hoge", "name", lagName2), resource.TestCheckResourceAttr("aws_dx_lag.hoge", "connections_bandwidth", "1Gbps"), resource.TestCheckResourceAttr("aws_dx_lag.hoge", "location", "EqSe2"), - resource.TestCheckResourceAttr("aws_dx_lag.hoge", "number_of_connections", "2"), resource.TestCheckResourceAttr("aws_dx_lag.hoge", "tags.%", "0"), ), }, @@ -127,7 +125,6 @@ resource "aws_dx_lag" "hoge" { name = "%s" connections_bandwidth = "1Gbps" location = "EqSe2" - number_of_connections = 2 force_destroy = true } `, n) @@ -139,7 +136,6 @@ resource "aws_dx_lag" "hoge" { name = "%s" connections_bandwidth = "1Gbps" location = "EqSe2" - number_of_connections = 2 force_destroy = true tags { @@ -156,7 +152,6 @@ resource "aws_dx_lag" "hoge" { name = "%s" connections_bandwidth = "1Gbps" location = "EqSe2" - number_of_connections = 2 force_destroy = true tags { diff --git a/website/docs/r/dx_lag.html.markdown b/website/docs/r/dx_lag.html.markdown index 27c91d745c5..fcac8f1f092 100644 --- a/website/docs/r/dx_lag.html.markdown +++ b/website/docs/r/dx_lag.html.markdown @@ -29,7 +29,7 @@ The following arguments are supported: * `name` - (Required) The name of the LAG. * `connections_bandwidth` - (Required) The bandwidth of the individual physical connections bundled by the LAG. Available values: 1Gbps, 10Gbps. Case sensitive. * `location` - (Required) The AWS Direct Connect location in which the LAG should be allocated. See [DescribeLocations](https://docs.aws.amazon.com/directconnect/latest/APIReference/API_DescribeLocations.html) for the list of AWS Direct Connect locations. Use `locationCode`. -* `number_of_connections` - (Required) The number of physical connections initially provisioned and bundled by the LAG. +* `number_of_connections` - (**Deprecated**) The number of physical connections initially provisioned and bundled by the LAG. Use `aws_dx_connection` and `aws_dx_connection_association` resources instead. Default connections will be removed as part of LAG creation automatically in future versions. * `force_destroy` - (Optional, Default:false) A boolean that indicates all connections associated with the LAG should be deleted so that the LAG can be destroyed without error. These objects are *not* recoverable. * `tags` - (Optional) A mapping of tags to assign to the resource.