Skip to main content

☁️ AWS Terraform Generator

This module provides a Cloudhopper generator for deploying annotated Java functions as AWS Lambda functions using Terraform.

It generates:

  • AWS-specific handler classes
  • Terraform configuration files
  • Integration metadata to bridge vendor-neutral logic with AWS infrastructure

📦 How to Use

To enable this generator in your own project, you need to:


1. Add the Maven dependency

<dependency>
<groupId>eu.cloudhopper.mc</groupId>
<artifactId>generator-aws-terraform</artifactId>
<version>${cloudhopper.version}</version>
</dependency>

2. Configure the annotation processor

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
<encoding>UTF-8</encoding>
<annotationProcessors>
<annotationProcessor>
eu.cloudhopper.mc.deployment.config.generator.ServerlessFunctionProcessor
</annotationProcessor>
</annotationProcessors>
<compilerArgs>
<arg>-Acloudprovider=aws</arg>
<arg>-AgeneratorId=aws-terraform</arg>
<arg>-AconfigOutputDir=${project.build.directory}/deployment/aws</arg>
<arg>-AtargetDir=${project.build.directory}</arg>
<arg>-AartifactId=${project.artifactId}</arg>
<arg>-Aversion=${project.version}</arg>
<arg>-Aclassifier=aws</arg>
</compilerArgs>
</configuration>
</plugin>

This setup enables Cloudhopper to generate AWS-specific Terraform and handler code.


📁 Templates

Templates used by this generator are located under:

src/main/resources/templates/aws/
TemplateOutput TypePurpose
api.ftlTerraformAPI Gateway integration resource
apiIntegrationClass.ftlJavaAPI handler implementation
function.ftlTerraformLambda function resource
handler.ftlJavaEntry class using AwsLambdaRequestHandler
integration.ftlTerraformAPI Gateway/Lambda integration resource
schedule.ftlTerraformScheduled (CloudWatch Event) trigger
shared.ftlTerraformShared infrastructure (IAM roles, Lambda layer, etc.)

🔌 Template Registration

The generator is registered via:

@TemplateRegistration(
generatorId = "aws-terraform",
templates = {
@Template(name = "handler", phase = GenerationPhase.SOURCES),
@Template(name = "apiIntegrationClass", phase = GenerationPhase.SOURCES),
@Template(name = "function", phase = GenerationPhase.DEPLOYMENT),
@Template(name = "api", phase = GenerationPhase.DEPLOYMENT),
@Template(name = "integration", phase = GenerationPhase.DEPLOYMENT),
@Template(name = "schedule", phase = GenerationPhase.DEPLOYMENT),
@Template(name = "shared", phase = GenerationPhase.DEPLOYMENT)
}
)
public class AwsTerraformOpenApiJava21TemplateRegistration { ... }

Cloudhopper uses Java’s ServiceLoader (SPI) mechanism to discover and apply this registration.


📂 Output

ArtifactLocation
Java handler classestarget/generated-sources/aws/
Terraform configurationtarget/deployment/aws/*.tf
Metadata (handler-info.properties)target/classes/META-INF/cloudhopper/
Shaded JAR or ZIPtarget/${artifactId}-${version}-aws.jar or .zip

🛠️ Notes for Generator Developers

  • Handler classes extend AwsLambdaRequestHandler from the provider-aws module
  • The generated infrastructure assumes the use of Terraform to deploy Lambda, IAM, and API Gateway resources
  • You can override templates or inject additional files into the deployment directory by placing them in src/main/resources/deployment/aws/

ModulePurpose
provider-awsProvides the AwsLambdaRequestHandler runtime class
deployment-config-apiDefines core annotations and function interface

📝 Use this generator if you want to deploy Cloudhopper-based functions to AWS with minimal boilerplate and Terraform-based infrastructure-as-code.