Cloud formation has custom resource types.Example given below :
“BucketACL”: {
“DependsOn”: “LambdaPutBucketACL”,
“Type”: “Custom::BucketACL”,
“Version”: “1.0”,
“Properties”: {
“DeletionPolicy”: “Retain”,
“ServiceToken”: {
“Fn::GetAtt”: [
“LambdaPutBucketACL”,
“Arn”
]
},
“BucketName”: {
“Ref”: “Bucket”
},
“Owner”: {
“Ref”: “CanonicalOwner”
},
“Grants”: [
{
“Grantee”: {
“ID”: {
“Ref”: “CanonicalOwner”
},
“Type”: “CanonicalUser”
},
“Permission”: [
“FULL_CONTROL”
]
},
{
“Grantee”: {
“ID”: {
“Ref”: “CanonicalElastiCache”
},
“Type”: “CanonicalUser”
},
“Permission”: {
“Fn::Split”: [
“,”,
{
“Ref”: “ACLPermissions”
}
]
}
}
]
}
}
Is it possible to have similar resource types in terraform ?
Or is there any other way to implement the same functionality ?
Hi @Athulia123,
The extensibility mechanism for new resource types in Terraform is to implement a provider plugin.
Terraform is slightly different to CloudFormation in that all of the Terraform execution happens on the local system where terraform
is running, whereas CloudFormation is a hosted service. Therefore the extensibility model is different too: provider plugins are just normal programs that run on the same computer where terraform
is running, rather than being implemented as remote calls to a network service such as AWS Lambda.
On the other hand, a consequence of running locally rather than in AWS is that a custom provider plugin cannot directly access the configuration and clients from Terraform’s aws
plugin, so if the custom resource will call into AWS APIs it will need to implement its own AWS client configuration separate from the AWS API.
If you already have a CloudFormation custom resource that you are happy with, another possibility is to use the aws_cloudformation_stack
resource type to integrate Terraform with CloudFormation to apply that custom resource. That will allow you to configure the custom resource in exactly the same way (embedded in your Terraform configuration) but allow passing values into and out of the CloudFormation stack to integrate with other objects Terraform is managing outside of CloudFormation.