All notes

DevOps & Cloud / One-Click-Multi-Cloud-Provisioner

One-Click Multi-Cloud Provisioner

A comprehensive DevOps automation tool that provisions complete infrastructure on AWS and GCP using Terraform, Ansible, and Python.

November 13, 20259 min readPython1 stars
Open the full technical write-up

A comprehensive DevOps automation tool that provisions complete infrastructure on AWS and GCP using Terraform, Ansible, and Python. Deploy production-ready infrastructure with monitoring, databases, and CI/CD integration in a single command.

Table of Contents

What this project does

The One-Click Multi-Cloud Provisioner automates the entire infrastructure provisioning lifecycle:

  1. Infrastructure as Code: Terraform manages VPCs, subnets, compute instances, and databases
  2. Configuration Management: Ansible deploys applications and monitoring agents
  3. Cost Optimization: Real-time cost estimation using cloud provider APIs
  4. Drift Detection: Automated monitoring of infrastructure configuration drift
  5. CI/CD Ready: Jenkins and GitHub Actions workflows included

Core workflows

  • Multi-Cloud Support: Deploy to AWS and GCP with the same command
  • Environment Management: Separate configurations for dev, staging, and prod
  • Automated Monitoring: Prometheus and Node Exporter pre-configured
  • Database Support: Optional RDS (AWS) or CloudSQL (GCP) provisioning
  • Cost Estimation: Real-time cost estimates before provisioning
  • Drift Detection: Automated alerts for infrastructure configuration drift
  • CI/CD Integration: Ready-to-use Jenkins and GitHub Actions workflows
  • Production Ready: Security groups, encryption, and best practices included

How the system is built

graph TB
    subgraph "User Interface"
        CLI[Python CLI
provision.py]
    end
    
    subgraph "Orchestration Layer"
        PROV[Provisioner
Python Script]
        COST[Cost Estimator
Module]
        DRIFT[Drift Detector
Module]
    end
    
    subgraph "Infrastructure Layer"
        TF_AWS[Terraform
AWS]
        TF_GCP[Terraform
GCP]
    end
    
    subgraph "Configuration Layer"
        ANS[Ansible
Playbooks]
        APP[App Deployment
Role]
        MON[Monitoring
Role]
    end
    
    subgraph "Cloud Providers"
        AWS[AWS
EC2, VPC, RDS]
        GCP[GCP
Compute, VPC, CloudSQL]
    end
    
    subgraph "Monitoring Stack"
        PROM[Prometheus]
        NODE[Node Exporter]
    end
    
    CLI --> PROV
    PROV --> COST
    PROV --> TF_AWS
    PROV --> TF_GCP
    PROV --> ANS
    TF_AWS --> AWS
    TF_GCP --> GCP
    ANS --> APP
    ANS --> MON
    MON --> PROM
    MON --> NODE
    PROV --> DRIFT
    DRIFT --> TF_AWS
    DRIFT --> TF_GCP
    
    style CLI fill:#e1f5ff
    style PROV fill:#fff4e1
    style TF_AWS fill:#ffebee
    style TF_GCP fill:#e8f5e9
    style ANS fill:#f3e5f5

Prerequisites

Required Software

  • Python 3.9+
  • Terraform 1.0+
  • Ansible 2.9+
  • AWS CLI (for AWS deployments)
  • Google Cloud SDK (for GCP deployments)

Cloud Provider Accounts

  • AWS Account with appropriate IAM permissions
  • GCP Project with billing enabled and required APIs enabled

Authentication

  • AWS: Configure credentials using aws configure or environment variables
  • GCP: Authenticate using gcloud auth application-default login

Quick Start

1. Clone the Repository

git clone https://github.com/yourusername/one-click-multicloud-provisioner.git
cd one-click-multicloud-provisioner

2. Install Dependencies

Windows (using winget):

python setup.py install-deps

Linux/Mac:

pip install -r requirements.txt

3. Provision Infrastructure

# AWS Staging Environment
python scripts/provision.py --cloud aws --env staging

# GCP Production Environment with Database
python scripts/provision.py --cloud gcp --env prod --enable-db

Setup Steps

Detailed Installation

  1. Install Python Dependencies

    pip install -r requirements.txt
    
  2. Install Terraform

    • Download from terraform.io
    • Or use package manager: winget install HashiCorp.Terraform
  3. Install Ansible

    pip install ansible ansible-core
    
  4. Configure AWS Credentials

    aws configure
    # Or set environment variables:
    # export AWS_ACCESS_KEY_ID=your_key
    # export AWS_SECRET_ACCESS_KEY=your_secret
    
  5. Configure GCP Credentials

    gcloud auth application-default login
    gcloud config set project YOUR_PROJECT_ID
    
  6. Set Terraform Variables (Optional)

    • Create terraform/aws/terraform.tfvars for AWS
    • Create terraform/gcp/terraform.tfvars for GCP

Usage Examples

Basic Provisioning

# Provision AWS dev environment
python scripts/provision.py --cloud aws --env dev

# Provision GCP staging environment
python scripts/provision.py --cloud gcp --env staging

With Database

# Provision AWS production with RDS
python scripts/provision.py --cloud aws --env prod --enable-db

# Provision GCP staging with CloudSQL
python scripts/provision.py --cloud gcp --env staging --enable-db

Cost Estimation Only

from modules.cost_estimator import CostEstimator

estimator = CostEstimator("aws", "staging", enable_db=True)
cost_summary = estimator.estimate()
estimator.print_summary(cost_summary)

Drift Detection

# Check for configuration drift
python scripts/drift_detector.py --cloud aws

# With email alerts
python scripts/drift_detector.py --cloud gcp --email-config email_config.json

Sample CLI Output

============================================================
šŸš€ Starting Multi-Cloud Provisioning
   Cloud: AWS
   Environment: STAGING
   Database: Enabled
============================================================

āœ… All prerequisites met

šŸ’° Estimating infrastructure costs for AWS...
============================================================
šŸ’° COST ESTIMATION SUMMARY
============================================================
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ Component        │ Details                      │ Monthly Cost (USD)  │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│ Compute          │ 1x t3.large                  │ $60.74              │
│ Storage          │ 50 GB                        │ $5.00               │
│ Data Transfer    │ Estimated                    │ $10.00              │
│ Database         │ db.t3.small                  │ $24.82              │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│ TOTAL (Monthly)  │                              │ $100.56             │
│ TOTAL (Yearly)   │                              │ $1,206.72           │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

šŸ”§ Initializing Terraform for AWS...
āœ… Terraform initialized successfully

šŸ“‹ Running Terraform plan for AWS...
āœ… Terraform plan completed successfully

šŸš€ Applying Terraform configuration for AWS...
āœ… Terraform apply completed successfully

šŸ“¦ Running Ansible playbooks...
āœ… Ansible deployment completed successfully

============================================================
āœ… Provisioning completed successfully!
============================================================

šŸ“Š Infrastructure Outputs:
   instance_public_ips: ['54.123.45.67']
   vpc_id: vpc-0123456789abcdef0

How files are organized

one-click-multicloud-provisioner/
ā”œā”€ā”€ terraform/
│   ā”œā”€ā”€ aws/
│   │   ā”œā”€ā”€ main.tf              # AWS infrastructure definition
│   │   ā”œā”€ā”€ variables.tf         # AWS variables
│   │   ā”œā”€ā”€ outputs.tf           # AWS outputs
│   │   └── .gitignore
│   └── gcp/
│       ā”œā”€ā”€ main.tf              # GCP infrastructure definition
│       ā”œā”€ā”€ variables.tf         # GCP variables
│       ā”œā”€ā”€ outputs.tf           # GCP outputs
│       └── .gitignore
ā”œā”€ā”€ ansible/
│   ā”œā”€ā”€ playbooks/
│   │   └── deploy.yml           # Main deployment playbook
│   ā”œā”€ā”€ roles/
│   │   ā”œā”€ā”€ app_deployment/      # Application deployment role
│   │   └── monitoring/          # Monitoring setup role
│   ā”œā”€ā”€ inventory/               # Dynamic inventory files
│   └── ansible.cfg              # Ansible configuration
ā”œā”€ā”€ scripts/
│   ā”œā”€ā”€ provision.py             # Main provisioning script
│   └── drift_detector.py        # Drift detection script
ā”œā”€ā”€ modules/
│   ā”œā”€ā”€ cost_estimator.py        # Cost estimation module
│   └── drift_detector.py        # Drift detector module wrapper
ā”œā”€ā”€ .github/
│   └── workflows/
│       └── ci.yml               # GitHub Actions workflow
ā”œā”€ā”€ Jenkinsfile                  # Jenkins pipeline
ā”œā”€ā”€ requirements.txt             # Python dependencies
ā”œā”€ā”€ setup.py                     # Setup script with winget
└── README.md                    # This file

Cost Estimation

The cost estimator module provides real-time cost estimates using:

  • AWS Pricing API: Fetches current pricing for EC2, RDS, and storage
  • GCP Billing API: Estimates costs for Compute Engine and CloudSQL
  • Fallback Pricing: Uses cached pricing if APIs are unavailable

What the project includes

  • Instance type recommendations based on environment
  • Storage and data transfer estimates
  • Database cost calculations
  • Monthly and yearly projections
  • Cost breakdown by component

Drift Detection

The drift detector monitors infrastructure for configuration drift:

What the project includes

  • Automated Terraform plan execution
  • Detailed drift reports
  • Email alerts (optional)
  • Historical drift tracking
  • Integration with CI/CD pipelines

Usage

# Basic drift detection
python scripts/drift_detector.py --cloud aws

# With email notifications
python scripts/drift_detector.py --cloud gcp \
  --email-config email_config.json

CI/CD Integration

GitHub Actions

The included workflow provides:

  • Automated linting and validation
  • Terraform syntax checking
  • Ansible syntax validation
  • Manual provisioning triggers
  • Multi-cloud testing

Setup:

  1. Add AWS credentials to GitHub Secrets: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
  2. Add GCP service account key to GitHub Secrets: GCP_SA_KEY
  3. Workflow will run on push/PR and can be triggered manually

Jenkins

The Jenkinsfile includes:

  • Multi-stage pipeline
  • Parallel testing
  • Terraform validation
  • Ansible syntax checks
  • Automated cleanup

Setup:

  1. Install required Jenkins plugins: Pipeline, Ansible, Terraform
  2. Configure cloud credentials in Jenkins
  3. Create a pipeline job pointing to the Jenkinsfile

Testing

The project includes a comprehensive test suite with 55 test cases covering all major components.

Test Coverage

  • Total Tests: 55 tests
  • Test Status: All passing
  • Code Coverage: 74% overall
    • modules/cost_estimator.py: 92% coverage
    • modules/drift_detector.py: 100% coverage
    • scripts/drift_detector.py: 79% coverage
    • scripts/provision.py: 61% coverage

Test Suite Structure

tests/
ā”œā”€ā”€ test_provisioner.py      # 13 tests - Provisioner class validation and workflows
ā”œā”€ā”€ test_cost_estimator.py   # 18 tests - Cost estimation logic for AWS and GCP
ā”œā”€ā”€ test_drift_detector.py   # 16 tests - Drift detection functionality
└── test_integration.py      # 5 tests - Integration and end-to-end scenarios

Running Tests

# Run all tests
pytest tests/ -v

# Run with coverage report
pytest tests/ --cov=scripts --cov=modules --cov-report=term-missing

# Run specific test file
pytest tests/test_provisioner.py -v

# Run specific test
pytest tests/test_cost_estimator.py::TestCostEstimator::test_estimate_aws -v

Test Results Summary

============================= test session starts =============================
platform win32 -- Python 3.11.9, pytest-8.4.2
collected 55 items

tests/test_cost_estimator.py::TestCostEstimator ................ [18 tests] āœ…
tests/test_drift_detector.py::TestDriftDetector ................ [16 tests] āœ…
tests/test_integration.py::TestIntegration ..................... [5 tests] āœ…
tests/test_provisioner.py::TestProvisioner ..................... [13 tests] āœ…

============================= 55 passed in 53.19s =============================

Test Categories

Unit Tests

  • Provisioner Tests: Initialization, validation, prerequisite checking, Terraform operations, Ansible integration
  • Cost Estimator Tests: AWS/GCP cost calculations, region/instance type selection, database cost estimation
  • Drift Detector Tests: Terraform plan execution, drift parsing, report generation, email alerts

Integration Tests

  • Multi-cloud provisioning workflows
  • Cost estimation across all environments (dev, staging, prod)
  • Database enablement scenarios
  • Validation flow for all cloud/environment combinations

Test Evidence

Last Test Run: All 55 tests passing

Coverage Report:

Name                        Stmts   Miss  Cover   Missing
---------------------------------------------------------
modules\cost_estimator.py     109      9    92%   
modules\drift_detector.py       2      0   100%   
scripts\drift_detector.py     141     30    79%   
scripts\provision.py          183     72    61%   
---------------------------------------------------------
TOTAL                         435    111    74%

Continuous Testing

Tests are automatically run:

  • On every commit via GitHub Actions (if configured)
  • Before merging pull requests
  • As part of the CI/CD pipeline

Adding New Tests

When adding new features:

  1. Write unit tests for new functions/classes
  2. Add integration tests for new workflows
  3. Ensure coverage remains above 70%
  4. Run tests locally before committing

Roadmap

Phase 1 (Current)

  • AWS and GCP provisioning
  • Basic monitoring setup
  • Cost estimation
  • Drift detection

Phase 2 (Planned)

  • Azure support
  • Kubernetes cluster provisioning
  • Advanced monitoring (Grafana, AlertManager)
  • Multi-region deployments
  • Disaster recovery automation

Phase 3 (Future)

  • Web UI dashboard
  • Infrastructure visualization
  • Cost optimization recommendations
  • Automated scaling policies
  • Blue-green deployment support

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow PEP 8 for Python code
  • Use Terraform best practices
  • Write Ansible roles with idempotency
  • Add tests for new features
  • Update documentation

Code Style

  • Python: Use black formatter, max line length 120
  • Terraform: Use terraform fmt
  • Ansible: Follow Ansible best practices

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • HashiCorp for Terraform
  • Red Hat for Ansible
  • Prometheus community
  • AWS and GCP for their excellent APIs

Support

Disclaimer

This tool provisions real cloud infrastructure that will incur costs. Always review the cost estimates and ensure you have proper access controls in place. The authors are not responsible for any costs incurred from using this tool.


Made by the DevOps community

Related notes

DevOps & Cloud

Self-Healing Kubernetes Monitor

An intelligent, automated Kubernetes monitoring and self-healing system that detects pod and service issues using Prometheus metrics and automatically takes corrective actions to restore cluster health.

DevOps & Cloud

MacForge

A lightweight macOS automation toolkit that intelligently manages performance, storage, and power - so your system runs fast, clean, and efficient without manual intervention.