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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
use tokio::process::Command;

pub async fn process_create_network(project_id: &str, service_name: &str) {
  let output = Command::new("gcloud")
    .args(
      &[
        "compute",
        "networks",
        "create",
        service_name,
        "--project",
        project_id
        ])
    .output()
    .await;
  println!("output = {:?}", output);
}

pub async fn process_create_firewall_tcp(project_id: &str, service_name: &str) {
  let output = Command::new("gcloud")
    .args(&[
      "compute",
      "firewall-rules",
      "create",
      "--network",
      service_name,
      "--allow",
      "tcp,udp,icmp",
      "--source-ranges",
      "10.124.0.0/28",
      "--project",
      project_id
    ])
    .output()
    .await;
  println!("output = {:?}", output);
}

pub async fn process_create_firewall_ssh(project_id: &str, service_name: &str) {
  let firewall = String::from(service_name) + "-ssh";
  let output = Command::new("gcloud")
    .args(&[
      "compute",
      "firewall-rules",
      "create",
      &firewall,
      "--network",
      service_name,
      "--allow",
      "tcp:22,tcp:3389,icmp",
      "--project",
      project_id
    ])
    .output()
    .await;
  println!("output = {:?}", output);
}

pub async fn process_create_subnet(project_id: &str, service_name: &str, region: &str) {
  let subnet = String::from(service_name) + "-subnet";
  let output = Command::new("gcloud")
    .args(&[
      "compute",
      "networks",
      "subnets",
      "create",
      &subnet,
      "--range",
      "10.124.0.0/28",
      "--network",
      service_name,
      "--region",
      region,
      "--project",
      project_id
    ])
    .output()
    .await;
  println!("output = {:?}", output);
}

pub async fn process_create_connector(project_id: &str, service_name: &str, region: &str) {
  let subnet = String::from(service_name) + "-subnet";
  let output = Command::new("gcloud")
    .args(&[
      "compute",
      "networks",
      "vpc-access",
      "connectors",
      "create",
      service_name,
      "--subnet",
      &subnet,
      "--subnet-project",
      project_id,
      "--region",
      region,
      "--project",
      project_id
    ])
    .output()
    .await;
  println!("output = {:?}", output);
}

pub async fn process_create_router(project_id: &str, service_name: &str, region: &str) {
  let router = String::from(service_name) + "-router";
  let output = Command::new("gcloud")
    .args(&[
      "compute",
      "routers",
      "create",
      &router,
      "--network",
      service_name,
      "--region",
      region,
      "--project",
      project_id
    ])
    .output()
    .await;
  println!("output = {:?}", output);
}

pub async fn process_create_external_ip(project_id: &str, service_name: &str, region: &str) {
  let external_ip = String::from(service_name) + "-ip";
  let output = Command::new("gcloud")
    .args(
      &[
        "compute",
        "addresses",
        "create",
        &external_ip,
        "--region",
        region,
        "--project",
        project_id
        ])
    .output()
    .await;
  println!("output = {:?}", output);
}

pub async fn process_create_nat(project_id: &str, service_name: &str, region: &str) {
  let nat = String::from(service_name) + "-nat";
  let router = String::from(service_name) + "-router";
  let nat_custom_subnet_ip_ranges = String::from(service_name) + "-subnet";
  let nat_external_ip_pool = String::from(service_name) + "-ip";
  let output = Command::new("gcloud")
    .args(&[
      "compute",
      "routers",
      "nats",
      "create",
      &nat,
      "--router",
      &router,
      "--region",
      region,
      "--nat-custom-subnet-ip-ranges",
      &nat_custom_subnet_ip_ranges,
      "--nat-external-ip-pool",
      &nat_external_ip_pool,
      "--project",
      project_id
    ])
    .output()
    .await;
  println!("output = {:?}", output);
}