Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/glue_connection - Add support network connection type + disappears test #14818

Merged
merged 2 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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