This project is a boilerplate that integrates a Java (Spring Boot) application with infrastructure as code using Terraform.
- Backend: Java 17+ with Spring Boot
- Infrastructure: Terraform (
infraestructure/folder) - Dependency Management: Maven
- Containerization: Dockerfile included
├── Dockerfile # Application containerization
├── infraestructure/ # Terraform files for infrastructure
│ └── main.tf
├── src/
│ ├── main/
│ │ ├── java/caioneves05/terraform_boilerplate/app/ # Java source code
│ │ │ ├── TerraformBoilerplateApplication.java
│ │ │ └── controller/ApiController.java
│ │ │ └── dtos/TimestampResponse.java
│ │ └── resources/ # Configurations and static resources
│ │ ├── application.properties
│ │ ├── static/
│ │ └── templates/
│ └── test/java/caioneves05/terraform_boilerplate/ # Automated tests
│ └── TerraformBoilerplateApplicationTests.java
├── pom.xml # Maven configuration
├── LICENSE
├── HELP.md
└── readme.md # This file
- Java 17+
- Maven 3.8+
- Docker (optional)
- Terraform 1.0+
- Build:
./mvnw clean package
- Run:
java -jar target/terraform-boilerplate-0.0.1-SNAPSHOT.jar
- Via Docker:
docker build -t terraform-boilerplate . docker run -p 8080:8080 terraform-boilerplate
./mvnw test- Go to the
infraestructure/folder:cd infraestructure - Initialize Terraform:
terraform init
- Preview the execution plan:
terraform plan
- Apply the infrastructure:
terraform apply
Attention: Review the Terraform files before applying them in production.
Do not hardcode the profile parameter in the Terraform provider block.
Hardcoding the AWS profile in your Terraform configuration can reduce portability and flexibility, especially in collaborative or automated environments. Instead, prefer the following approaches:
Set the AWS profile before running Terraform:
export AWS_PROFILE=your-sso-profileThis allows Terraform to use the correct credentials without changing the code.
If you use AWS SSO, authenticate with:
aws sso login --profile your-sso-profileThen, set the profile as shown above.
For advanced use, you can define a variable in your Terraform code:
variable "aws_profile" {
type = string
default = null
description = "AWS CLI profile to use."
}
provider "aws" {
region = "us-east-2"
profile = var.aws_profile
}And run:
terraform plan -var="aws_profile=your-sso-profile"Summary:
- Avoid hardcoding the profile in the provider block.
- Prefer environment variables or variables in Terraform for flexibility and security.
- This makes your code more portable and CI/CD friendly.
See the LICENSE file for more details.