main.tf modified

mail@pastecode.io avatar
unknown
plain_text
a month ago
4.6 kB
4
Indexable
Never
provider "azurerm" {
  features {}
}

data "azurerm_resource_group" "wf_cd_2_rg" {
  name = var.resource_group_name
}

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  = data.azurerm_resource_group.wf_cd_2_rg.name
  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  = data.azurerm_resource_group.wf_cd_2_rg.name
  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"
  depends_on          = [azurerm_mysql_server.wf-cd-2-sql]
}

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
  }
  depends_on          = [azurerm_mysql_server.wf-cd-2-sql]
}

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"
  depends_on          = [data.azurerm_resource_group.wf_cd_2_rg]
}

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"
  }
  depends_on          = [azurerm_service_plan.wf-cd-2-svplan]
}

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"]
  }
  depends_on          = [azurerm_subnet.sql_subnet, azurerm_mysql_server.wf-cd-2-sql]
}

resource "azurerm_linux_web_app_virtual_network_swift_connection" "wf-cd-2-swiftconn" {
  linux_web_app_id = azurerm_linux_web_app.wf-cd-2-apps.id
  subnet_id        = azurerm_subnet.app_service_subnet.id
  depends_on       = [azurerm_linux_web_app.wf-cd-2-apps, azurerm_subnet.app_service_subnet]
}

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

output "location" {
  value = data.azurerm_resource_group.wf_cd_2_rg.location
}
Leave a Comment