Skip to content

Commit

Permalink
Merge pull request #12 from lgfa29/update-refactor
Browse files Browse the repository at this point in the history
feat: reorganização de arquivos e atualizações
  • Loading branch information
lgfa29 authored Aug 6, 2022
2 parents df7329f + fe18375 commit 584aeb6
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: actions/checkout@v2

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@master
uses: google-github-actions/setup-gcloud@v0.6.0
with:
service_account_key: ${{ secrets.GCP_KEY }}
project_id: mentoria-iac-staging
Expand Down
34 changes: 34 additions & 0 deletions clients.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
data "google_compute_zones" "us-central1" {
region = var.region
}

module "nomad_clients" {
source = "github.com/mentoriaiac/iac-modulo-compute-gcp.git?ref=v0.2.1"
count = 2

project = var.project
zone = data.google_compute_zones.us-central1.names[count.index % length(data.google_compute_zones.us-central1.names)]

instance_name = "client-${count.index + 1}"
instance_image = "nomad-v0-3-0"
machine_type = "e2-small"

network = module.network_gcp.vpc_id
subnetwork = module.network_gcp.subnets[0].id
tags = ["nomad", "consul"]

metadata_startup_script = <<EOF
/usr/local/bin/nomad_bootstrap.sh client '\"provider=gce project_name=${var.project} tag_value=nomad-server\"' global dc1 nomad-ca-cert:1 nomad-client-cert:1 nomad-client-key:1
/usr/local/bin/consul_bootstrap.sh agent '\"provider=gce project_name=${var.project} tag_value=consul\"'
EOF

roles = [
"roles/secretmanager.secretAccessor",
"roles/compute.viewer",
]

labels = {
terraform = "true",
component = "nomad_client"
}
}
20 changes: 0 additions & 20 deletions local.tf

This file was deleted.

95 changes: 0 additions & 95 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,99 +1,4 @@
# colocar a chamada do módulo aqui

## Exemplo

provider "google" {
project = var.project
region = var.region
}

module "network_gcp" {
source = "github.com/mentoriaiac/iac-modulo-rede-gcp.git?ref=v0.2.0"
project = var.project
region = var.region
vpc_name = "rede-mentoria"
direction = "INGRESS"
target_tags = ["nomad", "consul"]
source_tags = ["nomad", "consul"]
subnetworks = [
{
name = "subnet-nomad"
ip_cidr_range = "10.0.0.0/16"
region = var.region
}
]

firewall_allow = [
{
protocol = "tcp"
port = [
22,
# Nomad
4646, 4647, 4648,
# Consul
"8300-8302", "8500-8502", 8600, "21000-21255",
]
}
]
}

module "nomad_servers" {
source = "github.com/mentoriaiac/iac-modulo-compute-gcp.git?ref=v0.2.0"

for_each = local.server_pool

project = var.project
instance_name = each.key
instance_image = each.value.instance_image
machine_type = each.value.machine_type
zone = each.value.zone
network = module.network_gcp.vpc_id
subnetwork = module.network_gcp.subnets[0].id
metadata_startup_script = <<EOF
/usr/local/bin/nomad_bootstrap.sh server 3 '\"provider=gce project_name=${var.project} tag_value=nomad-server\"'
/usr/local/bin/consul_bootstrap.sh server 3 '\"provider=gce project_name=${var.project} tag_value=consul\"'
EOF
tags = ["nomad", "nomad-server", "consul"]
labels = {
terraform = "true",
component = "nomad_server"
}
service_account_scopes = [
"https://www.googleapis.com/auth/compute.readonly",
]
}


data "google_compute_zones" "us-central1" {
# project = mentoria-terraform
region = var.region
}

module "nomad_clients" {
source = "github.com/mentoriaiac/iac-modulo-compute-gcp.git?ref=v0.2.0"

count = 3

project = var.project
instance_name = "client-${count.index + 1}"
machine_type = "e2-medium"
instance_image = "orquestradores-v0-2-0"
zone = data.google_compute_zones.us-central1.names[count.index % length(data.google_compute_zones.us-central1.names)]
network = module.network_gcp.vpc_id
subnetwork = module.network_gcp.subnets[0].id
metadata_startup_script = <<EOF
/usr/local/bin/nomad_bootstrap.sh client '\"provider=gce project_name=${var.project} tag_value=nomad-server\"'
/usr/local/bin/consul_bootstrap.sh agent '\"provider=gce project_name=${var.project} tag_value=consul\"'
EOF

service_account_scopes = [
"https://www.googleapis.com/auth/compute.readonly",
]

tags = ["nomad", "consul"]
labels = {
terraform = "true",
component = "nomad_client"
}
}

33 changes: 33 additions & 0 deletions network.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module "network_gcp" {
source = "github.com/mentoriaiac/iac-modulo-rede-gcp.git?ref=v0.2.0"

project = var.project
region = var.region

vpc_name = "rede-mentoria"
direction = "INGRESS"

target_tags = ["nomad", "consul"]
source_tags = ["nomad", "consul"]

subnetworks = [
{
name = "subnet-nomad"
ip_cidr_range = "10.0.0.0/16"
region = var.region
}
]

firewall_allow = [
{
protocol = "tcp"
port = [
22,
# Nomad
4646, 4647, 4648,
# Consul
"8300-8302", "8500-8502", 8600, "21000-21255",
]
}
]
}
50 changes: 50 additions & 0 deletions servers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
locals {
server_pool = {
server-node-1 = {
machine_type = "e2-small"
instance_image = "nomad-v0-3-0"
zone = "${var.region}-c"
},
server-node-2 = {
machine_type = "e2-small"
instance_image = "nomad-v0-3-0"
zone = "${var.region}-b"
},
server-node-3 = {
machine_type = "e2-small"
instance_image = "nomad-v0-3-0"
zone = "${var.region}-a"
}
}
}

module "nomad_servers" {
source = "github.com/mentoriaiac/iac-modulo-compute-gcp.git?ref=v0.2.1"
for_each = local.server_pool

project = var.project
zone = each.value.zone

instance_name = each.key
instance_image = each.value.instance_image
machine_type = each.value.machine_type

network = module.network_gcp.vpc_id
subnetwork = module.network_gcp.subnets[0].id
tags = ["nomad", "nomad-server", "consul"]

metadata_startup_script = <<EOF
/usr/local/bin/nomad_bootstrap.sh server 3 '\"provider=gce project_name=${var.project} tag_value=nomad-server\"' global dc1 nomad-ca-cert:1 nomad-server-cert:1 nomad-server-key:1
/usr/local/bin/consul_bootstrap.sh server 3 '\"provider=gce project_name=${var.project} tag_value=consul\"'
EOF

roles = [
"roles/secretmanager.secretAccessor",
"roles/compute.viewer",
]

labels = {
terraform = "true",
component = "nomad_server"
}
}

0 comments on commit 584aeb6

Please sign in to comment.