Skip to main content

Cloudhopper Maven Archetype

The easiest way to get started is the Maven Archetype. It generates a minimal Cloudhopper-based function project that can be deployed to various cloud providers using our provider-specific generators.

๐Ÿš€ Featuresโ€‹

The Archetype creates a simple "Hello World!" function using cloudhopper annotations. Using commandline parameters you can configure where you want to deploy the function, or more accurately, what generator you want to use. If you want to use Maven to deploy your functions, the archetype can optionally add a Terraform-based deployment profile.

๐Ÿ›  Usageโ€‹

๐Ÿ“ฆ Interactive (with prompts)โ€‹

    mvn archetype:generate \
-DarchetypeGroupId=eu.cloudhopper.mc \
-DarchetypeArtifactId=cloudhopper-maven-archetype-core \
-DarchetypeVersion=1.0-SNAPSHOT

โš™๏ธ Non-interactive (fully scripted)โ€‹

    mvn archetype:generate \
-DarchetypeGroupId=eu.cloudhopper.mc \
-DarchetypeArtifactId=cloudhopper-maven-archetype-core \
-DarchetypeVersion=1.0-SNAPSHOT \
-DgroupId=com.example \
-DartifactId=my-function \
-Dversion=1.0-SNAPSHOT \
-Dpackage=com.example.fn \
-DgeneratorIds=aws-terraform,gcp-terraform \
-DincludeTerraformProfile=true \
-B

> `-B` enables batch mode (non-interactive)

๐Ÿงฉ Supported Generatorsโ€‹

You can specify one or more generatorIds (comma-separated) to activate support for the following providers:

Generator IDDescription
aws-terraformAWS Lambda via Terraform
gcp-terraformGCP Cloud Functions via Terraform
azure-terraformAzure Functions via Terraform
springboot-httpLocal Spring Boot HTTP runtime

๐Ÿงช Terraform Supportโ€‹

If includeTerraformProfile=true, the generated project will include a deploy-with-terraform Maven profile that executes:

  • terraform init
  • terraform plan
  • terraform apply / destroy

Customize the Terraform executable path and environment using project properties:

    <properties>
<terraform.executable>terraform</terraform.executable>
<path.extras>/usr/local/bin</path.extras>
</properties>

๐Ÿ“‹ Project Layoutโ€‹

The generated project looks like this:

my-function
โ”œโ”€โ”€ pom.xml
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ src
โ””โ”€โ”€ main
โ”œโ”€โ”€ java
โ”‚ย ย  โ””โ”€โ”€ com
โ”‚ย ย  โ””โ”€โ”€ example
โ”‚ย ย  โ””โ”€โ”€ fn
โ”‚ย ย  โ””โ”€โ”€ HelloFunction.java // The sample function
โ””โ”€โ”€ resources
โ””โ”€โ”€ deployment // files will be copied to target/deployment/...
โ”œโ”€โ”€ aws-terraform // optional, only for generator aws-terraform
โ”‚ย ย  โ””โ”€โ”€ main.tf // customize to provide credentials, etc.
โ”œโ”€โ”€ azure-terraform // optional, only for generator azure-terraform
โ”‚ย ย  โ””โ”€โ”€ main.tf // customize to provide credentials, etc.
โ””โ”€โ”€ gcp-terraform // optional, only for generator gcp-terraform)
โ”œโ”€โ”€ gcp.auto.tfvars // customize to provide service account, etc.
โ””โ”€โ”€ main.tf // customize to provide credentials, etc.

๐Ÿ—๏ธ Build the projectโ€‹

For each of the generatorIds specified, a profile is created in the pom that can be used to build the project and generate for the specified platform and generate the boilerplate needed for deployment.

# build with generator aws-terraform
mvn clean install -Paws-terraform
# build with generator gcp-terraform
mvn clean install -Pgcp-terraform
# build with generator azure-terraform
mvn clean install -Pazure-terraform
# build with generator springboot-http
mvn clean install -Pspringboot-http

The annotation processor generates integration classes. The deployment files, (for aws, gcp and azure), will be generated into a directory in target/deployment/{generatorId}. You can import those files along with the generated function JAR in your own terraform project, or use terraform directly from the generated directory.

You need to provide additional variables for the deployment. Please check the generator documentation for details.

Deploy with Terraformโ€‹

If the generator is terraform based, the .tf files are generated in target/deployment/{generatorId}. You can copy the generated files to your terraform modules and use them from there. For smaller projects or for testing you can use the generated maven profile see here. Make sure to provide the path to your terraform executable in the pom's properties:

    <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cloudhopper.version>1.0-SNAPSHOT</cloudhopper.version>
<!-- add the path to your terraform executable here -->
<terraform.executable>terraform</terraform.executable>
<path.extras></path.extras>
</properties>

The maven profile is configured to always run terraform init. A second command can be passed via a parameter:

mvn verify -Pdeploy-with-terraform -Dterraform.command=plan
mvn verify -Pdeploy-with-terraform -Dterraform.command=apply
mvn verify -Pdeploy-with-terraform -Dterraform.command=delete