Note: The default ITS GitLab runner is a shared resource and is subject to slowdowns during heavy usage.
You can run your own GitLab runner that is dedicated just to your group if you need to avoid processing delays.

main.tf 3.69 KB
Newer Older
Kenny Moore's avatar
Kenny Moore committed
1
locals{
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    project_name_string = substr(lower(replace(var.project_name, "/\\s/", "-")), 0, 25)    
    curl_body           = {
        kind               = "project"
        security_contact   = var.security_contact
        mcomm_group_email  = var.mcomm_group_email
        shortcode          = var.shortcode
        vpn                = var.vpn  
        dt_phi             = var.dt_phi
        dt_ferpa           = var.dt_ferpa
        dt_pii             = var.dt_pii
        dt_glba            = var.dt_glba
        dt_hsr             = var.dt_hsr
        dt_ssn             = var.dt_ssn
        dt_acp             = var.dt_acp
        dt_it_sec_info     = var.dt_it_sec_info
        dt_itar            = var.dt_itar
        dt_pci             = var.dt_pci
        dt_fisma           = var.dt_fisma
        dt_other_data      = var.dt_other_data
        dt_other_data_info = var.dt_other_data_info
    }
Kenny Moore's avatar
Kenny Moore committed
23
24
}

Adam Robinson's avatar
Adam Robinson committed
25
26
27
28
resource "random_id" "id" {
    byte_length = 2
}

29
resource "google_project" "gcp_project" {    
Kenny Moore's avatar
Kenny Moore committed
30
    name = var.project_name
Kenny Moore's avatar
Kenny Moore committed
31
    project_id = var.project_id == "" ? "${local.project_name_string}-${random_id.id.hex}" : var.project_id
32
    folder_id = var.folder_id
Kenny Moore's avatar
Kenny Moore committed
33
    billing_account = var.billing_id
Kenny Moore's avatar
Kenny Moore committed
34
    auto_create_network = false
35
    labels = {
Kenny Moore's avatar
Kenny Moore committed
36
        "shortcode" = var.shortcode 
37
    }
38
39
}

40
41
42
resource "google_project_service" "compute_api" {
  project = google_project.gcp_project.project_id
  service = "compute.googleapis.com"
Kenny Moore's avatar
Kenny Moore committed
43
44
}

Kenny Moore's avatar
Kenny Moore committed
45
resource "google_project_service" "pubsub_api" {    
Kenny Moore's avatar
Kenny Moore committed
46
    project = google_project.gcp_project.project_id
Kenny Moore's avatar
Kenny Moore committed
47
    service = "pubsub.googleapis.com"
Kenny Moore's avatar
Kenny Moore committed
48
49
}

Adam Robinson's avatar
Adam Robinson committed
50
51
52
53
54
55
module "iam" {
    source            = "./modules/iam"
    project_id        = google_project.gcp_project.project_id
    mcomm_group_email = var.mcomm_group_email
}

Adam Robinson's avatar
Adam Robinson committed
56
57
58
59
module "logging" {
    source                       = "./modules/logging"
    project_id                   = google_project.gcp_project.project_id
    log_export_destination_topic = var.log_export_destination_topic
60
61
}

Kenny Moore's avatar
Kenny Moore committed
62
63
module "network" {
    source = "./modules/network"
Adam Robinson's avatar
Adam Robinson committed
64
65
66
67
68
    project_id     = google_project.gcp_project.project_id
    vpc_prefix     = var.vpc_prefix
    gke_vpc_ranges = var.gke_vpc_ranges
}

69
module "vpn" {
Adam Robinson's avatar
Adam Robinson committed
70
    source = "./modules/vpn"
Adam Robinson's avatar
Adam Robinson committed
71
    count  = var.vpn == true ? 1 : 0
72
73

    project_id      = google_project.gcp_project.project_id
74
    regions         = var.regions
75
76
77
78
    vpc_prefix      = var.vpc_prefix
    network_size    = var.vpn_network_size
    bgp_network     = var.vpn_bgp_network
    cloud_asn       = var.vpn_cloud_asn
79
    # um_vpn_endpoint = var.um_vpn_endpoint
80
}
81
82

# ## Receiving 404 error ##
Kenny Moore's avatar
Kenny Moore committed
83
data "google_service_account_id_token" "customer_db_token" {
Adam Robinson's avatar
Adam Robinson committed
84
    target_audience = var.customer_db_cloud_function_url
Kenny Moore's avatar
Kenny Moore committed
85
86
87
88
}

resource "null_resource" "customer_database" {
    triggers = {
Adam Robinson's avatar
Adam Robinson committed
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
        security_contact   = var.security_contact
        mcomm_group_email  = var.mcomm_group_email
        shortcode          = var.shortcode
        vpn                = var.vpn
        dt_phi             = var.dt_phi
        dt_ferpa           = var.dt_ferpa
        dt_pii             = var.dt_pii
        dt_glba            = var.dt_glba
        dt_hsr             = var.dt_hsr
        dt_ssn             = var.dt_ssn
        dt_acp             = var.dt_acp
        dt_it_sec_info     = var.dt_it_sec_info
        dt_itar            = var.dt_itar
        dt_pci             = var.dt_pci
        dt_fisma           = var.dt_fisma
        dt_other_data      = var.dt_other_data
Kenny Moore's avatar
Kenny Moore committed
105
106
        dt_other_data_info = var.dt_other_data_info
    }
107

Kenny Moore's avatar
Kenny Moore committed
108
    provisioner "local-exec" {
Adam Robinson's avatar
Adam Robinson committed
109
        command = "curl ${var.customer_db_cloud_function_url} -H \"Authorization: Bearer ${data.google_service_account_id_token.customer_db_token.id_token}\" -H \"Content-Type: application/json\" -d '${jsonencode(local.curl_body)}'"
Kenny Moore's avatar
Kenny Moore committed
110
    }
Adam Robinson's avatar
Adam Robinson committed
111
}