Infrastructure as Code

    Deploying OpenTofu on RamNode VPS

    OpenTofu is an open-source infrastructure-as-code tool backed by the Linux Foundation. Manage your cloud infrastructure through declarative configuration files with this Terraform-compatible alternative.

    Ubuntu/Debian/Rocky
    Terraform Compatible
    ⏱️ 15-20 minutes

    Why OpenTofu?

    Open Source Licensing

    Mozilla Public License 2.0

    Terraform Compatibility

    Drop-in replacement for Terraform 1.5.x and earlier

    Community-Driven

    Backed by the Linux Foundation

    Provider Ecosystem

    Access to thousands of providers

    State Management

    Built-in state tracking for infrastructure changes

    Recommended VPS Specifications

    Use CaseRAMStorageNotes
    Minimum1GB10GB SSDSmall projects
    Recommended2GB+20GB SSDLarger infrastructures

    Prerequisites

    Before starting, ensure you have:

    System Requirements

    • • RamNode VPS with at least 1GB RAM
    • • Ubuntu 22.04, Debian 12, or Rocky Linux 9
    • • Root or sudo access
    • • SSH client installed locally

    Optional

    • • Basic command-line familiarity
    • • API credentials for target providers
    • • Git for version control
    2

    Package Manager Installation (Recommended)

    This method uses the official OpenTofu repository for easy installation and updates.

    For Ubuntu/Debian:

    Install Prerequisites
    sudo apt-get update
    sudo apt-get install -y curl gnupg software-properties-common
    Add OpenTofu Repository & Install
    # Add OpenTofu GPG key
    curl -fsSL https://get.opentofu.org/opentofu.gpg | sudo gpg --dearmor -o /usr/share/keyrings/opentofu-archive-keyring.gpg
    
    # Add OpenTofu repository
    echo "deb [signed-by=/usr/share/keyrings/opentofu-archive-keyring.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main" | sudo tee /etc/apt/sources.list.d/opentofu.list
    
    # Update package list and install OpenTofu
    sudo apt-get update
    sudo apt-get install -y tofu

    For Rocky Linux/RHEL:

    Install on Rocky Linux
    # Install prerequisites
    sudo dnf install -y yum-utils
    
    # Add OpenTofu repository
    sudo yum-config-manager --add-repo https://packages.opentofu.org/opentofu/tofu/rpm/el/opentofu.repo
    
    # Install OpenTofu
    sudo dnf install -y tofu
    3

    Standalone Binary Installation (Alternative)

    For more control over the installation or if you need a specific version:

    Download & Install Binary
    # Download the latest release
    TOFU_VERSION="1.6.0"
    wget https://github.com/opentofu/opentofu/releases/download/v${TOFU_VERSION}/tofu_${TOFU_VERSION}_linux_amd64.zip
    
    # Install unzip if not already present
    sudo apt-get install -y unzip
    
    # Extract and install
    unzip tofu_${TOFU_VERSION}_linux_amd64.zip
    sudo mv tofu /usr/local/bin/
    sudo chmod +x /usr/local/bin/tofu
    
    # Clean up
    rm tofu_${TOFU_VERSION}_linux_amd64.zip
    4

    Verify Installation

    Confirm OpenTofu is properly installed:

    Check Version
    tofu version
    Expected Output
    OpenTofu v1.6.0
    on linux_amd64

    ✓ OpenTofu is now installed and ready to use!

    5

    Setting Up Your First Project

    Create a dedicated directory for your OpenTofu configurations:

    Create Project Directory
    mkdir -p ~/infrastructure/ramnode-demo
    cd ~/infrastructure/ramnode-demo
    6

    Basic Configuration Structure

    OpenTofu uses HCL (HashiCorp Configuration Language) for defining infrastructure. Create a basic configuration file:

    Create main.tf
    nano main.tf
    main.tf - Simple Example
    terraform {
      required_version = ">= 1.6.0"
      required_providers {
        local = {
          source  = "hashicorp/local"
          version = "~> 2.4"
        }
      }
    }
    
    resource "local_file" "example" {
      content  = "Hello from OpenTofu on RamNode!"
      filename = "${path.module}/hello.txt"
    }
    
    output "file_path" {
      value = local_file.example.filename
    }
    7

    Initialize and Apply

    Initialize OpenTofu to download required providers:

    Initialize Project
    tofu init

    This command downloads necessary provider plugins and prepares your working directory.

    Preview Changes
    tofu plan
    Apply Configuration
    tofu apply

    ⚠️ Type yes when prompted to confirm the changes.

    8

    Practical Example: Cloud Provider

    Here's a more practical example managing a DigitalOcean droplet (adaptable for other providers):

    Configure Provider Credentials

    Create a variables file for sensitive data:

    terraform.tfvars
    do_token = "your_digitalocean_api_token_here"

    ⚠️ Important: Add this file to .gitignore to prevent committing credentials!

    Create .gitignore
    echo "terraform.tfvars" >> .gitignore
    echo ".terraform/" >> .gitignore
    echo "*.tfstate*" >> .gitignore

    Create the Configuration

    digitalocean.tf
    terraform {
      required_providers {
        digitalocean = {
          source  = "digitalocean/digitalocean"
          version = "~> 2.34"
        }
      }
    }
    
    variable "do_token" {
      description = "DigitalOcean API Token"
      type        = string
      sensitive   = true
    }
    
    provider "digitalocean" {
      token = var.do_token
    }
    
    resource "digitalocean_droplet" "web" {
      image  = "ubuntu-22-04-x64"
      name   = "web-server"
      region = "nyc3"
      size   = "s-1vcpu-1gb"
      tags   = ["web", "production"]
    }
    
    output "droplet_ip" {
      value = digitalocean_droplet.web.ipv4_address
    }
    Deploy the Infrastructure
    # Initialize with new provider
    tofu init
    
    # Review the plan
    tofu plan
    
    # Apply the configuration
    tofu apply
    9

    Security Best Practices

    Secure Credential Management

    Never hardcode credentials. Use environment variables or secret management tools:

    Create Secure Credentials File
    nano ~/.tofu_credentials
    ~/.tofu_credentials
    export TF_VAR_do_token="your_token_here"
    export TF_VAR_aws_access_key="your_key_here"
    export TF_VAR_aws_secret_key="your_secret_here"
    Secure & Source Credentials
    # Restrict permissions
    chmod 600 ~/.tofu_credentials
    
    # Source when needed
    source ~/.tofu_credentials
    Additional Security Tips
    • Use remote state backends (S3, GCS) for team collaboration
    • Enable state encryption for sensitive data
    • Implement least-privilege IAM policies for providers
    • Use Vault or similar tools for secret management
    10

    Troubleshooting

    Provider Plugin Issues

    If you encounter provider download issues:

    Clear Cache & Reinitialize
    # Clear provider cache
    rm -rf .terraform/
    
    # Re-initialize
    tofu init

    State Lock Issues

    If state becomes locked:

    Force Unlock (Use Cautiously)
    tofu force-unlock <lock-id>

    Resource Drift Detection

    Check for manual changes outside of OpenTofu:

    Detect Drift
    tofu plan -refresh-only

    Setup Complete!

    OpenTofu provides a powerful, open-source solution for infrastructure as code on your RamNode VPS. Whether you're managing a single server or orchestrating complex multi-cloud deployments, OpenTofu offers the flexibility and reliability needed for modern infrastructure management.

    Key Takeaways:

    • OpenTofu is a production-ready Terraform alternative with full compatibility
    • Declarative configuration enables version-controlled infrastructure
    • Remote state management supports team collaboration
    • Provider ecosystem covers virtually all cloud platforms and services