cf2tf
cf2tf copied to clipboard
Add overrides for aws_sns_topic and other problematic conversions
This is an excellent python app for translating Cloudformation Stack to Terraform scripts
Some modules could however use an improvement while translating to terraform scripts:
- aws_autoscaling_notification
- aws_autoscaling_groups
- aws_acmpca_policy
- aws_cloudwatch_composite_alarm
- aws_sns_topic
The generated script has terraform blocks such as the following:
resource "aws_sns_topic" "some_topic" {
name = "${var.environment_name}-some-topic"
// CF Property(Subscription) = [
// {
// Endpoint = aws_lambda_function.lambda_function_name.arn
// Protocol = "lambda"
// }
// ]
}
When in ideal scenario, there should have been 2 resources (1 for SNS Topic, 1 for SNS Subscription):
resource "aws_sns_topic" "some_topic" {
name = "${var.environment_name}-some-topic"
}
resource "aws_sns_topic_subscription" some_sqs_target" {
topic_arn = aws_sns_topic.some_topic.arn
protocol = "lambda"
endpoint = "aws_lambda_function.lambda_function_name.arn"
}
I think the primary reason for this is that my Cloudformation script is creating the resources within the same module(CF block Type: "AWS::SNS::Topic"
), however terraform based on its API documentation requires multiple modules to replicate the same resource structure.
PS: Props to the idea of not failing the conversion for such scenarios and instead adding a comment block at the appropriate locations//CF Property....
so that developers can resolve them manually.
@jignesh1995 That is exactly what is happening. The converter tries to convery the Cloudformation property "Subscription" into a Terraform attribute for aws_sns_topic
but it doesn't exist, so it gives up.
This is something could be fixed. I added an override system to the tool in a previous release. This override functionality allows you to inspect the Cloudformation properties ahead of time and then manually do things.
The logic for performing the overrides is here: https://github.com/DontShaveTheYak/cf2tf/blob/a0ad1ea6bdfde200976ea31a26b37968f8cf6827/src/cf2tf/convert.py#L610-L625 The actual overrides are stored here: https://github.com/DontShaveTheYak/cf2tf/blob/a0ad1ea6bdfde200976ea31a26b37968f8cf6827/src/cf2tf/conversion/overrides.py#L1-L52
I will take a look at fixing the topic subscription with an override soon. Thanks for opening the issue with a clear example.