{
  "id": "5T0q54z7XbP4rDKb",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Launch AWS EC2 Instances from Google Sheets",
  "tags": [],
  "nodes": [
    {
      "id": "7b6273c0-bbfc-4f5d-aecb-288b154300cc",
      "name": "Workflow Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        920,
        -860
      ],
      "parameters": {
        "width": 420,
        "height": 300,
        "content": "## \ud83d\ude80 AWS EC2 Auto Launcher\n\n### Features:\n\u2022 Reads launch requests from Google Sheets\n\u2022 Launches EC2 instances via AWS API\n\u2022 Updates status in spreadsheet\n\u2022 Sends detailed confirmation emails\n\u2022 Error handling with notifications\n\u2022 Scheduled or manual execution\n\n### Triggers: Daily at 9 AM or Manual"
      },
      "typeVersion": 1
    },
    {
      "id": "b6c7b146-2815-4669-bdf0-f0cad7b7a0d7",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        -980
      ],
      "parameters": {
        "color": 5,
        "width": 580,
        "height": 1140,
        "content": "### **`main.tf`**\n\n```hcl\n# Configure AWS provider\nprovider \"aws\" {\n  region  = var.aws_region\n  profile = var.aws_profile\n}\n\n# Create EC2 instance\nresource \"aws_instance\" \"example\" {\n  ami           = var.ami_id\n  instance_type = var.instance_type\n  key_name      = var.key_name\n\n  tags = {\n    Name = var.instance_name\n  }\n}\n\n# Output EC2 public IP\noutput \"ec2_public_ip\" {\n  value = aws_instance.example.public_ip\n}\n```\n\n---\n\n### **`variables.tf`**\n\n```hcl\nvariable \"aws_region\" {\n  description = \"AWS region to deploy in\"\n  type        = string\n}\n\nvariable \"aws_profile\" {\n  description = \"AWS CLI profile to use\"\n  type        = string\n  default     = \"default\"\n}\n\nvariable \"ami_id\" {\n  description = \"AMI ID for EC2 instance\"\n  type        = string\n}\n\nvariable \"instance_type\" {\n  description = \"EC2 instance type\"\n  type        = string\n  default     = \"t2.micro\"\n}\n\nvariable \"key_name\" {\n  description = \"SSH key pair name\"\n  type        = string\n}\n\nvariable \"instance_name\" {\n  description = \"EC2 instance Name tag\"\n  type        = string\n}\n```\n\n---\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "70087b97-5a6c-4a47-9c28-906f731d97ae",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        380,
        -860
      ],
      "parameters": {
        "color": 3,
        "width": 460,
        "height": 220,
        "content": "\n### **`terraform.tfvars`** (example values)\n\n```hcl\naws_region     = \"us-east-1\"\nami_id         = \"ami-0c55b159cbfafe1f0\"\ninstance_type  = \"t2.micro\"\nkey_name       = \"my-keypair\"\ninstance_name  = \"MyTerraformEC2\"\n```\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "55d7ea64-2ad7-4359-ba3c-0a589d29ce9c",
      "name": "Google Sheets Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        500,
        -480
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 10
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "ef286e0d-08f4-429c-b701-448406fb950d",
      "name": "Extract Instance Details",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        720,
        -480
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "Launch_Requests",
          "cachedResultName": "Launch Requests"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_EC2_SHEET_ID",
          "cachedResultName": "EC2 Launch Requests"
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "b74895b0-b01a-4675-9af0-8cd256016576",
      "name": "Launch EC2 Instance",
      "type": "n8n-nodes-base.ssh",
      "position": [
        940,
        -480
      ],
      "parameters": {
        "command": "=# Variables\nSERVER_USER=\"{{ $json.server_user }}\"\nSERVER_IP=\"{{ $json.server_ip }}\"\nWORKSPACE_NAME=\"{{ $json.workspace_name }}\"\nPWD=\"{{ $json.pwd }}\"\n\n# SSH and run Terraform commands\necho \"$PWD\" | ssh ${SERVER_USER}@${SERVER_IP} \"\n    cd /path/to/terraform/project &&\n    terraform workspace new ${WORKSPACE_NAME} || terraform workspace select ${WORKSPACE_NAME} &&\n    terraform init &&\n    terraform plan -out=tfplan &&\n    terraform apply -auto-approve tfplan\n\"",
        "authentication": "privateKey"
      },
      "credentials": {
        "sshPrivateKey": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ee365181-a63b-4216-990b-ac2c5d721ea8",
      "name": "Update Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1160,
        -480
      ],
      "parameters": {
        "columns": {
          "value": {
            "ami_id": "={{ $json.ami_id }}",
            "region": "={{ $json.region }}",
            "key_pair": "={{ $json.key_pair }}",
            "public_ip": "={{ $json.public_ip }}",
            "timestamp": "={{ $now.toISO() }}",
            "private_ip": "={{ $json.private_ip }}",
            "instance_id": "={{ $json.instance_id }}",
            "project_name": "={{ $json.project_name }}",
            "instance_name": "={{ $json.instance_name }}",
            "instance_type": "={{ $json.instance_type }}",
            "launch_status": "={{ $json.launch_status }}",
            "instance_state": "={{ $json.instance_state }}",
            "reservation_id": "={{ $json.reservation_id }}",
            "security_group": "={{ $json.security_group }}",
            "requester_email": "={{ $json.requester_email }}",
            "availability_zone": "={{ $json.availability_zone }}"
          },
          "schema": [
            {
              "id": "timestamp",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Launch Timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "instance_name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Instance Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "instance_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Instance ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "instance_type",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Instance Type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ami_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "AMI ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "region",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Region",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "availability_zone",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Availability Zone",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "private_ip",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Private IP",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "public_ip",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Public IP",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "instance_state",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Instance State",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "key_pair",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Key Pair",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "security_group",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Security Group",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "project_name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Project Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "requester_email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Requester Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "launch_status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Launch Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "reservation_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Reservation ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow"
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "Launched_Instances",
          "cachedResultName": "Launched Instances"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_EC2_SHEET_ID",
          "cachedResultName": "EC2 Launch Requests"
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "61b4af75-72fd-4da6-a2ca-e3e9a16d928e",
      "name": "Send Confirmation Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1380,
        -480
      ],
      "parameters": {
        "sendTo": "={{ $json.requester_email }}",
        "message": "=<h2>\ud83d\ude80 EC2 Instance Launch Confirmation</h2><br><br><strong>Great news!</strong> Your EC2 instance has been launched successfully.<br><br><div style=\"background-color: #f8f9fa; padding: 20px; border-radius: 8px; border-left: 4px solid #28a745;\"><h3>\ud83d\udccb Instance Details</h3><p><strong>Instance Name:</strong> {{ $json.instance_name }}<br><strong>Instance ID:</strong> <code>{{ $json.instance_id }}</code><br><strong>Instance Type:</strong> {{ $json.instance_type }}<br><strong>AMI ID:</strong> {{ $json.ami_id }}<br><strong>Region:</strong> {{ $json.region }}<br><strong>Availability Zone:</strong> {{ $json.availability_zone }}<br><strong>Current State:</strong> {{ $json.instance_state }}<br><strong>Key Pair:</strong> {{ $json.key_pair }}<br><strong>Security Group:</strong> {{ $json.security_group }}</p></div><br><div style=\"background-color: #e3f2fd; padding: 20px; border-radius: 8px; border-left: 4px solid #2196f3;\"><h3>\ud83c\udf10 Network Information</h3><p><strong>Private IP:</strong> {{ $json.private_ip }}<br><strong>Public IP:</strong> {{ $json.public_ip || 'Not assigned yet' }}</p></div><br><div style=\"background-color: #fff3e0; padding: 20px; border-radius: 8px; border-left: 4px solid #ff9800;\"><h3>\ud83d\udcca Additional Info</h3><p><strong>Launch Time:</strong> {{ $json.launch_time_aws }}<br><strong>Project:</strong> {{ $json.project_name }}<br><strong>Reservation ID:</strong> {{ $json.reservation_id }}<br><strong>Platform:</strong> {{ $json.platform }}<br><strong>Architecture:</strong> {{ $json.architecture }}</p></div><br><div style=\"background-color: #ffebee; padding: 15px; border-radius: 8px; border: 1px solid #f44336;\"><h4>\u26a0\ufe0f Important Notes</h4><ul><li>It may take a few minutes for the instance to be fully available</li><li>Public IP will be assigned once the instance is running</li><li>Remember to terminate the instance when no longer needed to avoid charges</li><li>You can connect using your key pair: <code>{{ $json.key_pair }}</code></li></ul></div><br><h3>\ud83d\udd17 AWS Console Link</h3><p><a href=\"https://{{ $json.region }}.console.aws.amazon.com/ec2/v2/home?region={{ $json.region }}#InstanceDetails:instanceId={{ $json.instance_id }}\" style=\"background-color: #007bff; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px;\">View in AWS Console</a></p><br><p>If you have any questions or need assistance, please contact the infrastructure team.</p><br><p><em>This instance was launched automatically via n8n workflow.</em></p>",
        "options": {
          "ccList": "user@example.com"
        },
        "subject": "\u2705 AWS EC2 Instance Launched Successfully - {{ $json.instance_name }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "843e8aef-5fe8-413e-9a16-7c42b7575f7f",
  "connections": {
    "Launch EC2 Instance": {
      "main": [
        [
          {
            "node": "Update Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Google Sheet": {
      "main": [
        [
          {
            "node": "Send Confirmation Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets Trigger": {
      "main": [
        [
          {
            "node": "Extract Instance Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Instance Details": {
      "main": [
        [
          {
            "node": "Launch EC2 Instance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}