azurerm_nginx_deployment

Manages an NGINX Deployment.

Example Usage

resource "azurerm_resource_group" "example" {
  name     = "example-rg"
  location = "West Europe"
}

resource "azurerm_public_ip" "example" {
  name                = "example"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  allocation_method   = "Static"
  sku                 = "Standard"

  tags = {
    environment = "Production"
  }
}

resource "azurerm_virtual_network" "example" {
  name                = "example-vnet"
  address_space       = ["10.0.0.0/16"]
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
}

resource "azurerm_subnet" "example" {
  name                 = "example-subnet"
  resource_group_name  = azurerm_resource_group.example.name
  virtual_network_name = azurerm_virtual_network.example.name
  address_prefixes     = ["10.0.2.0/24"]
  delegation {
    name = "delegation"

    service_delegation {
      name = "NGINX.NGINXPLUS/nginxDeployments"
      actions = [
        "Microsoft.Network/virtualNetworks/subnets/join/action",
      ]
    }
  }
}

locals {
  config_content = base64encode(<<-EOT
http {
    server {
        listen 80;
        location / {
            auth_basic "Protected Area";
            auth_basic_user_file /opt/.htpasswd;
            default_type text/html;
        }
        include site/*.conf;
    }
}
EOT
  )

  protected_content = base64encode(<<-EOT
user:$apr1$VeUA5kt.$IjjRk//8miRxDsZvD4daF1
EOT
  )

  sub_config_content = base64encode(<<-EOT
location /bbb {
    default_type text/html;
    return 200 '<!doctype html><html lang="en"><head></head><body>
        <div>this one will be updated</div>
        <div>at 10:38 am</div>
    </body></html>';
}
EOT
  )
}


resource "azurerm_nginx_deployment" "example" {
  name                      = "example-nginx"
  resource_group_name       = azurerm_resource_group.example.name
  sku                       = "publicpreview_Monthly_gmz7xq9ge3py"
  location                  = azurerm_resource_group.example.location
  managed_resource_group    = "example"
  diagnose_support_enabled  = true
  automatic_upgrade_channel = "stable"

  frontend_public {
    ip_address = [azurerm_public_ip.example.id]
  }
  network_interface {
    subnet_id = azurerm_subnet.example.id
  }

  capacity = 20

  email = "user@test.com"
  configuration {
    root_file = "/etc/nginx/nginx.conf"

    config_file {
      content      = local.config_content
      virtual_path = "/etc/nginx/nginx.conf"
    }

    config_file {
      content      = local.sub_config_content
      virtual_path = "/etc/nginx/site/b.conf"
    }

    protected_file {
      content      = local.protected_content
      virtual_path = "/opt/.htpasswd"
    }
  }

  lifecycle {
    ignore_changes = [configuration.0.protected_file]
  }

}

Arguments Reference

The following arguments are supported:



A identity block supports the following:


A frontend_private block supports the following:


A frontend_public block supports the following:


A logging_storage_account block supports the following:


A network_interface block supports the following:


A configuration block supports the following:



A config_file block supports the following:


A protected_file (Protected File) block supports the following:

* virtual_path - (Required) Specify the path of this config file.

An auto_scale_profile block supports the following:

Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

Import

NGINX Deployments can be imported using the resource id, e.g.

terraform import azurerm_nginx_deployment.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Nginx.NginxPlus/nginxDeployments/dep1