Skip to content

Commit

Permalink
Merge pull request #15350 from nikhil-goenka/f/aws_glue_crawler-s3-ta…
Browse files Browse the repository at this point in the history
…rget-connectionName

f/aws_glue_crawler s3_target connection_name
  • Loading branch information
gdavison authored Sep 25, 2020
2 parents 824b48c + 622f463 commit 9dac8ef
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
9 changes: 9 additions & 0 deletions aws/resource_aws_glue_crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func resourceAwsGlueCrawler() *schema.Resource {
MinItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"connection_name": {
Type: schema.TypeString,
Optional: true,
},
"path": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -411,6 +415,10 @@ func expandGlueS3Target(cfg map[string]interface{}) *glue.S3Target {
Path: aws.String(cfg["path"].(string)),
}

if connection, ok := cfg["connection_name"]; ok {
target.ConnectionName = aws.String(connection.(string))
}

if exclusions, ok := cfg["exclusions"]; ok {
target.Exclusions = expandStringList(exclusions.([]interface{}))
}
Expand Down Expand Up @@ -604,6 +612,7 @@ func flattenGlueS3Targets(s3Targets []*glue.S3Target) []map[string]interface{} {
attrs := make(map[string]interface{})
attrs["exclusions"] = flattenStringList(s3Target.Exclusions)
attrs["path"] = aws.StringValue(s3Target.Path)
attrs["connection_name"] = aws.StringValue(s3Target.ConnectionName)

result = append(result, attrs)
}
Expand Down
107 changes: 107 additions & 0 deletions aws/resource_aws_glue_crawler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,35 @@ func TestAccAWSGlueCrawler_S3Target(t *testing.T) {
})
}

func TestAccAWSGlueCrawler_S3Target_ConnectionName(t *testing.T) {
var crawler glue.Crawler
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_glue_crawler.test"
connectionName := "aws_glue_connection.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSGlueCrawlerDestroy,
Steps: []resource.TestStep{
{
Config: testAccGlueCrawlerConfig_S3Target_ConnectionName(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSGlueCrawlerExists(resourceName, &crawler),
testAccCheckResourceAttrRegionalARN(resourceName, "arn", "glue", fmt.Sprintf("crawler/%s", rName)),
resource.TestCheckResourceAttr(resourceName, "s3_target.#", "1"),
resource.TestCheckResourceAttrPair(resourceName, "s3_target.0.connection_name", connectionName, "name"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSGlueCrawler_S3Target_Exclusions(t *testing.T) {
var crawler glue.Crawler
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -1679,6 +1708,84 @@ resource "aws_glue_crawler" "test" {
`, rName, rName, exclusion1)
}

func testAccGlueCrawlerConfig_S3Target_ConnectionName(rName string) string {
return testAccGlueCrawlerConfig_Base(rName) + 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-base"
}
}
resource "aws_security_group" "test" {
name = "%[1]s"
vpc_id = aws_vpc.test.id
ingress {
from_port = 1
protocol = "tcp"
self = true
to_port = 65535
}
}
resource "aws_subnet" "test" {
count = 2
availability_zone = data.aws_availability_zones.available.names[count.index]
cidr_block = "10.0.${count.index}.0/24"
vpc_id = aws_vpc.test.id
tags = {
Name = "terraform-testacc-glue-connection-base"
}
}
resource "aws_glue_catalog_database" "test" {
name = "%[1]s"
}
resource "aws_glue_connection" "test" {
connection_properties = {
JDBC_ENFORCE_SSL = false
}
connection_type = "NETWORK"
name = "%[1]s"
physical_connection_requirements {
availability_zone = aws_subnet.test[0].availability_zone
security_group_id_list = [aws_security_group.test.id]
subnet_id = aws_subnet.test[0].id
}
}
resource "aws_glue_crawler" "test" {
depends_on = [aws_iam_role_policy_attachment.test-AWSGlueServiceRole]
database_name = aws_glue_catalog_database.test.name
name = "%[1]s"
role = aws_iam_role.test.name
s3_target {
connection_name = aws_glue_connection.test.name
path = "s3://bucket1"
}
}
`, rName)
}

func testAccGlueCrawlerConfig_S3Target_Exclusions2(rName, exclusion1, exclusion2 string) string {
return testAccGlueCrawlerConfig_Base(rName) + fmt.Sprintf(`
resource "aws_glue_catalog_database" "test" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/glue_crawler.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ The following arguments are supported:
### s3_target Argument Reference

* `path` - (Required) The path to the Amazon S3 target.
* `connection_name` - (Optional) The name of a connection which allows crawler to access data in S3 within a VPC.
* `exclusions` - (Optional) A list of glob patterns used to exclude from the crawl.

### catalog_target Argument Reference
Expand Down

0 comments on commit 9dac8ef

Please sign in to comment.