forked from SygniaLabs/ScallOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetwork.tf
73 lines (59 loc) · 1.87 KB
/
network.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# VPC and subnets
module "gcp-network" {
source = "terraform-google-modules/network/google"
project_id = var.project_id
network_name = "${var.infra_name}-offensive-pipeline-vpc"
subnets = [
{
subnet_name = "${var.infra_name}-offensive-pipeline-subnet"
subnet_ip = local.vpc_main_subnet
subnet_region = var.region
}
]
secondary_ranges = {
("${var.infra_name}-offensive-pipeline-subnet") = [
{
range_name = "${var.infra_name}-gke-pods-subnet"
ip_cidr_range = local.gke_pod_subnet
},
{
range_name = "${var.infra_name}-gke-service-subnet"
ip_cidr_range = local.gke_svc_subnet
}
]
}
}
# Operators access rule
resource "google_compute_firewall" "operators" {
name = "${var.infra_name}-operators-access"
network = module.gcp-network.network_name
provider = google.offensive-pipeline
source_ranges = var.operator_ips
target_tags = ["${var.infra_name}-gitlab"]
allow {
protocol = "tcp"
ports = var.operator_ports
}
}
# Rule allowing internal access from K8s' Pods to Gitlab
resource "google_compute_firewall" "pods-to-gitlab-access" {
name = "${var.infra_name}-gke-pods-gitlab-access"
network = module.gcp-network.network_name
provider = google.offensive-pipeline
source_ranges = [local.gke_pod_subnet]
target_tags = ["${var.infra_name}-gitlab"]
allow {
protocol = "tcp"
ports = var.operator_ports
}
}
# DNS Record
resource "google_dns_record_set" "ext-dns" {
provider = google.dns_infra
count = var.external_hostname != "" ? 1 : 0
name = "${var.external_hostname}."
type = "A"
ttl = var.dns_record_ttl
managed_zone = var.dns_managed_zone_name
rrdatas = [google_compute_instance.gitlab.network_interface.0.access_config.0.nat_ip]
}