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

f/aws_glue_crawler s3_target connection_name #15350

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
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