-
Notifications
You must be signed in to change notification settings - Fork 4
Seed standalone NGINXaaS deployment #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
puneetsarna
wants to merge
1
commit into
main
Choose a base branch
from
ps-dev-standalone
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
terraform { | ||
required_version = "~> 1.3" | ||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = "~> 4.0" | ||
} | ||
} | ||
} | ||
|
||
provider "azurerm" { | ||
# Add your subscription ID here. | ||
subscription_id = "" | ||
features {} | ||
} | ||
|
||
# VARIABLES | ||
variable "location" { | ||
description = "Azure location name for NGINXaaS deployment." | ||
default = "eastus" | ||
} | ||
|
||
variable "name" { | ||
description = "Name of NGINXaaS deployment and related resources." | ||
default = "example-dev" | ||
} | ||
|
||
variable "sku" { | ||
description = "SKU of NGINXaaS deployment." | ||
default = "standardv2_Monthly" | ||
} | ||
|
||
variable "tags" { | ||
description = "Tags for NGINXaaS deployment and related resources." | ||
type = map(any) | ||
default = { | ||
env = "dev" | ||
} | ||
} | ||
|
||
# Azure Resources | ||
resource "azurerm_resource_group" "example" { | ||
name = var.name | ||
location = var.location | ||
|
||
tags = var.tags | ||
} | ||
|
||
resource "azurerm_public_ip" "example" { | ||
name = var.name | ||
resource_group_name = azurerm_resource_group.example.name | ||
location = azurerm_resource_group.example.location | ||
sku = "Standard" | ||
allocation_method = "Static" | ||
} | ||
|
||
resource "azurerm_virtual_network" "example" { | ||
name = var.name | ||
location = azurerm_resource_group.example.location | ||
resource_group_name = azurerm_resource_group.example.name | ||
address_space = ["10.0.0.0/27"] | ||
|
||
tags = var.tags | ||
} | ||
|
||
resource "azurerm_subnet" "example" { | ||
name = var.name | ||
resource_group_name = azurerm_resource_group.example.name | ||
virtual_network_name = azurerm_virtual_network.example.name | ||
address_prefixes = ["10.0.0.0/27"] | ||
|
||
delegation { | ||
name = "nginx" | ||
service_delegation { | ||
name = "NGINX.NGINXPLUS/nginxDeployments" | ||
actions = [ | ||
"Microsoft.Network/virtualNetworks/subnets/join/action" | ||
] | ||
} | ||
} | ||
} | ||
|
||
# WARNING: This opens up the NSG to allow traffic to deployment from anywhere. | ||
resource "azurerm_network_security_group" "example" { | ||
name = var.name | ||
location = azurerm_resource_group.example.location | ||
resource_group_name = azurerm_resource_group.example.name | ||
|
||
security_rule { | ||
name = var.name | ||
priority = 100 | ||
direction = "Inbound" | ||
access = "Allow" | ||
protocol = "Tcp" | ||
source_port_range = "*" | ||
destination_port_range = "*" | ||
source_address_prefix = "*" | ||
destination_address_prefix = "*" | ||
} | ||
|
||
tags = var.tags | ||
} | ||
|
||
resource "azurerm_subnet_network_security_group_association" "example" { | ||
subnet_id = azurerm_subnet.example.id | ||
network_security_group_id = azurerm_network_security_group.example.id | ||
} | ||
|
||
resource "azurerm_nginx_deployment" "example" { | ||
name = var.name | ||
resource_group_name = azurerm_resource_group.example.name | ||
sku = var.sku | ||
location = var.location | ||
capacity = 20 | ||
automatic_upgrade_channel = "stable" | ||
diagnose_support_enabled = true | ||
|
||
identity { | ||
type = "SystemAssigned" | ||
} | ||
|
||
frontend_public { | ||
ip_address = [azurerm_public_ip.example.id] | ||
} | ||
network_interface { | ||
subnet_id = azurerm_subnet.example.id | ||
} | ||
|
||
tags = var.tags | ||
} | ||
|
||
resource "azurerm_nginx_configuration" "example-config" { | ||
nginx_deployment_id = azurerm_nginx_deployment.example.id | ||
root_file = "/etc/nginx/nginx.conf" | ||
|
||
config_file { | ||
content = base64encode(<<-EOT | ||
user nginx; | ||
worker_processes auto; | ||
worker_rlimit_nofile 8192; | ||
pid /run/nginx/nginx.pid; | ||
|
||
events { | ||
worker_connections 4000; | ||
} | ||
|
||
error_log /var/log/nginx/error.log error; | ||
|
||
http { | ||
server { | ||
listen 80 default_server; | ||
server_name localhost; | ||
location / { | ||
return 200 'Hello World'; | ||
} | ||
} | ||
} | ||
EOT | ||
) | ||
virtual_path = "/etc/nginx/nginx.conf" | ||
} | ||
} | ||
|
||
# OUTPUTS | ||
|
||
output "ip_address" { | ||
description = "IP address of NGINXaaS deployment." | ||
value = azurerm_nginx_deployment.example.ip_address | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a short
README
next to this file?