Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rectory Structureproject/
- ├── aws/
- │ ├── main.tf
- │ ├── variables.tf
- │ └── outputs.tf
- ├── azure/
- │ ├── main.tf
- │ ├── variables.tf
- │ └── outputs.tf
- ├── gcp/
- │ ├── main.tf
- │ ├── variables.tf
- │ └── outputs.tf
- └── main.tfMain Terraform Configuration (main.tf)# Main Terraform configuration for multi-cloud provisioning
- # Define providers for AWS, Azure, and GCP
- provider "aws" {
- region = "us-east-1" # Specify your AWS region
- }
- provider "azurerm" {
- features {}
- }
- provider "google" {
- project = "your-gcp-project-id"
- region = "us-central1" # Specify your GCP region
- }
- # Include configurations for AWS, Azure, and GCP modules
- module "aws_infrastructure" {
- source = "./aws"
- }
- module "azure_infrastructure" {
- source = "./azure"
- }
- module "gcp_infrastructure" {
- source = "./gcp"
- }AWS Configuration (aws/main.tf)# AWS resources configuration
- resource "aws_instance" "example" {
- ami = "ami-0c55b159cbfafe1f0"
- instance_type = "t2.micro"
- tags = {
- Name = "example-instance"
- }
- }
- # Define variables
- variable "aws_region" {
- default = "us-east-1"
- }
- # Define outputs
- output "aws_instance_public_ip" {
- value = aws_instance.example.public_ip
- }Azure Configuration (azure/main.tf)# Azure resources configuration
- resource "azurerm_virtual_machine" "example" {
- name = "example-vm"
- location = "East US"
- resource_group_name = "example-resources"
- vm_size = "Standard_DS1_v2"
- storage_image_reference {
- publisher = "Canonical"
- offer = "UbuntuServer"
- sku = "16.04-LTS"
- version = "latest"
- }
- os_profile {
- computer_name = "hostname"
- admin_username = "adminuser"
- admin_ssh_key {
- username = "adminuser"
- public_key = file("~/.ssh/id_rsa.pub")
- }
- }
- tags = {
- environment = "production"
- }
- }
- # Define variables
- variable "azure_location" {
- default = "East US"
- }
- # Define outputs
- output "azure_vm_public_ip" {
- value = azurerm_virtual_machine.example.network_interface_ids[0]
- }GCP Configuration (gcp/main.tf)# GCP resources configuration
- resource "google_compute_instance" "example" {
- name = "example-instance"
- machine_type = "e2-medium"
- zone = "us-central1-a"
- boot_disk {
- initialize_params {
- image = "debian-cloud/debian-10"
- }
- }
- network_interface {
- network = "default"
- access_config {
- // Ephemeral IP
- }
- }
- tags = ["web", "dev"]
- metadata = {
- ssh-keys = "your-user:${file("~/.ssh/id_rsa.pub")}"
- }
- }
- # Define variables
- variable "gcp_zone" {
- default = "us-central1-a"
- }
- # Define outputs
- output "gcp_instance_public_ip" {
- value = google_compute_instance.example.network_interface[0].access_config[0].nat_ip
- }
Advertisement
Add Comment
Please, Sign In to add comment