Skip to content

Commit 001fefb

Browse files
WodansSontombuildsstuff
andauthoredMay 13, 2020
fixes #5864 and #6763
* Adding private endpoint example HCL * Update examples/private_endpoint/postgreSql/README.md Co-authored-by: Tom Harvey <[email protected]> * Update examples/private_endpoint/cosmosDb/README.md Co-authored-by: Tom Harvey <[email protected]> * Requested changes per PR review * Update location descriptions in README.md Co-authored-by: Tom Harvey <[email protected]>
1 parent 2bb29c1 commit 001fefb

File tree

12 files changed

+252
-80
lines changed

12 files changed

+252
-80
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Example: Private Endpoint
2+
3+
This example provisions a Private Endpoint in Azure connected to a CosmosDB Account configured with MongoDB.
4+
5+
### Variables
6+
7+
* `prefix` - (Required) The prefix used for all resources in this example.
8+
9+
* `location` - (Required) The Azure Region in which all resources in this example should be created.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
provider "azurerm" {
2+
features {}
3+
}
4+
5+
resource "azurerm_resource_group" "example" {
6+
name = "${var.prefix}-resources"
7+
location = "${var.location}"
8+
}
9+
10+
resource "azurerm_virtual_network" "example" {
11+
name = "${var.prefix}-vnet"
12+
address_space = ["10.0.0.0/16"]
13+
location = azurerm_resource_group.example.location
14+
resource_group_name = azurerm_resource_group.example.name
15+
}
16+
17+
resource "azurerm_subnet" "endpoint" {
18+
name = "endpoint"
19+
resource_group_name = azurerm_resource_group.example.name
20+
virtual_network_name = azurerm_virtual_network.example.name
21+
address_prefix = "10.0.2.0/24"
22+
23+
enforce_private_link_endpoint_network_policies = true
24+
}
25+
26+
resource "azurerm_cosmosdb_account" "example" {
27+
name = "${var.prefix}-cosmosdb-example"
28+
location = azurerm_resource_group.example.location
29+
resource_group_name = azurerm_resource_group.example.name
30+
offer_type = "Standard"
31+
kind = "MongoDB"
32+
33+
enable_automatic_failover = false
34+
is_virtual_network_filter_enabled = true
35+
ip_range_filter = "104.42.195.92,40.76.54.131,52.176.6.30,52.169.50.45,52.187.184.26"
36+
37+
capabilities {
38+
name = "EnableMongo"
39+
}
40+
41+
consistency_policy {
42+
consistency_level = "BoundedStaleness"
43+
max_interval_in_seconds = 310
44+
max_staleness_prefix = 101000
45+
}
46+
47+
geo_location {
48+
prefix = "${var.prefix}-cosmos-db-customid"
49+
location = azurerm_resource_group.example.location
50+
failover_priority = 0
51+
}
52+
}
53+
54+
resource "azurerm_private_endpoint" "example" {
55+
name = "${var.prefix}-pe"
56+
location = azurerm_resource_group.example.location
57+
resource_group_name = azurerm_resource_group.example.name
58+
subnet_id = azurerm_subnet.endpoint.id
59+
60+
private_service_connection {
61+
name = "tfex-cosmosdb-connection"
62+
is_manual_connection = false
63+
private_connection_resource_id = azurerm_cosmosdb_account.example.id
64+
subresource_names = ["MongoDB"]
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Example: Private Endpoint
2+
3+
This example provisions a Private Endpoint which connects to a PostgreSQL server within Azure.
4+
5+
### Variables
6+
7+
* `prefix` - (Required) The prefix used for all resources in this example.
8+
9+
* `location` - (Required) The Azure Region in which all resources in this example should be created.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
provider "azurerm" {
2+
features {}
3+
}
4+
5+
resource "azurerm_resource_group" "example" {
6+
name = "${var.prefix}-resources"
7+
location = "${var.location}"
8+
}
9+
10+
resource "azurerm_virtual_network" "example" {
11+
name = "${var.prefix}-vnet"
12+
address_space = ["10.0.0.0/16"]
13+
location = azurerm_resource_group.example.location
14+
resource_group_name = azurerm_resource_group.example.name
15+
}
16+
17+
resource "azurerm_subnet" "endpoint" {
18+
name = "endpoint"
19+
resource_group_name = azurerm_resource_group.example.name
20+
virtual_network_name = azurerm_virtual_network.example.name
21+
address_prefix = "10.0.2.0/24"
22+
23+
enforce_private_link_endpoint_network_policies = true
24+
}
25+
26+
resource "azurerm_postgresql_server" "example" {
27+
name = "${var.prefix}-postgresql"
28+
location = azurerm_resource_group.example.location
29+
resource_group_name = azurerm_resource_group.example.name
30+
31+
administrator_login = "psqladmin"
32+
administrator_login_password = "H@Sh1CoR3!"
33+
auto_grow_enabled = true
34+
backup_retention_days = 7
35+
geo_redundant_backup_enabled = false
36+
sku_name = "GP_Gen5_2"
37+
ssl_enforcement_enabled = true
38+
storage_mb = 51200
39+
version = "11"
40+
}
41+
42+
resource "azurerm_private_endpoint" "example" {
43+
name = "${var.prefix}-pe"
44+
location = azurerm_resource_group.example.location
45+
resource_group_name = azurerm_resource_group.example.name
46+
subnet_id = azurerm_subnet.endpoint.id
47+
48+
private_service_connection {
49+
name = "tfex-postgresql-connection"
50+
is_manual_connection = false
51+
private_connection_resource_id = azurerm_postgresql_server.example.id
52+
subresource_names = ["postgresqlServer"]
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
variable "prefix" {
2+
description = "The Prefix used for all resources in this example"
3+
}
4+
5+
variable "location" {
6+
description = "The Azure Region in which all resources in this example should be created."
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Example: Private Endpoint
2+
3+
This example provisions a Private Endpoint which connects to a Private Link Service within Azure.
4+
5+
### Variables
6+
7+
* `prefix` - (Required) The prefix used for all resources in this example.
8+
9+
* `location` - (Required) The Azure Region in which all resources in this example should be created.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
provider "azurerm" {
2+
features {}
3+
}
4+
5+
data "azurerm_subscription" "current" {}
6+
7+
resource "azurerm_resource_group" "example" {
8+
name = "${var.prefix}-resources"
9+
location = "${var.location}"
10+
}
11+
12+
resource "azurerm_virtual_network" "example" {
13+
name = "${var.prefix}-vnet"
14+
address_space = ["10.0.0.0/16"]
15+
location = azurerm_resource_group.example.location
16+
resource_group_name = azurerm_resource_group.example.name
17+
}
18+
19+
resource "azurerm_subnet" "service" {
20+
name = "service"
21+
resource_group_name = azurerm_resource_group.example.name
22+
virtual_network_name = azurerm_virtual_network.example.name
23+
address_prefix = "10.0.1.0/24"
24+
25+
enforce_private_link_service_network_policies = true
26+
}
27+
28+
resource "azurerm_subnet" "endpoint" {
29+
name = "endpoint"
30+
resource_group_name = azurerm_resource_group.example.name
31+
virtual_network_name = azurerm_virtual_network.example.name
32+
address_prefix = "10.0.2.0/24"
33+
34+
enforce_private_link_endpoint_network_policies = true
35+
}
36+
37+
resource "azurerm_public_ip" "example" {
38+
name = "${var.prefix}-pip"
39+
sku = "Standard"
40+
location = azurerm_resource_group.example.location
41+
resource_group_name = azurerm_resource_group.example.name
42+
allocation_method = "Static"
43+
}
44+
45+
resource "azurerm_lb" "example" {
46+
name = "${var.prefix}-lb"
47+
sku = "Standard"
48+
location = azurerm_resource_group.example.location
49+
resource_group_name = azurerm_resource_group.example.name
50+
51+
frontend_ip_configuration {
52+
name = azurerm_public_ip.example.name
53+
public_ip_address_id = azurerm_public_ip.example.id
54+
}
55+
}
56+
57+
resource "azurerm_private_link_service" "example" {
58+
name = "${var.prefix}-pls"
59+
location = azurerm_resource_group.example.location
60+
resource_group_name = azurerm_resource_group.example.name
61+
62+
auto_approval_subscription_ids = [data.azurerm_subscription.current.subscription_id]
63+
visibility_subscription_ids = [data.azurerm_subscription.current.subscription_id]
64+
65+
nat_ip_configuration {
66+
name = azurerm_public_ip.example.name
67+
subnet_id = azurerm_subnet.service.id
68+
primary = true
69+
}
70+
71+
load_balancer_frontend_ip_configuration_ids = [azurerm_lb.example.frontend_ip_configuration.0.id]
72+
}
73+
74+
resource "azurerm_private_endpoint" "example" {
75+
name = "${var.prefix}-pe"
76+
location = azurerm_resource_group.example.location
77+
resource_group_name = azurerm_resource_group.example.name
78+
subnet_id = azurerm_subnet.endpoint.id
79+
80+
private_service_connection {
81+
name = "tfex-pls-connection"
82+
is_manual_connection = false
83+
private_connection_resource_id = azurerm_private_link_service.example.id
84+
}
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
variable "prefix" {
2+
description = "The Prefix used for all resources in this example"
3+
}
4+
5+
variable "location" {
6+
description = "The Azure Region in which all resources in this example should be created."
7+
}

‎examples/private_endpoint/README.md

-9
This file was deleted.

‎examples/private_endpoint/main.tf

-71
This file was deleted.

‎website/docs/r/private_endpoint.html.markdown

+6
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ The following attributes are exported:
151151

152152
* `id` - The ID of the Private Endpoint.
153153

154+
## Example HCL Configurations
155+
156+
* How to connect a `Private Endpoint` to a [Cosmos MongoDB](https://github.com/terraform-providers/terraform-provider-azurerm/tree/master/examples/private-endpoint/cosmos-db)
157+
* How to connect a `Private Endpoint` to a [PostgreSQL Server](https://github.com/terraform-providers/terraform-provider-azurerm/tree/master/examples/private-endpoint/postgresql)
158+
* How to connect a `Private Endpoint` to a [Private Link Service](https://github.com/terraform-providers/terraform-provider-azurerm/tree/master/examples/private-endpoint/private-link-service)
159+
154160
## Timeouts
155161

156162
The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:

0 commit comments

Comments
 (0)
Please sign in to comment.