-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Add KMS encryption support to the aws_athena_database resource. #6117
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @joestump 👋 Thanks for submitting this! Please see the initial feedback below and let us know if you have any questions.
aws/resource_aws_athena_database.go
Outdated
}, | ||
} | ||
} | ||
|
||
func getResultConfig(d *schema.ResourceData) (*athena.ResultConfiguration, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this project has a very flat package structure, we prefer to include the service name in the function name. We also refer to these generally as "expand" functions and it would be nice to reduce the signature to not use d
directly. e.g.
func expandAthenaResultConfiguration(bucket string, encryptionConfigurationList []interface{}) (*athena.ResultConfiguration, error) {
aws/resource_aws_athena_database.go
Outdated
keyType := data["type"].(string) | ||
keyID := data["id"].(string) | ||
|
||
if len(keyType) <= 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the schema already has this set as Required: true
this error handling is extraneous.
aws/resource_aws_athena_database.go
Outdated
} | ||
|
||
if strings.HasSuffix(keyType, "_KMS") && len(keyID) <= 0 { | ||
return nil, fmt.Errorf("Key type %s requires a valid KMS key ID", keyType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the API not provide a helpful error message already? Since this error handling occurs during apply time anyways, we should avoid adding logic the API already handles unless necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does; just felt dirty making an AWS call for known errors. If that’s the pattern, I’ll update though.
aws/resource_aws_athena_database.go
Outdated
@@ -38,18 +38,73 @@ func resourceAwsAthenaDatabase() *schema.Resource { | |||
Optional: true, | |||
Default: false, | |||
}, | |||
"encryption_key": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API refers to this as encryption_configuration
-- is there any reason to diverge from their naming?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd modeled it after the CodePipeline's HCL, which makes a bit more sense, but if the pattern is to copy the API directly to HCL I'll update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make a bit more sense today, but not necessarily in the future should the API change. Here are a few reasons we prefer to stick with the API:
- We have gotten bitten in the past by trying to create abstractions and the API changes in a way that doesn't match those abstractions.
- Less of a maintenance burden to mentally work with the codebase if there are no abstractions/conversions.
- It keeps Terraform in line with the AWS API documentation, SDKs, and CloudFormation so operators coming from other documentation or systems can easily reference or convert between them.
- Different AWS services don't always line up with each other in terms of implementations. While this may look similar to CodePipeline today, Athena or CodePipeline may change tomorrow.
Hope this helps!
aws/resource_aws_athena_database.go
Outdated
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"id": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API refers to this as kms_key
-- is there any reason to diverge from their naming?
aws/resource_aws_athena_database.go
Outdated
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"type": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things:
- The API refers to this as
encryption_option
-- is there any reason to diverge from their naming? - We should validate this attribute using the SDK provided constants:
ValidateFunc: validation.StringInSlice([]string{
athena.EncryptionOptionCseKms,
athena.EncryptionOptionSseKms,
athena.EncryptionOptionSseS3,
}, false),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call on the validate. I mentioned why I diverged from the API above. I think the HCL I've proposed would look cleaner than this:
encryption_configuration {
encryption_option = "CSE_KMS"
kms_key = "${aws_kms_key.foo.id}"
}
It feels verbose to me. I think the CodePipeline API looks/feels more correct.
@bflad I've addressed most of the comments related to the Golang. Let me know what you think about my response on the HCL. I'm new to the AWS provider and will defer to the prevailing patterns. 👍 Thanks for the review! |
@bflad I took a stab at adding your notes into the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much, @joestump! 🚀
--- PASS: TestAccAWSAthenaDatabase_nameCantHaveUppercase (0.89s)
--- PASS: TestAccAWSAthenaDatabase_nameStartsWithUnderscore (26.71s)
--- PASS: TestAccAWSAthenaDatabase_basic (26.77s)
--- PASS: TestAccAWSAthenaDatabase_forceDestroyAlwaysSucceeds (31.01s)
--- PASS: TestAccAWSAthenaDatabase_destroyFailsIfTablesExist (36.16s)
--- PASS: TestAccAWSAthenaDatabase_encryption (49.10s)
This has been released in version 1.41.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
What does this add?
Adds an
encryption_key
attribute to theaws_athena_database
resource. This allows TF to create databases that read from encrypted S3 buckets.Example HCL
Test output