Skip to content

Commit

Permalink
Change TF resource and data names to use underscores
Browse files Browse the repository at this point in the history
  • Loading branch information
ldx committed Aug 21, 2020
1 parent a646194 commit 90a029b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 42 deletions.
44 changes: 22 additions & 22 deletions deploy/terraform-aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ locals {
}
}

data "aws_availability_zones" "available-azs" {
data "aws_availability_zones" "available_azs" {
state = "available"
exclude_zone_ids = var.excluded_azs
}

resource "random_shuffle" "azs" {
input = data.aws_availability_zones.available-azs.names
input = data.aws_availability_zones.available_azs.names
result_count = 1
}

Expand Down Expand Up @@ -82,7 +82,7 @@ resource "aws_subnet" "subnet" {
tags = local.k8s_cluster_tags
}

resource "aws_route_table" "route-table" {
resource "aws_route_table" "route_table" {
vpc_id = aws_vpc.main.id

route {
Expand All @@ -99,9 +99,9 @@ resource "aws_route_table" "route-table" {
}
}

resource "aws_route_table_association" "route-table-to-subnet" {
resource "aws_route_table_association" "route_table_to_subnet" {
subnet_id = aws_subnet.subnet.id
route_table_id = aws_route_table.route-table.id
route_table_id = aws_route_table.route_table.id
}

resource "aws_efs_file_system" "efs" {
Expand Down Expand Up @@ -159,7 +159,7 @@ resource "aws_security_group" "kubernetes" {
tags = local.k8s_cluster_tags
}

resource "aws_iam_role" "k8s-node" {
resource "aws_iam_role" "k8s_node" {
name = "k8s-node-${var.cluster_name}"
assume_role_policy = <<EOF
{
Expand All @@ -179,9 +179,9 @@ EOF
tags = local.k8s_cluster_tags
}

resource "aws_iam_role_policy" "k8s-node" {
resource "aws_iam_role_policy" "k8s_node" {
name = "k8s-node-${var.cluster_name}"
role = aws_iam_role.k8s-node.id
role = aws_iam_role.k8s_node.id
policy = <<EOF
{
"Version": "2012-10-17",
Expand Down Expand Up @@ -293,12 +293,12 @@ resource "aws_iam_role_policy" "k8s-node" {
EOF
}

resource "aws_iam_instance_profile" "k8s-node" {
resource "aws_iam_instance_profile" "k8s_node" {
name = "k8s-node-${var.cluster_name}"
role = aws_iam_role.k8s-node.name
role = aws_iam_role.k8s_node.name
}

resource "random_id" "k8stoken-prefix" {
resource "random_id" "k8stoken_prefix" {
byte_length = 3
}

Expand All @@ -309,7 +309,7 @@ resource "random_id" "k8stoken-suffix" {
locals {
k8stoken = format(
"%s.%s",
random_id.k8stoken-prefix.hex,
random_id.k8stoken_prefix.hex,
random_id.k8stoken-suffix.hex,
)
}
Expand All @@ -318,7 +318,7 @@ data "external" "manifest" {
program = ["bash", "-c", "set -e; set -o pipefail; kustomize build ${var.kustomize_dir} | jq -s -R '{\"output\": .}'"]
}

data "template_file" "node-userdata" {
data "template_file" "node_userdata" {
template = file("${path.module}/node.sh")

vars = {
Expand Down Expand Up @@ -349,31 +349,31 @@ data "aws_ami" "ubuntu" {
locals {
node_ami = length(var.node_ami) > 0 ? var.node_ami : data.aws_ami.ubuntu.id
create_ssh_key = length(var.ssh_key_name) > 0 ? false : true
ssh_key_name = local.create_ssh_key ? aws_key_pair.ssh-key.0.key_name : var.ssh_key_name
ssh_key_name = local.create_ssh_key ? aws_key_pair.ssh_key.0.key_name : var.ssh_key_name
}

resource "tls_private_key" "ssh-key" {
resource "tls_private_key" "ssh_key" {
count = local.create_ssh_key ? 1 : 0
algorithm = "RSA"
}

resource "aws_key_pair" "ssh-key" {
resource "aws_key_pair" "ssh_key" {
count = local.create_ssh_key ? 1 : 0
key_name = "ssh-key-${var.cluster_name}"
public_key = tls_private_key.ssh-key.0.public_key_openssh
public_key = tls_private_key.ssh_key.0.public_key_openssh

tags = local.k8s_cluster_tags
}

resource "aws_instance" "k8s-node" {
resource "aws_instance" "k8s_node" {
ami = local.node_ami
instance_type = "t3.medium"
subnet_id = aws_subnet.subnet.id
user_data = data.template_file.node-userdata.rendered
user_data = data.template_file.node_userdata.rendered
key_name = local.ssh_key_name
associate_public_ip_address = true
vpc_security_group_ids = [aws_security_group.kubernetes.id]
iam_instance_profile = aws_iam_instance_profile.k8s-node.id
iam_instance_profile = aws_iam_instance_profile.k8s_node.id
source_dest_check = false

root_block_device {
Expand All @@ -385,14 +385,14 @@ resource "aws_instance" "k8s-node" {
type = "ssh"
user = "ubuntu"
host = self.public_ip
private_key = local.create_ssh_key ? tls_private_key.ssh-key.0.private_key_pem : null
private_key = local.create_ssh_key ? tls_private_key.ssh_key.0.private_key_pem : null
}
inline = [
"timeout 600 bash -x -c 'echo Waiting for cluster to come up; while true; do kubectl cluster-info && kubectl get svc kubernetes && exit 0; sleep 5; done'",
]
}

depends_on = [aws_internet_gateway.gw, aws_key_pair.ssh-key]
depends_on = [aws_internet_gateway.gw, aws_key_pair.ssh_key]

tags = merge(local.k8s_cluster_tags,
{"Name" = "${var.cluster_name}-node"})
Expand Down
2 changes: 1 addition & 1 deletion deploy/terraform-aws/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
output "node-ip" {
value = aws_instance.k8s-node.public_ip
value = aws_instance.k8s_node.public_ip
}

output "efs-ip" {
Expand Down
2 changes: 1 addition & 1 deletion deploy/terraform-gcp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ resource "google_container_cluster" "cluster" {
}
}

resource "google_container_node_pool" "node-pool" {
resource "google_container_node_pool" "node_pool" {
name = "node-pool-${var.cluster_name}"
location = var.zone
cluster = google_container_cluster.cluster.name
Expand Down
36 changes: 18 additions & 18 deletions deploy/terraform-vpn/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module "vpc" {
}
}

resource "local_file" "vpn-deployment-yaml" {
resource "local_file" "vpn_deployment_yaml" {
content = templatefile("${path.module}/kustomization/vpn-deployment.yaml.tmpl", {
dnspolicy=var.vpn_hostnetwork ? "ClusterFirstWithHostNet" : "ClusterFirst",
hostnetwork=var.vpn_hostnetwork ? "true" : "false",
Expand All @@ -88,7 +88,7 @@ resource "local_file" "vpn-deployment-yaml" {
file_permission = "0644"
}

resource "local_file" "kustomization-yaml" {
resource "local_file" "kustomization_yaml" {
sensitive_content = templatefile("${path.module}/kustomization/kustomization.yaml.tmpl", {
aws_access_key_id=var.aws_access_key_id,
aws_secret_access_key=var.aws_secret_access_key,
Expand All @@ -97,7 +97,7 @@ resource "local_file" "kustomization-yaml" {
file_permission = "0600"
}

resource "local_file" "aws-vpn-client-env" {
resource "local_file" "aws_vpn_client_env" {
sensitive_content = templatefile("${path.module}/kustomization/aws-vpn-client.env.tmpl", {
tunnel1_address=module.vpn_gateway.vpn_connection_tunnel1_address,
tunnel1_cgw_inside_address=module.vpn_gateway.vpn_connection_tunnel1_cgw_inside_address,
Expand All @@ -118,7 +118,7 @@ resource "local_file" "aws-vpn-client-env" {
file_permission = "0600"
}

resource "local_file" "provider-yaml" {
resource "local_file" "provider_yaml" {
sensitive_content = templatefile("${path.module}/kustomization/provider.yaml.tmpl", {
name=var.name,
region=var.region,
Expand All @@ -130,15 +130,15 @@ resource "local_file" "provider-yaml" {
file_permission = "0600"
}

resource "local_file" "command-extra-args-yaml" {
resource "local_file" "command_extra_args_yaml" {
content = templatefile("${path.module}/kustomization/command-extra-args.yaml.tmpl", {
local_dns=var.local_dns,
})
filename = "${path.module}/kustomization/command-extra-args.yaml"
file_permission = "0644"
}

resource "local_file" "node-local-dns-yaml" {
resource "local_file" "node_local_dns_yaml" {
content = templatefile("${path.module}/kustomization/node-local-dns.yaml.tmpl", {
cluster_domain=var.cluster_domain,
local_dns=var.local_dns,
Expand All @@ -162,20 +162,20 @@ resource "null_resource" "deploy" {
}

triggers = {
vpn-deployment-yaml=local_file.vpn-deployment-yaml.content,
node-local-dns-yaml=local_file.node-local-dns-yaml.content
aws-vpn-client-env=local_file.aws-vpn-client-env.sensitive_content,
kustomization-yaml=local_file.kustomization-yaml.sensitive_content,
command-extra-args-yaml=local_file.command-extra-args-yaml.content,
provider-yaml=local_file.provider-yaml.sensitive_content,
vpn_deployment_yaml=local_file.vpn_deployment_yaml.content,
node_local_dns_yaml=local_file.node_local_dns_yaml.content
aws_vpn_client_env=local_file.aws_vpn_client_env.sensitive_content,
kustomization_yaml=local_file.kustomization_yaml.sensitive_content,
command_extra_args_yaml=local_file.command_extra_args_yaml.content,
provider_yaml=local_file.provider_yaml.sensitive_content,
}

depends_on = [
local_file.vpn-deployment-yaml,
local_file.node-local-dns-yaml,
local_file.aws-vpn-client-env,
local_file.kustomization-yaml,
local_file.command-extra-args-yaml,
local_file.provider-yaml,
local_file.vpn_deployment_yaml,
local_file.node_local_dns_yaml,
local_file.aws_vpn_client_env,
local_file.kustomization_yaml,
local_file.command_extra_args_yaml,
local_file.provider_yaml,
]
}

0 comments on commit 90a029b

Please sign in to comment.