main.tf

mail@pastecode.io avatar
unknown
yaml
2 months ago
2.7 kB
2
Indexable
Never
provider "azurerm" {
  features {}
}

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

data "azurerm_virtual_network" "example" {
  name                = "production"
  resource_group_name = var.resource_group_name
}

resource "azurerm_mysql_server" "example" {
  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" "example" {
  name                = "office"
  resource_group_name = azurerm_resource_group.example.name
  server_name         = azurerm_mysql_server.example.name
  start_ip_address    = "40.112.0.0"
  end_ip_address      = "40.112.255.255"
}

resource "azurerm_mysql_database" "example" {
  name                = var.mysql_database_name
  resource_group_name = data.azurerm_resource_group.wf_cd_2_rg.name
  server_name         = azurerm_mysql_server.example.name
  charset             = "utf8"
  collation           = "utf8_unicode_ci"

  # prevent the possibility of accidental data loss
  lifecycle {
    prevent_destroy = true
  }
}

resource "azurerm_app_service_plan" "example" {
  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

  sku {
    tier = "Standard"
    size = "S1"
  }
}

resource "azurerm_app_service" "example" {
  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
  app_service_plan_id = azurerm_app_service_plan.example.id

  site_config {
    dotnet_framework_version = "v5.0"
    scm_type                 = "LocalGit"
  }

  app_settings = {
    "SOME_KEY" = "some-value"
  }

  connection_string {
    name  = "Database"
    type  = "SQLServer"
    value = "Server=${azurerm_mysql_server.example.fqdn};Integrated Security=SSPI"
  }
}
Leave a Comment