Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform 0.12.0 lint #177

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
3 changes: 1 addition & 2 deletions build/golang/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.14.4-stretch
FROM golang:1.16.7-stretch
RUN apt-get update && \
apt-get install -y \
curl \
Expand Down Expand Up @@ -36,7 +36,6 @@ RUN go get -tags netgo \
github.com/fzipp/gocyclo \
github.com/gogo/protobuf/gogoproto \
github.com/gogo/protobuf/protoc-gen-gogoslick \
github.com/golang/dep/... \
golang.org/x/lint/golint \
github.com/golang/protobuf/protoc-gen-go \
github.com/kisielk/errcheck \
Expand Down
19 changes: 19 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module github.com/weaveworks/build-tools

go 1.16

require (
github.com/FiloSottile/gvt v0.0.0-20180825041312-4899cb1641fb // indirect
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 // indirect
github.com/client9/misspell v0.3.4 // indirect
github.com/fzipp/gocyclo v0.3.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/kisielk/errcheck v1.6.0 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mjibson/esc v0.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/weaveworks/common v0.0.0-20210722103813-e649eff5ab4a // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/tools v0.1.5
)
468 changes: 468 additions & 0 deletions go.sum

Large diffs are not rendered by default.

53 changes: 27 additions & 26 deletions provisioning/aws/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Specify the provider and access details
provider "aws" {
# Access key, secret key and region are sourced from environment variables or input arguments -- see README.md
region = "${var.aws_dc}"
region = var.aws_dc
version = "~> 3.37"
}

resource "aws_security_group" "allow_ssh" {
Expand All @@ -16,9 +17,9 @@ resource "aws_security_group" "allow_ssh" {
cidr_blocks = ["${var.client_ip}/32"]
}

tags {
tags = {
Name = "${var.name}_allow_ssh"
App = "${var.app}"
App = "var.app"
CreatedBy = "terraform"
}
}
Expand All @@ -35,9 +36,9 @@ resource "aws_security_group" "allow_docker" {
cidr_blocks = ["${var.client_ip}/32"]
}

tags {
tags = {
Name = "${var.name}_allow_docker"
App = "${var.app}"
App = "var.app"
CreatedBy = "terraform"
}
}
Expand All @@ -54,9 +55,9 @@ resource "aws_security_group" "allow_weave" {
cidr_blocks = ["${var.client_ip}/32"]
}

tags {
tags = {
Name = "${var.name}_allow_weave"
App = "${var.app}"
App = "var.app"
CreatedBy = "terraform"
}
}
Expand All @@ -70,12 +71,12 @@ resource "aws_security_group" "allow_private_ingress" {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["${var.aws_vpc_cidr_block}"]
cidr_blocks = [var.aws_vpc_cidr_block]
}

tags {
tags = {
Name = "${var.name}_allow_private_ingress"
App = "${var.app}"
App = var.app
CreatedBy = "terraform"
}
}
Expand All @@ -92,46 +93,46 @@ resource "aws_security_group" "allow_all_egress" {
cidr_blocks = ["0.0.0.0/0"]
}

tags {
tags = {
Name = "${var.name}_allow_all_egress"
App = "${var.app}"
App = var.app
CreatedBy = "terraform"
}
}

resource "aws_instance" "tf_test_vm" {
instance_type = "${var.aws_size}"
count = "${var.num_hosts}"
instance_type = var.aws_size
count = var.num_hosts

# Lookup the correct AMI based on the region we specified
ami = "${lookup(var.aws_amis, var.aws_dc)}"
ami = lookup(var.aws_amis, var.aws_dc)

key_name = "${var.aws_public_key_name}"
key_name = var.aws_public_key_name

security_groups = [
"${aws_security_group.allow_ssh.name}",
"${aws_security_group.allow_docker.name}",
"${aws_security_group.allow_weave.name}",
"${aws_security_group.allow_private_ingress.name}",
"${aws_security_group.allow_all_egress.name}",
aws_security_group.allow_ssh.name,
aws_security_group.allow_docker.name,
aws_security_group.allow_weave.name,
aws_security_group.allow_private_ingress.name,
aws_security_group.allow_all_egress.name,
]

# Wait for machine to be SSH-able:
provisioner "remote-exec" {
inline = ["exit"]

connection {
host = aws_instance.tf_test_vm[count.index].public_ip
type = "ssh"

# Lookup the correct username based on the AMI we specified
user = "${lookup(var.aws_usernames, "${lookup(var.aws_amis, var.aws_dc)}")}"
private_key = "${file("${var.aws_private_key_path}")}"
user = lookup(var.aws_usernames, lookup(var.aws_amis, var.aws_dc))
private_key = file(var.aws_private_key_path)
}
}

tags {
tags = {
Name = "${var.name}-${count.index}"
App = "${var.app}"
App = var.app
CreatedBy = "terraform"
}
}
38 changes: 19 additions & 19 deletions provisioning/aws/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
output "username" {
value = "${lookup(var.aws_usernames, "${lookup(var.aws_amis, var.aws_dc)}")}"
value = lookup(var.aws_usernames, lookup(var.aws_amis, var.aws_dc))
}

output "public_ips" {
value = ["${aws_instance.tf_test_vm.*.public_ip}"]
value = [aws_instance.tf_test_vm.*.public_ip]
}

output "hostnames" {
value = "${join("\n",
"${formatlist("%v.%v.%v",
value = join("\n",
formatlist("%v.%v.%v",
aws_instance.tf_test_vm.*.tags.Name,
aws_instance.tf_test_vm.*.availability_zone,
var.app
)}"
)}"
)
)
}

# /etc/hosts file for the Droplets:
output "private_etc_hosts" {
value = "${join("\n",
"${formatlist("%v %v.%v.%v",
value = join("\n",
formatlist("%v %v.%v.%v",
aws_instance.tf_test_vm.*.private_ip,
aws_instance.tf_test_vm.*.tags.Name,
aws_instance.tf_test_vm.*.availability_zone,
var.app
)}"
)}"
)
)
}

# /etc/hosts file for the client:
output "public_etc_hosts" {
value = "${join("\n",
"${formatlist("%v %v.%v.%v",
value = join("\n",
formatlist("%v %v.%v.%v",
aws_instance.tf_test_vm.*.public_ip,
aws_instance.tf_test_vm.*.tags.Name,
aws_instance.tf_test_vm.*.availability_zone,
var.app
)}"
)}"
)
)
}

output "ansible_inventory" {
value = "${format("[all]\n%s", join("\n",
"${formatlist("%v private_ip=%v",
value = format("[all]\n%s", join("\n",
formatlist("%v private_ip=%v",
aws_instance.tf_test_vm.*.public_ip,
aws_instance.tf_test_vm.*.private_ip,
)}"
))}"
)
))
}

output "private_key_path" {
value = "${var.aws_private_key_path}"
value = var.aws_private_key_path
}
24 changes: 13 additions & 11 deletions provisioning/do/main.tf
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
provider "digitalocean" {
# See README.md for setup instructions.
version = "~> 2.8"
}

# Tags to label and organize droplets:
resource "digitalocean_tag" "name" {
name = "${var.name}"
name = var.name
}

resource "digitalocean_tag" "app" {
name = "${var.app}"
name = var.app
}

resource "digitalocean_tag" "terraform" {
name = "terraform"
}

resource "digitalocean_droplet" "tf_test_vm" {
ssh_keys = ["${var.do_public_key_id}"]
image = "${var.do_os}"
region = "${var.do_dc}"
size = "${var.do_size}"
ssh_keys = [var.do_public_key_id]
image = var.do_os
region = var.do_dc
size = var.do_size
name = "${var.name}-${count.index}"
count = "${var.num_hosts}"
count = var.num_hosts

tags = [
"${var.app}",
"${var.name}",
var.app,
var.name,
"terraform",
]

Expand All @@ -34,9 +35,10 @@ resource "digitalocean_droplet" "tf_test_vm" {
inline = ["exit"]

connection {
host = digitalocean_droplet.tf_test_vm[count.index].ipv4_address
type = "ssh"
user = "${var.do_username}"
private_key = "${file("${var.do_private_key_path}")}"
user = var.do_username
private_key = file(var.do_private_key_path)
}
}
}
38 changes: 19 additions & 19 deletions provisioning/do/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
output "username" {
value = "${var.do_username}"
value = var.do_username
}

output "public_ips" {
value = ["${digitalocean_droplet.tf_test_vm.*.ipv4_address}"]
value = [digitalocean_droplet.tf_test_vm.*.ipv4_address]
}

output "hostnames" {
value = "${join("\n",
"${formatlist("%v.%v.%v",
value = join("\n",
formatlist("%v.%v.%v",
digitalocean_droplet.tf_test_vm.*.name,
digitalocean_droplet.tf_test_vm.*.region,
var.app
)}"
)}"
)
)
}

# /etc/hosts file for the Droplets:
# N.B.: by default Digital Ocean droplets only have public IPs, but in order to
# be consistent with other providers' recipes, we provide an output to generate
# an /etc/hosts file on the Droplets, even though it is using public IPs only.
output "private_etc_hosts" {
value = "${join("\n",
"${formatlist("%v %v.%v.%v",
value = join("\n",
formatlist("%v %v.%v.%v",
digitalocean_droplet.tf_test_vm.*.ipv4_address,
digitalocean_droplet.tf_test_vm.*.name,
digitalocean_droplet.tf_test_vm.*.region,
var.app
)}"
)}"
)
)
}

# /etc/hosts file for the client:
output "public_etc_hosts" {
value = "${join("\n",
"${formatlist("%v %v.%v.%v",
value = join("\n",
formatlist("%v %v.%v.%v",
digitalocean_droplet.tf_test_vm.*.ipv4_address,
digitalocean_droplet.tf_test_vm.*.name,
digitalocean_droplet.tf_test_vm.*.region,
var.app
)}"
)}"
)
)
}

output "ansible_inventory" {
value = "${format("[all]\n%s", join("\n",
"${formatlist("%v private_ip=%v",
value = format("[all]\n%s", join("\n",
formatlist("%v private_ip=%v",
digitalocean_droplet.tf_test_vm.*.ipv4_address,
digitalocean_droplet.tf_test_vm.*.ipv4_address
)}"
))}"
)
))
}

output "private_key_path" {
value = "${var.do_private_key_path}"
value = var.do_private_key_path
}