main.tf

mail@pastecode.io avatar
unknown
plain_text
2 months ago
4.1 kB
3
Indexable
Never
provider "azurerm" {
  features {}
}

# Reference the existing resource group
data "azurerm_resource_group" "wf_cd_2_rg" {
  name = var.resource_group_name
}

output "id" {
  value = data.azurerm_resource_group.wf_cd_2_rg.id
}

output "location" {
  value = data.azurerm_resource_group.wf_cd_2_rg.location
}

data "azurerm_virtual_network" "wf-cd-2-vnet" {
  name                = "wf-cd-2-vnet"
  resource_group_name = var.resource_group_name
}

resource "azurerm_subnet" "sql_subnet" {
  name                 = "sql-subnet"
  resource_group_name  = "wf-cd-2"
  virtual_network_name = data.azurerm_virtual_network.wf-cd-2-vnet.name
  address_prefixes     = ["10.0.1.0/24"]
}

resource "azurerm_subnet" "app_service_subnet" {
  name                 = "app-service-subnet"
  resource_group_name  = "wf-cd-2"
  virtual_network_name = data.azurerm_virtual_network.wf-cd-2-vnet.name
  address_prefixes     = ["10.0.2.0/24"]
}

resource "azurerm_mysql_server" "wf-cd-2-sql" {
  name                = var.mysql_server_name
  location            = data.azurerm_resource_group.wf_cd_2_rg.location
  resource_group_name = data.azurerm_resource_group.wf_cd_2_rg.name

  administrator_login          = var.mysql_server_admin_login
  administrator_login_password = var.mysql_server_admin_password

  sku_name   = "GP_Gen5_2"
  storage_mb = 5120
  version    = "5.7"

  auto_grow_enabled                 = true
  backup_retention_days             = 7
  geo_redundant_backup_enabled      = true
  infrastructure_encryption_enabled = true
  public_network_access_enabled     = false
  ssl_enforcement_enabled           = true
  ssl_minimal_tls_version_enforced  = "TLS1_2"
}

resource "azurerm_mysql_firewall_rule" "wf-cd-2-fwrule" {
  name                = "office"
  resource_group_name = data.azurerm_resource_group.wf_cd_2_rg.name
  server_name         = azurerm_mysql_server.wf-cd-2-sql.name
  start_ip_address    = "40.112.0.0"
  end_ip_address      = "40.112.255.255"
}

resource "azurerm_mysql_database" "wf-cd-2-sqldb" {
  name                = var.mysql_database_name
  resource_group_name = data.azurerm_resource_group.wf_cd_2_rg.name
  server_name         = azurerm_mysql_server.wf-cd-2-sql.name
  charset             = "utf8"
  collation           = "utf8_unicode_ci"
  
  lifecycle {
    prevent_destroy = true
  }
}

resource "azurerm_service_plan" "wf-cd-2-svplan" {
  name                = var.app_service_plan_name
  location            = data.azurerm_resource_group.wf_cd_2_rg.location
  resource_group_name = data.azurerm_resource_group.wf_cd_2_rg.name
  os_type             = "Linux"
  sku_name            = "B1"
}

resource "azurerm_linux_web_app" "wf-cd-2-apps" {
  name                = var.app_service_name
  location            = data.azurerm_resource_group.wf_cd_2_rg.location
  resource_group_name = data.azurerm_resource_group.wf_cd_2_rg.name
  service_plan_id     = azurerm_service_plan.wf-cd-2-svplan.id

  site_config {
    application_stack {
      dotnet_version = "7.0"
    }
  }

  connection_string {
    name  = "Database"
    type  = "SQLServer"
    value = "Server=${azurerm_mysql_server.wf-cd-2-sql.fqdn};Integrated Security=SSPI"
  }
}


resource "azurerm_private_endpoint" "sql_private_endpoint" {
  name                = "sql-private-endpoint"
  location            = data.azurerm_resource_group.wf_cd_2_rg.location
  resource_group_name = data.azurerm_resource_group.wf_cd_2_rg.name
  subnet_id           = azurerm_subnet.sql_subnet.id

  private_service_connection {
    name                           = "sql-private-service-connection"
    private_connection_resource_id = azurerm_mysql_server.wf-cd-2-sql.id
    is_manual_connection           = false
    subresource_names              = ["mysqlServer"]
  }
}

resource "azurerm_linux_web_app_virtual_network_swift_connection" "example" {
  linux_web_app_id = azurerm_linux_web_app.wf-cd-2-apps.id
  subnet_id        = azurerm_subnet.app_service_subnet.id
}
Leave a Comment