Guest User

Untitled

a guest
Jun 13th, 2024
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | Source Code | 0 0
  1. rectory Structureproject/
  2. ├── aws/
  3. │ ├── main.tf
  4. │ ├── variables.tf
  5. │ └── outputs.tf
  6. ├── azure/
  7. │ ├── main.tf
  8. │ ├── variables.tf
  9. │ └── outputs.tf
  10. ├── gcp/
  11. │ ├── main.tf
  12. │ ├── variables.tf
  13. │ └── outputs.tf
  14. └── main.tfMain Terraform Configuration (main.tf)# Main Terraform configuration for multi-cloud provisioning
  15.  
  16. # Define providers for AWS, Azure, and GCP
  17. provider "aws" {
  18. region = "us-east-1" # Specify your AWS region
  19. }
  20.  
  21. provider "azurerm" {
  22. features {}
  23. }
  24.  
  25. provider "google" {
  26. project = "your-gcp-project-id"
  27. region = "us-central1" # Specify your GCP region
  28. }
  29.  
  30. # Include configurations for AWS, Azure, and GCP modules
  31. module "aws_infrastructure" {
  32. source = "./aws"
  33. }
  34.  
  35. module "azure_infrastructure" {
  36. source = "./azure"
  37. }
  38.  
  39. module "gcp_infrastructure" {
  40. source = "./gcp"
  41. }AWS Configuration (aws/main.tf)# AWS resources configuration
  42. resource "aws_instance" "example" {
  43. ami = "ami-0c55b159cbfafe1f0"
  44. instance_type = "t2.micro"
  45.  
  46. tags = {
  47. Name = "example-instance"
  48. }
  49. }
  50.  
  51. # Define variables
  52. variable "aws_region" {
  53. default = "us-east-1"
  54. }
  55.  
  56. # Define outputs
  57. output "aws_instance_public_ip" {
  58. value = aws_instance.example.public_ip
  59. }Azure Configuration (azure/main.tf)# Azure resources configuration
  60. resource "azurerm_virtual_machine" "example" {
  61. name = "example-vm"
  62. location = "East US"
  63. resource_group_name = "example-resources"
  64. vm_size = "Standard_DS1_v2"
  65.  
  66. storage_image_reference {
  67. publisher = "Canonical"
  68. offer = "UbuntuServer"
  69. sku = "16.04-LTS"
  70. version = "latest"
  71. }
  72.  
  73. os_profile {
  74. computer_name = "hostname"
  75. admin_username = "adminuser"
  76.  
  77. admin_ssh_key {
  78. username = "adminuser"
  79. public_key = file("~/.ssh/id_rsa.pub")
  80. }
  81. }
  82.  
  83. tags = {
  84. environment = "production"
  85. }
  86. }
  87.  
  88. # Define variables
  89. variable "azure_location" {
  90. default = "East US"
  91. }
  92.  
  93. # Define outputs
  94. output "azure_vm_public_ip" {
  95. value = azurerm_virtual_machine.example.network_interface_ids[0]
  96. }GCP Configuration (gcp/main.tf)# GCP resources configuration
  97. resource "google_compute_instance" "example" {
  98. name = "example-instance"
  99. machine_type = "e2-medium"
  100. zone = "us-central1-a"
  101.  
  102. boot_disk {
  103. initialize_params {
  104. image = "debian-cloud/debian-10"
  105. }
  106. }
  107.  
  108. network_interface {
  109. network = "default"
  110. access_config {
  111. // Ephemeral IP
  112. }
  113. }
  114.  
  115. tags = ["web", "dev"]
  116.  
  117. metadata = {
  118. ssh-keys = "your-user:${file("~/.ssh/id_rsa.pub")}"
  119. }
  120. }
  121.  
  122. # Define variables
  123. variable "gcp_zone" {
  124. default = "us-central1-a"
  125. }
  126.  
  127. # Define outputs
  128. output "gcp_instance_public_ip" {
  129. value = google_compute_instance.example.network_interface[0].access_config[0].nat_ip
  130. }
Advertisement
Add Comment
Please, Sign In to add comment