Resource: aws_glue_connection

Provides a Glue Connection resource.

Example Usage

Non-VPC Connection

resource "aws_glue_connection" "example" {
  connection_properties = {
    JDBC_CONNECTION_URL = "jdbc:mysql://example.com/exampledatabase"
    PASSWORD            = "examplepassword"
    USERNAME            = "exampleusername"
  }

  name = "example"
}

Non-VPC Connection with secret manager reference

data "aws_secretmanager_secret" "example" {
  name = "example-secret"
}

resource "aws_glue_connection" "example" {
  connection_properties = {
    JDBC_CONNECTION_URL = "jdbc:mysql://example.com/exampledatabase"
    SECRET_ID           = data.aws_secretmanager_secret.example.name
  }

  name = "example"
}

VPC Connection

For more information, see the AWS Documentation.

resource "aws_glue_connection" "example" {
  connection_properties = {
    JDBC_CONNECTION_URL = "jdbc:mysql://${aws_rds_cluster.example.endpoint}/exampledatabase"
    PASSWORD            = "examplepassword"
    USERNAME            = "exampleusername"
  }

  name = "example"

  physical_connection_requirements {
    availability_zone      = aws_subnet.example.availability_zone
    security_group_id_list = [aws_security_group.example.id]
    subnet_id              = aws_subnet.example.id
  }
}

Connection using a custom connector

# Define the custom connector using the connection_type of `CUSTOM` with the match_criteria of `template_connection`
# Example here being a snowflake jdbc connector with a secret having user and password as keys

data "aws_secretmanager_secret" "example" {
  name = "example-secret"
}

resource "aws_glue_connection" "example_connector" {
  connection_type = "CUSTOM"

  connection_properties = {
    CONNECTOR_CLASS_NAME = "net.snowflake.client.jdbc.SnowflakeDriver"
    CONNECTION_TYPE      = "Jdbc"
    CONNECTOR_URL        = "s3://example/snowflake-jdbc.jar" # S3 path to the snowflake jdbc jar
    JDBC_CONNECTION_URL  = "[[\"default=jdbc:snowflake://example.com/?user=$${user}&password=$${password}\"],\",\"]"
  }

  name = "example_connector"

  match_criteria = ["template-connection"]
}

# Reference the connector using match_criteria with the connector created above.

resource "aws_glue_connection" "example_connection" {
  connection_type = "CUSTOM"

  connection_properties = {
    CONNECTOR_CLASS_NAME = "net.snowflake.client.jdbc.SnowflakeDriver"
    CONNECTION_TYPE      = "Jdbc"
    CONNECTOR_URL        = "s3://example/snowflake-jdbc.jar"
    JDBC_CONNECTION_URL  = "jdbc:snowflake://example.com/?user=$${user}&password=$${password}"
    SECRET_ID            = data.aws_secretmanager_secret.example.name
  }
  name           = "example"
  match_criteria = ["Connection", aws_glue_connection.example_connector.name]
}

Argument Reference

This resource supports the following arguments:

physical_connection_requirements

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Import

In Terraform v1.5.0 and later, use an import block to import Glue Connections using the CATALOG-ID (AWS account ID if not custom) and NAME. For example:

import {
  to = aws_glue_connection.MyConnection
  id = "123456789012:MyConnection"
}

Using terraform import, import Glue Connections using the CATALOG-ID (AWS account ID if not custom) and NAME. For example:

% terraform import aws_glue_connection.MyConnection 123456789012:MyConnection