Skip to content

Feature/update private endpoint #3

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
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
834e624
updated files
payasam-raghuramakrishna-nttd Aug 13, 2025
08ad2a0
updated files
payasam-raghuramakrishna-nttd Aug 13, 2025
137a0c0
updated files
payasam-raghuramakrishna-nttd Aug 13, 2025
e3d7a44
updated files
payasam-raghuramakrishna-nttd Aug 13, 2025
aa8af35
files updated
payasam-raghuramakrishna-nttd Aug 13, 2025
d3795d4
updated locals.tf files
payasam-raghuramakrishna-nttd Aug 14, 2025
c0a1034
updated files
payasam-raghuramakrishna-nttd Aug 14, 2025
0426610
updates files
payasam-raghuramakrishna-nttd Aug 14, 2025
f7c464b
uopdated file
payasam-raghuramakrishna-nttd Aug 14, 2025
f7a3e0a
updated files
payasam-raghuramakrishna-nttd Aug 14, 2025
bdde02a
updated main.tf
payasam-raghuramakrishna-nttd Aug 14, 2025
b8a819b
updated files
payasam-raghuramakrishna-nttd Aug 14, 2025
24b23a0
updated file
payasam-raghuramakrishna-nttd Aug 14, 2025
2d66e8a
updated files
payasam-raghuramakrishna-nttd Aug 17, 2025
632fe33
updated files
payasam-raghuramakrishna-nttd Aug 17, 2025
48729ac
updated files
payasam-raghuramakrishna-nttd Aug 17, 2025
0cdcbff
updated files
payasam-raghuramakrishna-nttd Aug 17, 2025
51045c3
updated files
payasam-raghuramakrishna-nttd Aug 18, 2025
2dbfef4
updated files
payasam-raghuramakrishna-nttd Aug 18, 2025
d4f991d
updated files
payasam-raghuramakrishna-nttd Aug 18, 2025
42af6d1
updated files
payasam-raghuramakrishna-nttd Aug 18, 2025
18d578a
updated files
payasam-raghuramakrishna-nttd Aug 18, 2025
20c9b48
Update main.tf
payasam-raghuramakrishna-nttd Aug 18, 2025
54d52df
Update main.tf
payasam-raghuramakrishna-nttd Aug 18, 2025
56be0a8
Update locals.tf
payasam-raghuramakrishna-nttd Aug 18, 2025
fc820f6
Update locals.tf
payasam-raghuramakrishna-nttd Aug 18, 2025
45134ae
Update main.tf
payasam-raghuramakrishna-nttd Aug 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# Local values for resource names and tags
locals {
resource_group_name = module.resource_names["resource_group"].standard
endpoint_name = "hygtmp-sandbox-004-neu-postgresql-001"
private_endpoint_tags = merge({ resource_name = local.endpoint_name }, local.default_tags, var.tags)
endpoint_name = var.endpoint_name
private_endpoint_tags = merge({ resource_name = local.endpoint_name }, local.default_tags, var.tags)
private_service_connection_name = "${local.endpoint_name}-psc"
default_tags = {
"provisioner" = "terraform"
default_tags = {
"provisioner" = "terraform"
}
private_endpoint_tags = merge({ resource_name = local.endpoint_name }, local.default_tags, var.tags)
private_service_connection_name = "hygtmp-sandbox-004-neu-postgresql-001-psc"
Copy link
Preview

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The endpoint name is hardcoded. This should be generated dynamically or made configurable to avoid conflicts when the module is used multiple times or in different environments.

Suggested change
private_service_connection_name = "hygtmp-sandbox-004-neu-postgresql-001-psc"
endpoint_name = var.endpoint_name
private_endpoint_tags = merge({ resource_name = local.endpoint_name }, local.default_tags, var.tags)
private_service_connection_name = "${local.endpoint_name}-psc"
default_tags = {
"provisioner" = "terraform"
}

Copilot uses AI. Check for mistakes.

Copy link
Preview

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is duplicated and will cause a Terraform configuration error. The same local value 'private_endpoint_tags' is defined multiple times.

Suggested change
private_service_connection_name = "hygtmp-sandbox-004-neu-postgresql-001-psc"
endpoint_name = var.endpoint_name
default_tags = {
"provisioner" = "terraform"
}
private_endpoint_tags = merge({ resource_name = local.endpoint_name }, local.default_tags, var.tags)
private_service_connection_name = "${local.endpoint_name}-psc"

Copilot uses AI. Check for mistakes.

Copy link
Preview

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line redefines 'endpoint_name' but references 'var.endpoint_name' which doesn't exist in the variables.tf file. This will cause a Terraform validation error.

Suggested change
private_service_connection_name = "hygtmp-sandbox-004-neu-postgresql-001-psc"
default_tags = {
"provisioner" = "terraform"
}
private_endpoint_tags = merge({ resource_name = local.endpoint_name }, local.default_tags, var.tags)
private_service_connection_name = "${local.endpoint_name}-psc"

Copilot uses AI. Check for mistakes.

Copy link
Preview

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'default_tags' local value definition is malformed and duplicated, missing proper block structure. This will cause a syntax error.

Suggested change
private_service_connection_name = "hygtmp-sandbox-004-neu-postgresql-001-psc"
default_tags = {
provisioner = "terraform"
}
private_endpoint_tags = merge({ resource_name = local.endpoint_name }, local.default_tags, var.tags)
private_service_connection_name = "${local.endpoint_name}-psc"

Copilot uses AI. Check for mistakes.

Copy link
Preview

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The private service connection name is hardcoded. This should be generated dynamically based on the endpoint name to maintain consistency and avoid conflicts.

Suggested change
private_service_connection_name = "hygtmp-sandbox-004-neu-postgresql-001-psc"
private_service_connection_name = "${local.endpoint_name}-psc"

Copilot uses AI. Check for mistakes.

}


23 changes: 23 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -101,3 +102,25 @@ module "postgresql_server_ad_administrator" {
principal_name = var.ad_administrator.principal_name
principal_type = var.ad_administrator.principal_type
}

module "private_endpoint" {
source = "terraform.registry.launch.nttdata.com/module_primitive/private_endpoint/azurerm"
version = "~> 1.0"

count = var.public_network_access_enabled ? 0 : 1

endpoint_name = local.endpoint_name
resource_group_name = local.resource_group_name
region = var.location
subnet_id = var.subnet_id
private_dns_zone_group_name = var.private_dns_zone_group_name
private_dns_zone_ids = var.private_dns_zone_ids
is_manual_connection = var.is_manual_connection
private_connection_resource_id = module.postgresql_server.id
subresource_names = var.subresource_names
request_message = var.request_message
tags = local.private_endpoint_tags
private_service_connection_name = local.private_service_connection_name

depends_on = [module.postgresql_server]
}
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ output "source_server_id" {

output "server_configuration" {
value = { for config in module.postgresql_server_configuration : config.name => config.value }
}
}
52 changes: 51 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,56 @@ variable "delegated_subnet_id" {
type = string
default = null
}
variable "subnet_id" {
description = <<EOT
The ID of the Subnet from which Private IP Addresses will be allocated for this Private Endpoint.
Changing this forces a new resource to be created.
EOT
type = string
default = null
}

variable "private_dns_zone_group_name" {
description = "Specifies the Name of the Private DNS Zone Group."
type = string
default = "vault"
Copy link
Preview

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value 'vault' is incorrect for a PostgreSQL private endpoint. It should be 'postgresqlServer' according to Azure documentation for PostgreSQL subresources.

Suggested change
default = "vault"
default = "postgresqlServer"

Copilot uses AI. Check for mistakes.

}


variable "private_dns_zone_ids" {
description = "A list of Private DNS Zone IDs to link with the Private Endpoint."
type = list(string)
default = []
}

variable "is_manual_connection" {
description = <<EOT
Does the Private Endpoint require Manual Approval from the remote resource owner? Changing this forces a new resource
to be created.
EOT
type = bool
default = false
}

variable "subresource_names" {
description = <<EOT
A list of subresource names which the Private Endpoint is able to connect to. subresource_names corresponds to group_id.
Possible values are detailed in the product documentation in the Subresources column.
https://docs.microsoft.com/azure/private-link/private-endpoint-overview#private-link-resource
EOT
type = list(string)
default = ["vault"]
Copy link
Preview

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default subresource name 'vault' is incorrect for PostgreSQL. It should be 'postgresqlServer' for Azure Database for PostgreSQL.

Suggested change
default = ["vault"]
default = ["postgresqlServer"]

Copilot uses AI. Check for mistakes.

}

variable "request_message" {
description = <<EOT
A message passed to the owner of the remote resource when the private endpoint attempts to establish the connection
to the remote resource. The request message can be a maximum of 140 characters in length.
Only valid if `is_manual_connection=true`
EOT
type = string
default = ""
}

variable "private_dns_zone_id" {
description = "The ID of the private DNS zone. Required when `delegated_subnet_id` is set"
Expand Down Expand Up @@ -339,4 +389,4 @@ variable "tags" {
description = "A mapping of tags to assign to the resource."
type = map(string)
default = {}
}
}
Loading