Problem:
AWS Secret Manager has an optional feature to automatically rotate the secret with specified intervals and they are using expandable design where entire rotation mechanism is based on prebuilt lambda function provided through AWS SAM (Serverless Application Model) Repository. This repository has several ready made password rotation lambda function for standard RDS database such as MySQL, Postgres, Oracle ect.
When the secret rotation is enabled from the console GUI, AWS setup everything in the background to enable the key rotation without any manual user input. However if you are configuring Key rotation inside a Terraform configuration, all the operations done internally by GUI has to be performed by the terraform script. This article shows the steps required and some background information as well.
Solution:
- The argument capabilities should be set with CAPABILITY_AUTO_EXPAND
- Transform should be AWS:Serverless-2016-10-31 for CloudForm to identify this as a nested application stack
- Type should be set to AWS::Serverless::application
- Under the properties, ApplicationId specify the prebuilt rotation function and supportive resources such as execution policies to be created inside your AWS account before linking it with the Secret Manager. This parameter accept the standard AWS arn of the application that can be retrived on SAM Repository Console. for example arn:aws:serverlessrepo:us-east-1:297356227824:applications/<name_of_the_application>. name_of_the_application should be selected based on the type of RDS database and the type of authentication mode used. "SecretsManagerRDSPostgreSQLRotationSingleUser" is used in this example to deploy the secret rotation lambda function and related resources for a RDS Postgres instance with Single user credentials mode. details of other available applications can be found here.
- SemanticVersion is used to specify the version of the function as as AWS team keep developing this git repository and made available over the SAM Repository. As of the time of writing there was no way to determine the latest version of the application so I had to use AWS CLI commandaws serverlessrepo list-application-versions --application-id <ApplicationId>to get the list of version available. For the version it is recommended to use the latest version.
- depending on the ApplicationId and the SemanticVersion parameters should be specified and terraform apply will fail with validation errors if not supplied correctly.
Thanks for sharing useful information.. we have learned so much information from your blog.
ReplyDeleteWorkday Integration Training
Workday Integration Online Training