A Terraform module for creating and managing ArgoCD applications, projects, and repositories with support for multiple authentication methods and advanced configuration options.
Note: This module is used to manage ArgoCD, not deploy ArgoCD
- Multiple Authentication Types: SSH, HTTPS, GitHub App, and Token-based authentication
- Project Management: Create scoped ArgoCD projects with advanced RBAC
- Advanced Kustomize Support: Full Kustomize configuration including patches, images, and labels
- Flexible Sync Policies: Automated and manual sync with retry mechanisms
- Security Best Practices: Secure defaults with validation and proper secret handling
- Enterprise Ready: Support for GitHub Enterprise and advanced organizational features
Name | Version |
---|---|
terraform | >= 1.12.2 |
Name | Version |
---|---|
argoproj-labs/argocd | >= 7.10.0 |
module "my_app" {
source = "./terraform-argocd-module"
repo_auth_type = "ssh"
git_ssh_private_key = file("~/.ssh/argocd_key")
# ... other variables
}
module "my_app" {
source = "./terraform-argocd-module"
repo_auth_type = "https"
git_username = "myusername"
git_password = var.github_token
# ... other variables
}
module "my_app" {
source = "./terraform-argocd-module"
repo_auth_type = "github_app"
github_app_id = "123456"
github_app_installation_id = "78901234"
github_app_private_key = var.github_app_key
github_enterprise_base_url = "https://api.github.enterprise.com" # Optional
# ... other variables
}
module "my_app" {
source = "./terraform-argocd-module"
repo_auth_type = "token"
git_password = var.access_token
# ... other variables
}
# Configure the ArgoCD provider (in your root configuration)
provider "argocd" {
server_addr = "argocd.example.com:443"
auth_token = var.argocd_auth_token
}
# Use the module
module "web_app_production" {
source = "./terraform-argocd-module"
# Required variables
app_name = "web-app-prod"
app_namespace = "production"
project_name = "web-applications"
repo_url = "[email protected]:myorg/kustomize-configs.git"
kustomize_path = "overlays/production/web-app"
# Authentication
repo_auth_type = "ssh"
git_ssh_private_key = file("~/.ssh/argocd_deploy_key")
# Optional: Kustomize configuration
kustomize_name_prefix = "prod-"
kustomize_images = [
"web-app=registry.example.com/web-app:v2.1.0"
]
kustomize_common_labels = {
environment = "production"
team = "web"
}
}
module "platform_services" {
source = "./terraform-argocd-module"
# Basic configuration
app_name = "platform-core"
app_namespace = "platform"
project_name = "platform-services"
repo_url = "[email protected]:myorg/platform-base.git"
kustomize_path = "overlays/production"
# SSH Authentication
repo_auth_type = "ssh"
git_ssh_private_key = file("~/.ssh/platform_key")
insecure_ignore_host_key = false
# Multiple repositories for the project
project_source_repos = [
"[email protected]:myorg/shared-configs.git",
"[email protected]:myorg/platform-addons.git",
"https://charts.bitnami.com/bitnami"
]
# Multiple deployment destinations
project_destinations = [
{
server = "https://prod-east.k8s.example.com"
namespace = "platform"
},
{
server = "https://prod-west.k8s.example.com"
namespace = "platform"
}
]
# Advanced sync configuration
sync_policy_automated = true
sync_retry_limit = 10
sync_retry_backoff_duration = "30s"
# Ignore specific differences
ignore_differences = [
{
group = "apps"
kind = "Deployment"
json_pointers = ["/spec/replicas"]
}
]
}
Name | Description | Type |
---|---|---|
app_name |
The name of the ArgoCD application | string |
app_namespace |
The Kubernetes namespace where the application will be deployed | string |
project_name |
The name of the ArgoCD project | string |
repo_url |
The URL of the Git repository | string |
kustomize_path |
The path within the repository to the Kustomize overlay | string |
Name | Description | Type | Default |
---|---|---|---|
repo_auth_type |
Authentication method: ssh, https, github_app, token | string |
"ssh" |
git_ssh_private_key |
SSH private key for authentication | string |
"" |
git_username |
Username for HTTPS authentication | string |
"" |
git_password |
Password/PAT for HTTPS/token authentication | string |
"" |
github_app_id |
GitHub App ID | string |
"" |
github_app_installation_id |
GitHub App Installation ID | string |
"" |
github_app_private_key |
GitHub App private key | string |
"" |
github_enterprise_base_url |
GitHub Enterprise API base URL | string |
"" |
Name | Description | Type | Default |
---|---|---|---|
kustomize_name_prefix |
Prefix for all resources | string |
"" |
kustomize_name_suffix |
Suffix for all resources | string |
"" |
kustomize_images |
List of image overrides | list(string) |
[] |
kustomize_common_labels |
Common labels for all resources | map(string) |
{} |
kustomize_common_annotations |
Common annotations for all resources | map(string) |
{} |
kustomize_version |
Kustomize version to use | string |
"" |
Name | Description | Type | Default |
---|---|---|---|
sync_policy_automated |
Enable automated sync | bool |
true |
sync_policy_prune |
Enable pruning of deleted resources | bool |
true |
sync_policy_self_heal |
Enable self-healing | bool |
true |
sync_policy_allow_empty |
Allow empty applications | bool |
false |
sync_options |
List of sync options | list(string) |
["CreateNamespace=true"] |
sync_retry_limit |
Maximum sync retry attempts | number |
5 |
For a complete list of variables, see variables.tf.
Name | Description |
---|---|
application_name |
Name of the created ArgoCD application |
application_namespace |
Namespace of the ArgoCD application |
application_sync_status |
Current sync status of the application |
application_health_status |
Current health status of the application |
project_name |
Name of the created ArgoCD project |
repository_url |
URL of the registered repository |
repository_connection_status |
Connection status of the repository |
application_url |
Relative URL to view the application in ArgoCD UI |
For a complete list of outputs, see outputs.tf.
- SSH Keys: Store SSH private keys securely using Terraform variables or external secret management
- Access Tokens: Use environment variables or secret management systems for tokens
- Host Key Verification: Set
insecure_ignore_host_key = false
in production - Project Scoping: Use project-level restrictions to limit repository and destination access
- RBAC: Configure appropriate cluster and namespace resource restrictions
- Environment Separation: Use different projects for different environments
- Naming Conventions: Use consistent naming for applications and projects
- Resource Limits: Configure appropriate cluster and namespace resource whitelists
- Monitoring: Use the provided outputs for monitoring and alerting
- Validation: Enable application validation in production environments
- Git Practices: Use signed commits and protected branches for production applications
See examples.tf for comprehensive usage examples including:
- SSH authentication setup
- HTTPS with Personal Access Token
- GitHub App authentication for enterprises
- Multi-repository projects
- Development environment configurations
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests and examples
- Submit a pull request
This module is licensed under the Apache License 2.0. See LICENSE for details.
For issues and questions:
- Check the examples for common patterns
- Review the ArgoCD documentation for provider-specific details
- Open an issue with detailed information about your use case