Skip to content

Commit

Permalink
Merge pull request #14818 from DrFaust92/r/glue_connection_type_enum
Browse files Browse the repository at this point in the history
r/glue_connection - Add support network connection type + disappears test
  • Loading branch information
breathingdust authored Sep 23, 2020
2 parents 8e1288a + 709a8c1 commit 75e63d4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
33 changes: 14 additions & 19 deletions aws/resource_aws_glue_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,10 @@ func resourceAwsGlueConnection() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
},
"connection_type": {
Type: schema.TypeString,
Optional: true,
Default: glue.ConnectionTypeJdbc,
ValidateFunc: validation.StringInSlice([]string{
glue.ConnectionTypeJdbc,
glue.ConnectionTypeSftp,
glue.ConnectionTypeMongodb,
glue.ConnectionTypeKafka,
}, false),
Type: schema.TypeString,
Optional: true,
Default: glue.ConnectionTypeJdbc,
ValidateFunc: validation.StringInSlice(glue.ConnectionType_Values(), false),
},
"description": {
Type: schema.TypeString,
Expand Down Expand Up @@ -76,7 +71,7 @@ func resourceAwsGlueConnection() *schema.Resource {
Optional: true,
},
"security_group_id_list": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
Expand Down Expand Up @@ -109,7 +104,7 @@ func resourceAwsGlueConnectionCreate(d *schema.ResourceData, meta interface{}) e
log.Printf("[DEBUG] Creating Glue Connection: %s", input)
_, err := conn.CreateConnection(input)
if err != nil {
return fmt.Errorf("error creating Glue Connection (%s): %s", name, err)
return fmt.Errorf("error creating Glue Connection (%s): %w", name, err)
}

d.SetId(fmt.Sprintf("%s:%s", catalogID, name))
Expand Down Expand Up @@ -138,7 +133,7 @@ func resourceAwsGlueConnectionRead(d *schema.ResourceData, meta interface{}) err
d.SetId("")
return nil
}
return fmt.Errorf("error reading Glue Connection (%s): %s", d.Id(), err)
return fmt.Errorf("error reading Glue Connection (%s): %w", d.Id(), err)
}

connection := output.Connection
Expand All @@ -159,16 +154,16 @@ func resourceAwsGlueConnectionRead(d *schema.ResourceData, meta interface{}) err

d.Set("catalog_id", catalogID)
if err := d.Set("connection_properties", aws.StringValueMap(connection.ConnectionProperties)); err != nil {
return fmt.Errorf("error setting connection_properties: %s", err)
return fmt.Errorf("error setting connection_properties: %w", err)
}
d.Set("connection_type", connection.ConnectionType)
d.Set("description", connection.Description)
if err := d.Set("match_criteria", flattenStringList(connection.MatchCriteria)); err != nil {
return fmt.Errorf("error setting match_criteria: %s", err)
return fmt.Errorf("error setting match_criteria: %w", err)
}
d.Set("name", connection.Name)
if err := d.Set("physical_connection_requirements", flattenGluePhysicalConnectionRequirements(connection.PhysicalConnectionRequirements)); err != nil {
return fmt.Errorf("error setting physical_connection_requirements: %s", err)
return fmt.Errorf("error setting physical_connection_requirements: %w", err)
}

return nil
Expand All @@ -191,7 +186,7 @@ func resourceAwsGlueConnectionUpdate(d *schema.ResourceData, meta interface{}) e
log.Printf("[DEBUG] Updating Glue Connection: %s", input)
_, err = conn.UpdateConnection(input)
if err != nil {
return fmt.Errorf("error updating Glue Connection (%s): %s", d.Id(), err)
return fmt.Errorf("error updating Glue Connection (%s): %w", d.Id(), err)
}

return nil
Expand All @@ -208,7 +203,7 @@ func resourceAwsGlueConnectionDelete(d *schema.ResourceData, meta interface{}) e
log.Printf("[DEBUG] Deleting Glue Connection: %s", d.Id())
err = deleteGlueConnection(conn, catalogID, connectionName)
if err != nil {
return fmt.Errorf("error deleting Glue Connection (%s): %s", d.Id(), err)
return fmt.Errorf("error deleting Glue Connection (%s): %w", d.Id(), err)
}

return nil
Expand Down Expand Up @@ -276,7 +271,7 @@ func expandGluePhysicalConnectionRequirements(m map[string]interface{}) *glue.Ph
}

if v, ok := m["security_group_id_list"]; ok {
physicalConnectionRequirements.SecurityGroupIdList = expandStringList(v.([]interface{}))
physicalConnectionRequirements.SecurityGroupIdList = expandStringSet(v.(*schema.Set))
}

if v, ok := m["subnet_id"]; ok {
Expand All @@ -293,7 +288,7 @@ func flattenGluePhysicalConnectionRequirements(physicalConnectionRequirements *g

m := map[string]interface{}{
"availability_zone": aws.StringValue(physicalConnectionRequirements.AvailabilityZone),
"security_group_id_list": flattenStringList(physicalConnectionRequirements.SecurityGroupIdList),
"security_group_id_list": flattenStringSet(physicalConnectionRequirements.SecurityGroupIdList),
"subnet_id": aws.StringValue(physicalConnectionRequirements.SubnetId),
}

Expand Down
23 changes: 23 additions & 0 deletions aws/resource_aws_glue_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,29 @@ func TestAccAWSGlueConnection_PhysicalConnectionRequirements(t *testing.T) {
})
}

func TestAccAWSGlueConnection_disappears(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) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSGlueConnectionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSGlueConnectionConfig_Required(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSGlueConnectionExists(resourceName, &connection),
testAccCheckResourceDisappears(testAccProvider, resourceAwsGlueConnection(), resourceName),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func testAccCheckAWSGlueConnectionExists(resourceName string, connection *glue.Connection) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
Expand Down
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 @@ -54,7 +54,7 @@ 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_type` – (Optional) The type of the connection. Supported are: `JDBC`, `MONGODB`, `KAFKA`. Defaults to `JBDC`.
* `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.
* `name` – (Required) The name of the connection.
Expand Down

0 comments on commit 75e63d4

Please sign in to comment.