From f72d07b423695e43556640b30363d206c3c434bb Mon Sep 17 00:00:00 2001 From: danu165 Date: Fri, 9 Apr 2021 08:34:29 -0700 Subject: [PATCH 1/8] Add data source for aws_glue_connection --- aws/data_source_aws_glue_connection.go | 62 +++++++++++++++++++ aws/data_source_aws_glue_connection_test.go | 61 ++++++++++++++++++ ...s_glue_data_catalog_encryption_settings.go | 1 + ...e_data_catalog_encryption_settings_test.go | 1 + aws/provider.go | 1 + 5 files changed, 126 insertions(+) create mode 100644 aws/data_source_aws_glue_connection.go create mode 100644 aws/data_source_aws_glue_connection_test.go create mode 100644 aws/data_source_aws_glue_data_catalog_encryption_settings.go create mode 100644 aws/data_source_aws_glue_data_catalog_encryption_settings_test.go diff --git a/aws/data_source_aws_glue_connection.go b/aws/data_source_aws_glue_connection.go new file mode 100644 index 00000000000..8b44c9f84e9 --- /dev/null +++ b/aws/data_source_aws_glue_connection.go @@ -0,0 +1,62 @@ +package aws + +import ( + "context" + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/glue" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func dataSourceAwsGlueConnection() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceAwsGlueConnectionRead, + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.NoZeroValues, + }, + "catalog_id": { + Type: schema.TypeString, + Computed: true, + }, + "creation_time": { + Type: schema.TypeString, + Computed: true, + }, + "connection_type": { + Type: schema.TypeString, + Computed: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func dataSourceAwsGlueConnectionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*AWSClient).glueconn + catalogID, connectionName, err := decodeGlueConnectionID(d.Id()) + input := &glue.GetConnectionInput{ + CatalogId: aws.String(catalogID), + Name: aws.String(connectionName), + } + output, err := conn.GetConnection(input) + if err != nil { + if isAWSErr(err, glue.ErrCodeEntityNotFoundException, "") { + return diag.Errorf("error Glue Connection (%s) not found", d.Id()) + } + return diag.Errorf("error reading Glue Connection (%s): %s", d.Id(), err) + } + d.Set("catalog_id", catalogID) + d.Set("creation_time", aws.TimeValue(output.Connection.CreationTime).Format(time.RFC3339)) + d.Set("connection_type", output.Connection.ConnectionType) + d.Set("name", connectionName) + return nil +} diff --git a/aws/data_source_aws_glue_connection_test.go b/aws/data_source_aws_glue_connection_test.go new file mode 100644 index 00000000000..13f10f17401 --- /dev/null +++ b/aws/data_source_aws_glue_connection_test.go @@ -0,0 +1,61 @@ +package aws + +import ( + "fmt" + "testing" + + "github.com/aws/aws-sdk-go/service/glue" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccDataSourceAwsGlueConnection_basic(t *testing.T) { + resourceName := "aws_glue_connection.test" + datasourceName := "data.aws_glue_connection.test" + rName := fmt.Sprintf("tf-testacc-glue-connection-%s", acctest.RandString(13)) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, glue.EndpointsID), + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAwsGlueConnectionConfig(rName), + Check: resource.ComposeTestCheckFunc( + testAccDataSourceAwsGlueConnectionCheck(datasourceName), + resource.TestCheckResourceAttrPair(datasourceName, "catalog_id", resourceName, "catalog_id"), + resource.TestCheckResourceAttrPair(datasourceName, "creation_time", resourceName, "creation_time"), + resource.TestCheckResourceAttrPair(datasourceName, "connection_type", resourceName, "connection_type"), + resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"), + ), + }, + }, + }) +} + +func testAccDataSourceAwsGlueConnectionCheck(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + _, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("root module has no resource called %s", name) + } + + return nil + } +} + +func testAccDataSourceAwsGlueConnectionConfig(rName string) string { + return fmt.Sprintf(` +resource "aws_glue_connection" "test" { + name = %[1]q + connection_type = "NETWORK" + connection_properties = {} + +} + +data "aws_glue_connection" "test" { + id = aws_glue_connection.test.id +} +`, rName) +} diff --git a/aws/data_source_aws_glue_data_catalog_encryption_settings.go b/aws/data_source_aws_glue_data_catalog_encryption_settings.go new file mode 100644 index 00000000000..a1f9c0e3beb --- /dev/null +++ b/aws/data_source_aws_glue_data_catalog_encryption_settings.go @@ -0,0 +1 @@ +package aws diff --git a/aws/data_source_aws_glue_data_catalog_encryption_settings_test.go b/aws/data_source_aws_glue_data_catalog_encryption_settings_test.go new file mode 100644 index 00000000000..a1f9c0e3beb --- /dev/null +++ b/aws/data_source_aws_glue_data_catalog_encryption_settings_test.go @@ -0,0 +1 @@ +package aws diff --git a/aws/provider.go b/aws/provider.go index 27bf36d6f01..18e9ee4f5c6 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -284,6 +284,7 @@ func Provider() *schema.Provider { "aws_elasticache_replication_group": dataSourceAwsElasticacheReplicationGroup(), "aws_elb_hosted_zone_id": dataSourceAwsElbHostedZoneId(), "aws_elb_service_account": dataSourceAwsElbServiceAccount(), + "aws_glue_connection": dataSourceAwsGlueConnection(), "aws_glue_script": dataSourceAwsGlueScript(), "aws_guardduty_detector": dataSourceAwsGuarddutyDetector(), "aws_iam_account_alias": dataSourceAwsIamAccountAlias(), From 5f541f5232ce05cbb430acd91bf1d83169e34d42 Mon Sep 17 00:00:00 2001 From: danu165 Date: Mon, 12 Apr 2021 10:11:25 -0700 Subject: [PATCH 2/8] Add data source for aws_glue_data_catalog_encryption_settings --- ...s_glue_data_catalog_encryption_settings.go | 55 ++++++++++++++++ ...e_data_catalog_encryption_settings_test.go | 63 +++++++++++++++++++ aws/provider.go | 1 + 3 files changed, 119 insertions(+) diff --git a/aws/data_source_aws_glue_data_catalog_encryption_settings.go b/aws/data_source_aws_glue_data_catalog_encryption_settings.go index a1f9c0e3beb..6a1f59f548d 100644 --- a/aws/data_source_aws_glue_data_catalog_encryption_settings.go +++ b/aws/data_source_aws_glue_data_catalog_encryption_settings.go @@ -1 +1,56 @@ package aws + +import ( + "context" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/glue" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func dataSourceAwsGlueDataCatalogEncryptionSettings() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceAwsGlueDataCatalogEncryptionSettingsRead, + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.NoZeroValues, + }, + "connection_password_encrypted": { + Type: schema.TypeBool, + Computed: true, + }, + "connection_password_kms_key_arn": { + Type: schema.TypeString, + Computed: true, + }, + "encryption_mode": { + Type: schema.TypeString, + Computed: true, + }, + "encryption_kms_key_arn": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func dataSourceAwsGlueDataCatalogEncryptionSettingsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*AWSClient).glueconn + input := &glue.GetDataCatalogEncryptionSettingsInput{ + CatalogId: aws.String(d.Id()), + } + out, err := conn.GetDataCatalogEncryptionSettings(input) + if err != nil { + return diag.Errorf("Error reading Glue Data Catalog Encryption Settings: %s", err) + } + d.SetId(d.Id()) + d.Set("connection_password_encrypted", out.DataCatalogEncryptionSettings.ConnectionPasswordEncryption.ReturnConnectionPasswordEncrypted) + d.Set("connection_password_kms_key_arn", out.DataCatalogEncryptionSettings.ConnectionPasswordEncryption.AwsKmsKeyId) + d.Set("encryption_mode", out.DataCatalogEncryptionSettings.EncryptionAtRest.CatalogEncryptionMode) + d.Set("connection_password_encrypted", out.DataCatalogEncryptionSettings.EncryptionAtRest.SseAwsKmsKeyId) + return nil +} diff --git a/aws/data_source_aws_glue_data_catalog_encryption_settings_test.go b/aws/data_source_aws_glue_data_catalog_encryption_settings_test.go index a1f9c0e3beb..b7691e0c462 100644 --- a/aws/data_source_aws_glue_data_catalog_encryption_settings_test.go +++ b/aws/data_source_aws_glue_data_catalog_encryption_settings_test.go @@ -1 +1,64 @@ package aws + +import ( + "fmt" + "testing" + + "github.com/aws/aws-sdk-go/service/glue" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccDataSourceAwsGlueDataCatalogEncryptionSettings_basic(t *testing.T) { + resourceName := "aws_glue_data_catalog_encryption_settings.test" + datasourceName := "data.aws_glue_data_catalog_encryption_settings.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, glue.EndpointsID), + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAwsGlueDataCatalogEncryptionSettingsConfig(), + Check: resource.ComposeTestCheckFunc( + testAccDataSourceAwsGlueDataCatalogEncryptionSettingsCheck(datasourceName), + resource.TestCheckResourceAttrPair(datasourceName, "connection_password_encrypted", resourceName, "connection_password_encrypted"), + resource.TestCheckResourceAttrPair(datasourceName, "connection_password_kms_key_arn", resourceName, "connection_password_kms_key_arn"), + resource.TestCheckResourceAttrPair(datasourceName, "encryption_mode", resourceName, "encryption_mode"), + resource.TestCheckResourceAttrPair(datasourceName, "connection_password_encrypted", resourceName, "connection_password_encrypted"), + ), + }, + }, + }) +} + +func testAccDataSourceAwsGlueDataCatalogEncryptionSettingsCheck(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + _, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("root module has no resource called %s", name) + } + + return nil + } +} + +func testAccDataSourceAwsGlueDataCatalogEncryptionSettingsConfig() string { + return ` +resource "aws_glue_data_catalog_encryption_settings" "test" { + data_catalog_encryption_settings { + connection_password_encryption { + return_connection_password_encrypted = false + } + + encryption_at_rest { + catalog_encryption_mode = "DISABLED" + } + } +} + +data "aws_glue_data_catalog_encryption_settings" "test" { + id = aws_glue_data_catalog_encryption_settings.test.id +} +` +} diff --git a/aws/provider.go b/aws/provider.go index 18e9ee4f5c6..fd8738c65da 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -285,6 +285,7 @@ func Provider() *schema.Provider { "aws_elb_hosted_zone_id": dataSourceAwsElbHostedZoneId(), "aws_elb_service_account": dataSourceAwsElbServiceAccount(), "aws_glue_connection": dataSourceAwsGlueConnection(), + "aws_glue_data_catalog_encryption_settings": dataSourceAwsGlueDataCatalogEncryptionSettings(), "aws_glue_script": dataSourceAwsGlueScript(), "aws_guardduty_detector": dataSourceAwsGuarddutyDetector(), "aws_iam_account_alias": dataSourceAwsIamAccountAlias(), From 651972e40f5af65b4c53d448e5ffa50c5b4981e6 Mon Sep 17 00:00:00 2001 From: danu165 Date: Mon, 12 Apr 2021 11:05:21 -0700 Subject: [PATCH 3/8] Add changelog --- .changelog/18802.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changelog/18802.txt diff --git a/.changelog/18802.txt b/.changelog/18802.txt new file mode 100644 index 00000000000..33a0666a172 --- /dev/null +++ b/.changelog/18802.txt @@ -0,0 +1,7 @@ +```release-note:new-data-source +aws_glue_connection +``` + +```release-note:new-data-source +aws_glue_connection +``` \ No newline at end of file From 8ad215c09c2ad1db8c8dc26edf967a36dd0edc30 Mon Sep 17 00:00:00 2001 From: danu165 Date: Mon, 12 Apr 2021 11:15:56 -0700 Subject: [PATCH 4/8] Fix linting --- aws/data_source_aws_glue_connection.go | 3 +++ aws/data_source_aws_glue_connection_test.go | 1 - aws/data_source_aws_glue_data_catalog_encryption_settings.go | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/aws/data_source_aws_glue_connection.go b/aws/data_source_aws_glue_connection.go index 8b44c9f84e9..c12b0d9b551 100644 --- a/aws/data_source_aws_glue_connection.go +++ b/aws/data_source_aws_glue_connection.go @@ -43,6 +43,9 @@ func dataSourceAwsGlueConnection() *schema.Resource { func dataSourceAwsGlueConnectionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*AWSClient).glueconn catalogID, connectionName, err := decodeGlueConnectionID(d.Id()) + if err != nil { + return diag.Errorf("error decoding Glue Connection %s: %s", d.Id(), err) + } input := &glue.GetConnectionInput{ CatalogId: aws.String(catalogID), Name: aws.String(connectionName), diff --git a/aws/data_source_aws_glue_connection_test.go b/aws/data_source_aws_glue_connection_test.go index 13f10f17401..d99b334e5c8 100644 --- a/aws/data_source_aws_glue_connection_test.go +++ b/aws/data_source_aws_glue_connection_test.go @@ -51,7 +51,6 @@ resource "aws_glue_connection" "test" { name = %[1]q connection_type = "NETWORK" connection_properties = {} - } data "aws_glue_connection" "test" { diff --git a/aws/data_source_aws_glue_data_catalog_encryption_settings.go b/aws/data_source_aws_glue_data_catalog_encryption_settings.go index 6a1f59f548d..5fd2edd8c97 100644 --- a/aws/data_source_aws_glue_data_catalog_encryption_settings.go +++ b/aws/data_source_aws_glue_data_catalog_encryption_settings.go @@ -2,6 +2,7 @@ package aws import ( "context" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/glue" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" From 793d3a589d439d627b82720eb0dd082006283a78 Mon Sep 17 00:00:00 2001 From: danu165 Date: Mon, 12 Apr 2021 11:43:31 -0700 Subject: [PATCH 5/8] Add provider documentation --- website/docs/d/glue_connection.html.markdown | 34 +++++++++++++++++++ ..._catalog_encryption_settings.html.markdown | 33 ++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 website/docs/d/glue_connection.html.markdown create mode 100644 website/docs/d/glue_data_catalog_encryption_settings.html.markdown diff --git a/website/docs/d/glue_connection.html.markdown b/website/docs/d/glue_connection.html.markdown new file mode 100644 index 00000000000..92e7522037c --- /dev/null +++ b/website/docs/d/glue_connection.html.markdown @@ -0,0 +1,34 @@ +--- +subcategory: "Glue" +layout: "aws" +page_title: "AWS: aws_glue_connection" +description: |- + Get information on an AWS Glue Connection +--- + +# Data Source: aws_glue_connection + +This data source can be used to fetch information about a specific Glue Connection. + +## Example Usage + +```terraform +data "aws_glue_connection" "example" { + id = "123456789123:connection" +} +``` + +## Argument Reference + +* `id` - (Required) A concatenation of the catalog ID and connection name. For example, if your account ID is +`123456789123` and the connection name is `conn` then the ID is `123456789123:conn`. + +## Attributes Reference + +* `catalog_id` - The catalog ID of the Glue Connection. + +* `name` - The name of the Glue Connection. + +* `creation_time` - The time of creation of the Glue Connection. + +* `connection_type` - The type of Glue Connection. diff --git a/website/docs/d/glue_data_catalog_encryption_settings.html.markdown b/website/docs/d/glue_data_catalog_encryption_settings.html.markdown new file mode 100644 index 00000000000..3cc5e866b08 --- /dev/null +++ b/website/docs/d/glue_data_catalog_encryption_settings.html.markdown @@ -0,0 +1,33 @@ +--- +subcategory: "Glue" +layout: "aws" +page_title: "AWS: aws_glue_data_catalog_encryption_settings" +description: |- + Get information on AWS Glue Data Catalog Encryption Settings +--- + +# Data Source: aws_glue_data_catalog_encryption_settings + +This data source can be used to fetch information about AWS Glue Data Catalog Encryption Settings. + +## Example Usage + +```terraform +data "aws_glue_data_catalog_encryption_settings" "example" { + id = "123456789123" +} +``` + +## Argument Reference + +* `id` - (Required) The ID of the Data Catalog. This is typically the AWS account ID. + +## Attributes Reference + +* `connection_password_encrypted` - A boolean value which specifies whether connection passwords are encrypted. + +* `connection_password_kms_key_arn` - The ARN of the KMS key that encrypts connection passwords. + +* `encryption_mode` - The encryption mode of the Glue Data Catalog. + +* `encryption_kms_key_arn` - The ARN of the KMS key that encrypts the Glue Data Catalog. From 4cf7eac8a8e3a7d59603bab250db6626674cd65d Mon Sep 17 00:00:00 2001 From: danu165 Date: Mon, 12 Apr 2021 11:52:40 -0700 Subject: [PATCH 6/8] Fix lint of provider documentation --- website/docs/d/glue_connection.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/d/glue_connection.html.markdown b/website/docs/d/glue_connection.html.markdown index 92e7522037c..ecdeb2b0955 100644 --- a/website/docs/d/glue_connection.html.markdown +++ b/website/docs/d/glue_connection.html.markdown @@ -20,7 +20,7 @@ data "aws_glue_connection" "example" { ## Argument Reference -* `id` - (Required) A concatenation of the catalog ID and connection name. For example, if your account ID is +* `id` - (Required) A concatenation of the catalog ID and connection name. For example, if your account ID is `123456789123` and the connection name is `conn` then the ID is `123456789123:conn`. ## Attributes Reference From ed33d633e3eecca426303a0ade17f7c7c3366144 Mon Sep 17 00:00:00 2001 From: danu165 Date: Tue, 13 Apr 2021 08:52:13 -0700 Subject: [PATCH 7/8] Fix changelog --- .changelog/18802.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/18802.txt b/.changelog/18802.txt index 33a0666a172..aa95f71403f 100644 --- a/.changelog/18802.txt +++ b/.changelog/18802.txt @@ -3,5 +3,5 @@ aws_glue_connection ``` ```release-note:new-data-source -aws_glue_connection +aws_glue_data_catalog_encryption_settings ``` \ No newline at end of file From 1ebcc827f46c924de0f6a64db27d755924e745bd Mon Sep 17 00:00:00 2001 From: danu165 Date: Thu, 29 Apr 2021 10:49:44 -0700 Subject: [PATCH 8/8] Fix test for glue connection --- aws/data_source_aws_glue_connection_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/aws/data_source_aws_glue_connection_test.go b/aws/data_source_aws_glue_connection_test.go index d99b334e5c8..1f57b267f0c 100644 --- a/aws/data_source_aws_glue_connection_test.go +++ b/aws/data_source_aws_glue_connection_test.go @@ -48,9 +48,13 @@ func testAccDataSourceAwsGlueConnectionCheck(name string) resource.TestCheckFunc func testAccDataSourceAwsGlueConnectionConfig(rName string) string { return fmt.Sprintf(` resource "aws_glue_connection" "test" { - name = %[1]q - connection_type = "NETWORK" - connection_properties = {} + connection_properties = { + JDBC_CONNECTION_URL = "jdbc:mysql://terraformacctesting.com/testdatabase" + PASSWORD = "testpassword" + USERNAME = "testusername" + } + + name = "%s" } data "aws_glue_connection" "test" {