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

Added aws_glue_security_configuration resource to support encrypting… #41414

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
68 changes: 68 additions & 0 deletions internal/service/glue/security_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,33 @@ func ResourceSecurityConfiguration() *schema.Resource {
},
},
},
// new code block start
"data_quality_encryption": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
names.AttrKMSKeyARN: {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"data_quality_encryption_mode": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: awstypes.DataQualityEncryptionModeDisabled,
ValidateDiagFunc: enum.Validate[awstypes.DataQualityEncryptionMode](),
},
},
},
},
// new code block end
},
},
},
},
},
},
Expand Down Expand Up @@ -231,6 +258,9 @@ func expandEncryptionConfiguration(l []interface{}) *awstypes.EncryptionConfigur
CloudWatchEncryption: expandCloudWatchEncryption(m["cloudwatch_encryption"].([]interface{})),
JobBookmarksEncryption: expandJobBookmarksEncryption(m["job_bookmarks_encryption"].([]interface{})),
S3Encryption: expandS3Encryptions(m["s3_encryption"].([]interface{})),
// new code block start
DataQualityEncryption: expandDataQualityEncryption(m["data_quality_encryption"].([]interface{})),
// new code block end
}

return encryptionConfiguration
Expand Down Expand Up @@ -279,6 +309,26 @@ func expandS3Encryption(m map[string]interface{}) awstypes.S3Encryption {
return s3Encryption
}

// new code block start
func expandDataQualityEncryption(l []interface{}) *awstypes.DataQualityEncryption {
if len(l) == 0 || l[0] == nil {
return nil
}

m := l[0].(map[string]interface{})

dataQualityEncryption := &awstypes.DataQualityEncryption{
DataQualityEncryptionMode: awstypes.DataQualityEncryptionMode(m["data_quality_encryption_mode"].(string)),
}

if v, ok := m[names.AttrKMSKeyARN]; ok && v.(string) != "" {
dataQualityEncryption.KmsKeyArn = aws.String(v.(string))
}

return dataQualityEncryption
}
// new code block end

func flattenCloudWatchEncryption(cloudwatchEncryption *awstypes.CloudWatchEncryption) []interface{} {
if cloudwatchEncryption == nil {
return []interface{}{}
Expand All @@ -301,6 +351,9 @@ func flattenEncryptionConfiguration(encryptionConfiguration *awstypes.Encryption
"cloudwatch_encryption": flattenCloudWatchEncryption(encryptionConfiguration.CloudWatchEncryption),
"job_bookmarks_encryption": flattenJobBookmarksEncryption(encryptionConfiguration.JobBookmarksEncryption),
"s3_encryption": flattenS3Encryptions(encryptionConfiguration.S3Encryption),
// new code block start
"data_quality_encryption": flattenDataQualityEncryption(encryptionConfiguration.DataQualityEncryption),
// new code block end
}

return []interface{}{m}
Expand Down Expand Up @@ -337,3 +390,18 @@ func flattenS3Encryption(s3Encryption awstypes.S3Encryption) map[string]interfac

return m
}

// new code block start
func flattenDataQualityEncryption(dataQualityEncryption *awstypes.DataQualityEncryption) []interface{} {
if dataQualityEncryption == nil {
return []interface{}{}
}

m := map[string]interface{}{
names.AttrKMSKeyARN: aws.ToString(dataQualityEncryption.KmsKeyArn),
"data_quality_encryption_mode": string(dataQualityEncryption.DataQualityEncryptionMode),
}

return []interface{}{m}
}
// new code block end
81 changes: 81 additions & 0 deletions internal/service/glue/security_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func TestAccGlueSecurityConfiguration_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.s3_encryption.#", "1"),
resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.s3_encryption.0.kms_key_arn", ""),
resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.s3_encryption.0.s3_encryption_mode", "DISABLED"),
// new code block start
resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.data_quality_encryption.#", "1"),
resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.data_quality_encryption.0.kms_key_arn", ""),
resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.data_quality_encryption.0.data_quality_encryption_mode", "DISABLED"),
// new code block end
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
),
},
Expand Down Expand Up @@ -190,6 +195,42 @@ func TestAccGlueSecurityConfiguration_S3EncryptionS3EncryptionMode_sseS3(t *test
})
}

// new code block start
func TestAccGlueSecurityConfiguration_DataQualityEncryptionDataQualityEncryptionMode_sseKms(t *testing.T) {
ctx := acctest.Context(t)
var securityConfiguration awstypes.SecurityConfiguration

rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
kmsKeyResourceName := "aws_kms_key.test"
resourceName := "aws_glue_security_configuration.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.GlueServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckSecurityConfigurationDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccSecurityConfigurationConfig_dataQualityEncryptionModeSSEKMS(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckSecurityConfigurationExists(ctx, resourceName, &securityConfiguration),
resource.TestCheckResourceAttr(resourceName, "encryption_configuration.#", "1"),
resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.data_quality_encryption.#", "1"),
resource.TestCheckResourceAttr(resourceName, "encryption_configuration.0.data_quality_encryption.0.data_quality_encryption_mode", "SSE-KMS"),
resource.TestCheckResourceAttrPair(resourceName, "encryption_configuration.0.data_quality_encryption.0.kms_key_arn", kmsKeyResourceName, names.AttrARN),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

// new code block end

func testAccCheckSecurityConfigurationExists(ctx context.Context, resourceName string, securityConfiguration *awstypes.SecurityConfiguration) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
Expand Down Expand Up @@ -271,6 +312,12 @@ resource "aws_glue_security_configuration" "test" {
s3_encryption {
s3_encryption_mode = "DISABLED"
}

// new code block start
data_quality_encryption {
data_quality_encryption_mode = "DISABLED"
}
// new code block end
}
}
`, rName)
Expand Down Expand Up @@ -378,3 +425,37 @@ resource "aws_glue_security_configuration" "test" {
}
`, rName)
}

// new code block start
func testAccSecurityConfigurationConfig_dataQualityEncryptionModeSSEKMS(rName string) string {
return fmt.Sprintf(`
resource "aws_kms_key" "test" {
deletion_window_in_days = 7
}

resource "aws_glue_security_configuration" "test" {
name = %q

encryption_configuration {
cloudwatch_encryption {
cloudwatch_encryption_mode = "DISABLED"
}

job_bookmarks_encryption {
job_bookmarks_encryption_mode = "DISABLED"
}

s3_encryption {
s3_encryption_mode = "DISABLED"
}

data_quality_encryption {
data_quality_encryption_mode = "SSE-KMS"
kms_key_arn = aws_kms_key.test.arn
}
}
}
`, rName)
}

// new code block end