From 4255c5d10c90f5548c20527dc30c3a727f280369 Mon Sep 17 00:00:00 2001 From: Simone Shiozawa Date: Fri, 24 Jan 2025 13:43:25 -0300 Subject: [PATCH] feat: adicionando arquivo de var --- README.md | 34 +++++++++++++- main.tf | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ var.tf | 25 ++++++++++ 3 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 main.tf create mode 100644 var.tf diff --git a/README.md b/README.md index 8a02c7e..d4c74e8 100644 --- a/README.md +++ b/README.md @@ -1 +1,33 @@ -# projeto-wordpress \ No newline at end of file +# Projeto DevOps - Ambiente WordPress + +O objetivo deste projeto é a contrução de servidores para executar uma aplicação wordpress. +A plataforma utilizada para a construção da infraestrutura foi a Microsoft Azure. + + +## Equipe + +**Squad Lotus** + +Integrantes: +- Adriana +- Fernanda +- Karin +- Karilene +- Simone + + +## Como implementar a infraestrutura + +``` +terraform init +terraform validate +terraform apply +``` + +Para destruir os serviços: + +``` +terraform destroy +``` + +É importante verificar via painel se o Grupo de recurso com todos os recursos foram excluídos. \ No newline at end of file diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..92c9f78 --- /dev/null +++ b/main.tf @@ -0,0 +1,138 @@ +# Configuração do provedor +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "4.16.0" + } + } +} + +#Autentica o usuario azure +provider "azurerm" { + features {} + + subscription_id = var.subscription_id +} + + +#Criação do grupo de recursos +resource "azurerm_resource_group" "wordpress" { + name = "rg-wordpress" + location = "eastus2" +} + +#Criação da rede virtual +resource "azurerm_virtual_network" "wordpress" { + name = "vnet-wordpress" + resource_group_name = azurerm_resource_group.wordpress.name + location = azurerm_resource_group.wordpress.location + address_space = ["10.0.0.0/16"] +} + +#Criação da subnet +resource "azurerm_subnet" "wordpress" { + name = "subnet-wordpress" + resource_group_name = azurerm_resource_group.wordpress.name + virtual_network_name = azurerm_virtual_network.wordpress.name + address_prefixes = ["10.0.1.0/24"] +} + +resource "azurerm_public_ip" "wordpress" { + name = "acceptanceTestPublicIp1" + resource_group_name = azurerm_resource_group.wordpress.name + location = azurerm_resource_group.wordpress.location + allocation_method = "Static" + + tags = { + environment = "Production" + } +} + +#Criação do plano de serviço do MySQL +resource "azurerm_mssql_server" "wordpress" { + name = "sqlserver-wordpress" + resource_group_name = azurerm_resource_group.wordpress.name + location = azurerm_resource_group.wordpress.location + version = "12.0" + administrator_login = var.administrator_login + administrator_login_password = var.administrator_login_password +} + +#Criação do database MySQL +resource "azurerm_mssql_database" "wordpress" { + name = "db-wordpress" + server_id = azurerm_mssql_server.wordpress.id + collation = "SQL_Latin1_General_CP1_CI_AS" + license_type = "LicenseIncluded" + max_size_gb = 2 + sku_name = "S0" + enclave_type = "VBS" + + # prevent the possibility of accidental data loss + lifecycle { + prevent_destroy = true + } +} + +#Criação da interface de rede +resource "azurerm_network_interface" "wordpress" { + name = "nic-wordpress" + resource_group_name = azurerm_resource_group.wordpress.name + location = azurerm_resource_group.wordpress.location + + ip_configuration { + name = "internal" + subnet_id = azurerm_subnet.wordpress.id + private_ip_address_allocation = "Dynamic" +} +} + +#Criação da máquina virtual +resource "azurerm_virtual_machine" "wordpress" { + name = "vm-wordpress" + location = azurerm_resource_group.wordpress.location + resource_group_name = azurerm_resource_group.wordpress.name + network_interface_ids = [azurerm_network_interface.wordpress.id] + vm_size = "Standard_DS1_v2" + + # Uncomment this line to delete the OS disk automatically when deleting the VM + delete_os_disk_on_termination = true + + # Uncomment this line to delete the data disks automatically when deleting the VM + delete_data_disks_on_termination = true + + storage_image_reference { + publisher = "Canonical" + offer = "0001-com-ubuntu-server-jammy" + sku = "22_04-lts" + version = "latest" + } + storage_os_disk { + name = "myosdisk1" + caching = "ReadWrite" + create_option = "FromImage" + managed_disk_type = "Standard_LRS" + } + os_profile { + computer_name = "hostname" + admin_username = var.admin_username + admin_password = var.admin_password + } + os_profile_linux_config { + disable_password_authentication = false + } + tags = { + environment = "staging" + } +} + +#Criação do disco +resource "azurerm_managed_disk" "wordpress" { + name = "disk-wordpress" + resource_group_name = azurerm_resource_group.wordpress.name + location = azurerm_resource_group.wordpress.location + storage_account_type = "Standard_LRS" + create_option = "Empty" + disk_size_gb = 32 +} \ No newline at end of file diff --git a/var.tf b/var.tf new file mode 100644 index 0000000..0d0a36f --- /dev/null +++ b/var.tf @@ -0,0 +1,25 @@ + +variable "subscription_id" { + description = "The Subscription ID for the Azure account" + type = string +} + +variable "administrator_login" { + description = "value for the administrator_login" + type = string +} + +variable "administrator_login_password" { + description = "value for the administrator_login_password" + type = string +} + +variable "admin_password" { + description = "value for the admin_password" + type = string +} + +variable "admin_username" { + description = "value for the admin_username" + type = string +}