Skip to content

Commit

Permalink
resource/aws_glue_connection: ConnectionProperties to be opional
Browse files Browse the repository at this point in the history
ConnectionProperties is key-value pairs, and it's not mandatory field.
  • Loading branch information
no-brand committed May 15, 2021
1 parent 4896548 commit f921a0c
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 4 deletions.
8 changes: 5 additions & 3 deletions aws/resource_aws_glue_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func resourceAwsGlueConnection() *schema.Resource {
},
"connection_properties": {
Type: schema.TypeMap,
Required: true,
Optional: true,
Sensitive: true,
ValidateFunc: MapKeyInSlice(glue.ConnectionPropertyKey_Values(), false),
Elem: &schema.Schema{Type: schema.TypeString},
Expand Down Expand Up @@ -243,8 +243,10 @@ func deleteGlueConnection(conn *glue.Glue, catalogID, connectionName string) err

func expandGlueConnectionInput(d *schema.ResourceData) *glue.ConnectionInput {
connectionProperties := make(map[string]string)
for k, v := range d.Get("connection_properties").(map[string]interface{}) {
connectionProperties[k] = v.(string)
if val, ok := d.GetOkExists("connection_properties"); ok {
for k, v := range val.(map[string]interface{}) {
connectionProperties[k] = v.(string)
}
}

connectionInput := &glue.ConnectionInput{
Expand Down
88 changes: 88 additions & 0 deletions aws/resource_aws_glue_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,40 @@ func TestAccAWSGlueConnection_Kafka(t *testing.T) {
})
}

func TestAccAWSGlueConnection_Network(t *testing.T) {
var connection glue.Connection

rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5))
resourceName := "aws_glue_connection.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, glue.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSGlueConnectionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSGlueConnectionConfig_Network(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSGlueConnectionExists(resourceName, &connection),
resource.TestCheckResourceAttr(resourceName, "connection_properties.%", "0"),
resource.TestCheckResourceAttr(resourceName, "connection_type", "NETWORK"),
resource.TestCheckResourceAttr(resourceName, "match_criteria.#", "0"),
resource.TestCheckResourceAttr(resourceName, "physical_connection_requirements.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "physical_connection_requirements.0.availability_zone"),
resource.TestCheckResourceAttr(resourceName, "physical_connection_requirements.0.security_group_id_list.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "physical_connection_requirements.0.subnet_id"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSGlueConnection_Description(t *testing.T) {
var connection glue.Connection

Expand Down Expand Up @@ -564,3 +598,57 @@ resource "aws_glue_connection" "test" {
}
`, rName)
}

func testAccAWSGlueConnectionConfig_Network(rName string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {
state = "available"
filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "terraform-testacc-glue-connection-network"
}
}
resource "aws_subnet" "test" {
availability_zone = data.aws_availability_zones.available.names[0]
cidr_block = "10.0.0.0/24"
vpc_id = aws_vpc.test.id
tags = {
Name = "terraform-testacc-glue-connection-network"
}
}
resource "aws_security_group" "test" {
name = "%[1]s"
vpc_id = aws_vpc.test.id
ingress {
protocol = "tcp"
self = true
from_port = 1
to_port = 65535
}
}
resource "aws_glue_connection" "test" {
connection_type = "NETWORK"
name = "%[1]s"
physical_connection_requirements {
availability_zone = aws_subnet.test.availability_zone
security_group_id_list = [aws_security_group.test.id]
subnet_id = aws_subnet.test.id
}
}
`, rName)
}
2 changes: 1 addition & 1 deletion website/docs/r/glue_connection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ resource "aws_glue_connection" "example" {
The following arguments are supported:

* `catalog_id` – (Optional) The ID of the Data Catalog in which to create the connection. If none is supplied, the AWS account ID is used by default.
* `connection_properties` – (Required) A map of key-value pairs used as parameters for this connection.
* `connection_properties` – (Optional) A map of key-value pairs used as parameters for this connection.
* `connection_type` – (Optional) The type of the connection. Supported are: `JDBC`, `MONGODB`, `KAFKA`, and `NETWORK`. Defaults to `JBDC`.
* `description` – (Optional) Description of the connection.
* `match_criteria` – (Optional) A list of criteria that can be used in selecting this connection.
Expand Down

0 comments on commit f921a0c

Please sign in to comment.