-
Notifications
You must be signed in to change notification settings - Fork 696
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Feature/private service connect module (#722)
* create the private service connector module * fixes the domain for dns * Fixes an warning regarding parameters suage * fixes the test * fix Copyright year * remove unused variables at private service connect module * add global_address_id output * fix lint * add private_service_connect_ip variable * fix lint issues Co-authored-by: Daniel da Silva Andrade <dandrade@ciandt.com>
- Loading branch information
1 parent
78c7d90
commit b3b9145
Showing
12 changed files
with
320 additions
and
218 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
26 changes: 26 additions & 0 deletions
26
3-networks/modules/base_shared_vpc/private_service_connect.tf
This file contains 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,26 @@ | ||
/** | ||
* Copyright 2022 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
|
||
module "private_service_connect" { | ||
source = "../private_service_connect" | ||
project_id = var.project_id | ||
network_id = module.main.network_self_link | ||
environment_code = var.environment_code | ||
network_self_link = module.main.network_self_link | ||
private_service_connect_ip = "10.3.0.5" | ||
forwarding_rule_target = "all-apis" | ||
} |
This file contains 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,114 @@ | ||
/** | ||
* Copyright 2022 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
/****************************************** | ||
Private Google APIs DNS Zone & records. | ||
*****************************************/ | ||
|
||
module "googleapis" { | ||
source = "terraform-google-modules/cloud-dns/google" | ||
version = "~> 4.0" | ||
project_id = var.project_id | ||
type = "private" | ||
name = "dz-${var.environment_code}-shared-${local.vpc_type}-apis" | ||
domain = "googleapis.com." | ||
description = "Private DNS zone to configure ${local.googleapis_url}" | ||
|
||
private_visibility_config_networks = [ | ||
var.network_self_link | ||
] | ||
|
||
recordsets = [ | ||
{ | ||
name = "*" | ||
type = "CNAME" | ||
ttl = 300 | ||
records = [local.googleapis_url] | ||
}, | ||
{ | ||
name = local.recordsets_name | ||
type = "A" | ||
ttl = 300 | ||
records = [var.private_service_connect_ip] | ||
}, | ||
] | ||
} | ||
|
||
/****************************************** | ||
GCR DNS Zone & records. | ||
*****************************************/ | ||
|
||
module "gcr" { | ||
source = "terraform-google-modules/cloud-dns/google" | ||
version = "~> 3.1" | ||
project_id = var.project_id | ||
type = "private" | ||
name = "dz-${var.environment_code}-shared-${local.vpc_type}-gcr" | ||
domain = "gcr.io." | ||
description = "Private DNS zone to configure gcr.io" | ||
|
||
private_visibility_config_networks = [ | ||
var.network_self_link | ||
] | ||
|
||
recordsets = [ | ||
{ | ||
name = "*" | ||
type = "CNAME" | ||
ttl = 300 | ||
records = ["gcr.io."] | ||
}, | ||
{ | ||
name = "" | ||
type = "A" | ||
ttl = 300 | ||
records = [var.private_service_connect_ip] | ||
}, | ||
] | ||
} | ||
|
||
/*********************************************** | ||
Artifact Registry DNS Zone & records. | ||
***********************************************/ | ||
|
||
module "pkg_dev" { | ||
source = "terraform-google-modules/cloud-dns/google" | ||
version = "~> 3.1" | ||
project_id = var.project_id | ||
type = "private" | ||
name = "dz-${var.environment_code}-shared-${local.vpc_type}-pkg-dev" | ||
domain = "pkg.dev." | ||
description = "Private DNS zone to configure pkg.dev" | ||
|
||
private_visibility_config_networks = [ | ||
var.network_self_link | ||
] | ||
|
||
recordsets = [ | ||
{ | ||
name = "*" | ||
type = "CNAME" | ||
ttl = 300 | ||
records = ["pkg.dev."] | ||
}, | ||
{ | ||
name = "" | ||
type = "A" | ||
ttl = 300 | ||
records = [var.private_service_connect_ip] | ||
}, | ||
] | ||
} |
This file contains 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,41 @@ | ||
/** | ||
* Copyright 2022 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
locals { | ||
vpc_type = var.forwarding_rule_target == "vpc-sc" ? "restricted" : "base" | ||
googleapis_url = var.forwarding_rule_target == "vpc-sc" ? "restricted.googleapis.com." : "private.googleapis.com." | ||
recordsets_name = split(".", local.googleapis_url)[0] | ||
} | ||
|
||
resource "google_compute_global_address" "private_service_connect" { | ||
provider = google-beta | ||
project = var.project_id | ||
name = "global-psconnect-ip" | ||
address_type = "INTERNAL" | ||
purpose = "PRIVATE_SERVICE_CONNECT" | ||
network = var.network_id | ||
address = var.private_service_connect_ip | ||
} | ||
|
||
resource "google_compute_global_forwarding_rule" "forwarding_rule_private_service_connect" { | ||
provider = google-beta | ||
project = var.project_id | ||
name = "globalrule" | ||
target = var.forwarding_rule_target | ||
network = var.network_id | ||
ip_address = google_compute_global_address.private_service_connect.id | ||
load_balancing_scheme = "" | ||
} |
This file contains 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,29 @@ | ||
/** | ||
* Copyright 2022 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
output "private_service_connect_ip" { | ||
value = var.private_service_connect_ip | ||
description = "The private service connect ip" | ||
|
||
depends_on = [ | ||
google_compute_global_forwarding_rule.forwarding_rule_private_service_connect | ||
] | ||
} | ||
|
||
output "global_address_id" { | ||
value = google_compute_global_address.private_service_connect.id | ||
description = "An identifier for the global address created for the private service connect with format `projects/{{project}}/global/addresses/{{name}}`" | ||
} |
This file contains 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,50 @@ | ||
/** | ||
* Copyright 2022 Google LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
variable "project_id" { | ||
description = "Project ID for Private Service Connect." | ||
type = string | ||
} | ||
|
||
variable "network_id" { | ||
description = "Network ID for Private Service Connect." | ||
type = string | ||
} | ||
|
||
variable "network_self_link" { | ||
description = "Network self link for Private Service Connect." | ||
type = string | ||
} | ||
|
||
variable "environment_code" { | ||
description = "A short form of the folder level resources (environment) within the Google Cloud organization." | ||
type = string | ||
} | ||
|
||
variable "private_service_connect_ip" { | ||
description = "The internal IP to be used for the private service connect." | ||
type = string | ||
} | ||
|
||
variable "forwarding_rule_target" { | ||
description = "Target resource to receive the matched traffic. Only `all-apis` and `vpc-sc` are valid." | ||
type = string | ||
|
||
validation { | ||
condition = var.forwarding_rule_target == "all-apis" || var.forwarding_rule_target == "vpc-sc" | ||
error_message = "For forwarding_rule_target only `all-apis` and `vpc-sc` are valid." | ||
} | ||
} |
Oops, something went wrong.