From 6e92813daaec824b8db77a26905176a7d8a73bc9 Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Mon, 31 Aug 2015 10:19:02 +0200 Subject: [PATCH] examples: unify the configuration file syntax --- examples/aws-asg/main.tf | 70 ++++++++-------- examples/aws-asg/outputs.tf | 10 +-- examples/aws-asg/variables.tf | 34 ++++---- examples/aws-count/main.tf | 2 +- examples/aws-count/variables.tf | 16 ++-- examples/aws-eip/main.tf | 59 +++++++------ examples/aws-eip/variables.tf | 14 ++-- examples/aws-elb/main.tf | 88 ++++++++++---------- examples/aws-elb/variables.tf | 14 ++-- examples/aws-rds/main.tf | 28 +++---- examples/aws-rds/outputs.tf | 6 +- examples/aws-rds/sg-variables.tf | 8 +- examples/aws-rds/sg.tf | 16 ++-- examples/aws-rds/subnet-variables.tf | 18 ++-- examples/aws-rds/subnets.tf | 24 +++--- examples/aws-rds/variables.tf | 36 ++++---- examples/aws-s3-cross-account-access/main.tf | 64 +++++++------- examples/aws-two-tier/main.tf | 54 ++++++------ examples/aws-two-tier/variables.tf | 20 ++--- examples/consul/main.tf | 44 +++++----- examples/consul/variables.tf | 16 ++-- examples/cross-provider/main.tf | 4 +- examples/cross-provider/variables.tf | 2 +- examples/google-two-tier/main.tf | 88 ++++++++++---------- examples/google-two-tier/output.tf | 4 +- examples/google-two-tier/variables.tf | 8 +- 26 files changed, 372 insertions(+), 375 deletions(-) diff --git a/examples/aws-asg/main.tf b/examples/aws-asg/main.tf index 6ced0aa78..9dbb9ede5 100644 --- a/examples/aws-asg/main.tf +++ b/examples/aws-asg/main.tf @@ -1,6 +1,6 @@ # Specify the provider and access details provider "aws" { - region = "${var.aws_region}" + region = "${var.aws_region}" } resource "aws_elb" "web-elb" { @@ -36,49 +36,49 @@ resource "aws_autoscaling_group" "web-asg" { load_balancers = ["${aws_elb.web-elb.name}"] #vpc_zone_identifier = ["${split(",", var.availability_zones)}"] tag { - key = "Name" - value = "web-asg" - propagate_at_launch = "true" - } + key = "Name" + value = "web-asg" + propagate_at_launch = "true" } +} resource "aws_launch_configuration" "web-lc" { - name = "terraform-example-lc" - image_id = "${lookup(var.aws_amis, var.aws_region)}" - instance_type = "${var.instance_type}" - # Security group - security_groups = ["${aws_security_group.default.name}"] - user_data = "${file("userdata.sh")}" - key_name = "${var.key_name}" + name = "terraform-example-lc" + image_id = "${lookup(var.aws_amis, var.aws_region)}" + instance_type = "${var.instance_type}" + # Security group + security_groups = ["${aws_security_group.default.name}"] + user_data = "${file("userdata.sh")}" + key_name = "${var.key_name}" } # Our default security group to access # the instances over SSH and HTTP resource "aws_security_group" "default" { - name = "terraform_example_sg" - description = "Used in the terraform" + name = "terraform_example_sg" + description = "Used in the terraform" - # SSH access from anywhere - ingress { - from_port = 22 - to_port = 22 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } + # SSH access from anywhere + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } - # HTTP access from anywhere - ingress { - from_port = 80 - to_port = 80 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } + # HTTP access from anywhere + ingress { + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } - # outbound internet access - egress { - from_port = 0 - to_port = 0 - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] - } + # outbound internet access + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } } diff --git a/examples/aws-asg/outputs.tf b/examples/aws-asg/outputs.tf index afd78f134..a85793efb 100644 --- a/examples/aws-asg/outputs.tf +++ b/examples/aws-asg/outputs.tf @@ -1,12 +1,12 @@ output "security_group" { - value = "${aws_security_group.default.id}" + value = "${aws_security_group.default.id}" } output "launch_configuration" { - value = "${aws_launch_configuration.web-lc.id}" + value = "${aws_launch_configuration.web-lc.id}" } output "asg_name" { - value = "${aws_autoscaling_group.web-asg.id}" + value = "${aws_autoscaling_group.web-asg.id}" } output "elb_name" { - value = "${aws_elb.web-elb.dns_name}" -} \ No newline at end of file + value = "${aws_elb.web-elb.dns_name}" +} diff --git a/examples/aws-asg/variables.tf b/examples/aws-asg/variables.tf index b51450911..0171e4704 100644 --- a/examples/aws-asg/variables.tf +++ b/examples/aws-asg/variables.tf @@ -1,42 +1,42 @@ variable "aws_region" { - description = "The AWS region to create things in." - default = "us-east-1" + description = "The AWS region to create things in." + default = "us-east-1" } # ubuntu-trusty-14.04 (x64) variable "aws_amis" { - default = { - "us-east-1" = "ami-5f709f34" - "us-west-2" = "ami-7f675e4f" - } + default = { + "us-east-1" = "ami-5f709f34" + "us-west-2" = "ami-7f675e4f" + } } variable "availability_zones" { - default = "us-east-1b,us-east-1c,us-east-1d,us-east-1e" - description = "List of availability zones, use AWS CLI to find your " + default = "us-east-1b,us-east-1c,us-east-1d,us-east-1e" + description = "List of availability zones, use AWS CLI to find your " } variable "key_name" { - description = "Name of AWS key pair" + description = "Name of AWS key pair" } variable "instance_type" { - default = "t2.micro" - description = "AWS instance type" + default = "t2.micro" + description = "AWS instance type" } variable "asg_min" { - description = "Min numbers of servers in ASG" - default = "1" + description = "Min numbers of servers in ASG" + default = "1" } variable "asg_max" { - description = "Max numbers of servers in ASG" - default = "2" + description = "Max numbers of servers in ASG" + default = "2" } variable "asg_desired" { - description = "Desired numbers of servers in ASG" - default = "1" + description = "Desired numbers of servers in ASG" + default = "1" } diff --git a/examples/aws-count/main.tf b/examples/aws-count/main.tf index 419c1d8cd..3b06b5e5d 100644 --- a/examples/aws-count/main.tf +++ b/examples/aws-count/main.tf @@ -1,6 +1,6 @@ # Specify the provider and access details provider "aws" { - region = "${var.aws_region}" + region = "${var.aws_region}" } resource "aws_elb" "web" { diff --git a/examples/aws-count/variables.tf b/examples/aws-count/variables.tf index c7bdf20a7..e0913851b 100644 --- a/examples/aws-count/variables.tf +++ b/examples/aws-count/variables.tf @@ -1,14 +1,14 @@ variable "aws_region" { - description = "The AWS region to create things in." - default = "us-west-2" + description = "The AWS region to create things in." + default = "us-west-2" } # Ubuntu Precise 12.04 LTS (x64) variable "aws_amis" { - default = { - "eu-west-1" = "ami-b1cf19c6" - "us-east-1" = "ami-de7ab6b6" - "us-west-1" = "ami-3f75767a" - "us-west-2" = "ami-21f78e11" - } + default = { + "eu-west-1" = "ami-b1cf19c6" + "us-east-1" = "ami-de7ab6b6" + "us-west-1" = "ami-3f75767a" + "us-west-2" = "ami-21f78e11" + } } diff --git a/examples/aws-eip/main.tf b/examples/aws-eip/main.tf index 62757a6fe..2b2b1d234 100644 --- a/examples/aws-eip/main.tf +++ b/examples/aws-eip/main.tf @@ -1,42 +1,42 @@ # Specify the provider and access details provider "aws" { - region = "${var.aws_region}" + region = "${var.aws_region}" } resource "aws_eip" "default" { - instance = "${aws_instance.web.id}" - vpc = true + instance = "${aws_instance.web.id}" + vpc = true } # Our default security group to access # the instances over SSH and HTTP resource "aws_security_group" "default" { - name = "eip_example" - description = "Used in the terraform" + name = "eip_example" + description = "Used in the terraform" - # SSH access from anywhere - ingress { - from_port = 22 - to_port = 22 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } + # SSH access from anywhere + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } - # HTTP access from anywhere - ingress { - from_port = 80 - to_port = 80 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } + # HTTP access from anywhere + ingress { + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } - # outbound internet access - egress { - from_port = 0 - to_port = 0 - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] - } + # outbound internet access + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } } @@ -62,8 +62,7 @@ resource "aws_instance" "web" { # this should be on port 80 user_data = "${file("userdata.sh")}" #Instance tags - tags { - Name = "eip-example" - } + tags { + Name = "eip-example" + } } - diff --git a/examples/aws-eip/variables.tf b/examples/aws-eip/variables.tf index d1f0d0d6c..2c27e03cd 100644 --- a/examples/aws-eip/variables.tf +++ b/examples/aws-eip/variables.tf @@ -1,17 +1,17 @@ variable "aws_region" { - description = "The AWS region to create things in." - default = "us-east-1" + description = "The AWS region to create things in." + default = "us-east-1" } # ubuntu-trusty-14.04 (x64) variable "aws_amis" { - default = { - "us-east-1" = "ami-5f709f34" - "us-west-2" = "ami-7f675e4f" - } + default = { + "us-east-1" = "ami-5f709f34" + "us-west-2" = "ami-7f675e4f" + } } variable "key_name" { - description = "Name of the SSH keypair to use in AWS." + description = "Name of the SSH keypair to use in AWS." } diff --git a/examples/aws-elb/main.tf b/examples/aws-elb/main.tf index 6542a91ef..4051e0087 100644 --- a/examples/aws-elb/main.tf +++ b/examples/aws-elb/main.tf @@ -1,64 +1,62 @@ # Specify the provider and access details provider "aws" { - region = "${var.aws_region}" + region = "${var.aws_region}" } # Our default security group to access # the instances over SSH and HTTP resource "aws_security_group" "default" { - name = "instance_sg" - description = "Used in the terraform" + name = "instance_sg" + description = "Used in the terraform" - # SSH access from anywhere - ingress { - from_port = 22 - to_port = 22 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } + # SSH access from anywhere + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } - # HTTP access from anywhere - ingress { - from_port = 80 - to_port = 80 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } + # HTTP access from anywhere + ingress { + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } - # outbound internet access - egress { - from_port = 0 - to_port = 0 - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] - } + # outbound internet access + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } } # Our elb security group to access # the ELB over HTTP resource "aws_security_group" "elb" { - name = "elb_sg" - description = "Used in the terraform" + name = "elb_sg" + description = "Used in the terraform" - # HTTP access from anywhere - ingress { - from_port = 80 - to_port = 80 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } + # HTTP access from anywhere + ingress { + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } - # outbound internet access - egress { - from_port = 0 - to_port = 0 - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] - } - + # outbound internet access + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } } - resource "aws_elb" "web" { name = "example-elb" @@ -117,7 +115,7 @@ resource "aws_instance" "web" { user_data = "${file("userdata.sh")}" #Instance tags - tags { - Name = "elb-example" - } + tags { + Name = "elb-example" + } } diff --git a/examples/aws-elb/variables.tf b/examples/aws-elb/variables.tf index 150ffa36c..e776d6ecc 100644 --- a/examples/aws-elb/variables.tf +++ b/examples/aws-elb/variables.tf @@ -1,17 +1,17 @@ variable "key_name" { - description = "Name of the SSH keypair to use in AWS." + description = "Name of the SSH keypair to use in AWS." } variable "aws_region" { - description = "AWS region to launch servers." - default = "us-east-1" + description = "AWS region to launch servers." + default = "us-east-1" } # ubuntu-trusty-14.04 (x64) variable "aws_amis" { - default = { - "us-east-1" = "ami-5f709f34" - "us-west-2" = "ami-7f675e4f" - } + default = { + "us-east-1" = "ami-5f709f34" + "us-west-2" = "ami-7f675e4f" + } } diff --git a/examples/aws-rds/main.tf b/examples/aws-rds/main.tf index d292a38af..cb329ac18 100644 --- a/examples/aws-rds/main.tf +++ b/examples/aws-rds/main.tf @@ -1,19 +1,19 @@ resource "aws_db_instance" "default" { - depends_on = "aws_security_group.default" - identifier = "${var.identifier}" - allocated_storage = "${var.storage}" - engine = "${var.engine}" - engine_version = "${lookup(var.engine_version, var.engine)}" - instance_class = "${var.instance_class}" - name = "${var.db_name}" - username = "${var.username}" - password = "${var.password}" - vpc_security_group_ids = ["${aws_security_group.default.id}"] - db_subnet_group_name = "${aws_db_subnet_group.default.id}" + depends_on = "aws_security_group.default" + identifier = "${var.identifier}" + allocated_storage = "${var.storage}" + engine = "${var.engine}" + engine_version = "${lookup(var.engine_version, var.engine)}" + instance_class = "${var.instance_class}" + name = "${var.db_name}" + username = "${var.username}" + password = "${var.password}" + vpc_security_group_ids = ["${aws_security_group.default.id}"] + db_subnet_group_name = "${aws_db_subnet_group.default.id}" } resource "aws_db_subnet_group" "default" { - name = "main_subnet_group" - description = "Our main group of subnets" - subnet_ids = ["${aws_subnet.subnet_1.id}", "${aws_subnet.subnet_2.id}"] + name = "main_subnet_group" + description = "Our main group of subnets" + subnet_ids = ["${aws_subnet.subnet_1.id}", "${aws_subnet.subnet_2.id}"] } diff --git a/examples/aws-rds/outputs.tf b/examples/aws-rds/outputs.tf index 1bf2b0cb8..396497183 100644 --- a/examples/aws-rds/outputs.tf +++ b/examples/aws-rds/outputs.tf @@ -1,10 +1,10 @@ output "subnet_group" { - value = "${aws_db_subnet_group.default.name}" + value = "${aws_db_subnet_group.default.name}" } output "db_instance_id" { - value = "${aws_db_instance.default.id}" + value = "${aws_db_instance.default.id}" } output "db_instance_address" { - value = "${aws_db_instance.default.address}" + value = "${aws_db_instance.default.address}" } diff --git a/examples/aws-rds/sg-variables.tf b/examples/aws-rds/sg-variables.tf index a1fefe413..db9d10873 100644 --- a/examples/aws-rds/sg-variables.tf +++ b/examples/aws-rds/sg-variables.tf @@ -1,10 +1,10 @@ variable "cidr_blocks" { - default = "0.0.0.0/0" - description = "CIDR for sg" + default = "0.0.0.0/0" + description = "CIDR for sg" } variable "sg_name" { - default = "rds_sg" - description = "Tag Name for sg" + default = "rds_sg" + description = "Tag Name for sg" } diff --git a/examples/aws-rds/sg.tf b/examples/aws-rds/sg.tf index c55b0799d..6a3edde9f 100644 --- a/examples/aws-rds/sg.tf +++ b/examples/aws-rds/sg.tf @@ -4,17 +4,17 @@ resource "aws_security_group" "default" { vpc_id = "${var.vpc_id}" ingress { - from_port = 0 - to_port = 65535 - protocol = "TCP" - cidr_blocks = ["${var.cidr_blocks}"] + from_port = 0 + to_port = 65535 + protocol = "TCP" + cidr_blocks = ["${var.cidr_blocks}"] } egress { - from_port = 0 - to_port = 0 - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] } tags { diff --git a/examples/aws-rds/subnet-variables.tf b/examples/aws-rds/subnet-variables.tf index 35c695088..c4563081b 100644 --- a/examples/aws-rds/subnet-variables.tf +++ b/examples/aws-rds/subnet-variables.tf @@ -1,24 +1,24 @@ variable "subnet_1_cidr" { - default = "10.0.1.0/24" - description = "Your AZ" + default = "10.0.1.0/24" + description = "Your AZ" } variable "subnet_2_cidr" { - default = "10.0.2.0/24" - description = "Your AZ" + default = "10.0.2.0/24" + description = "Your AZ" } variable "az_1" { - default = "us-east-1b" - description = "Your Az1, use AWS CLI to find your account specific" + default = "us-east-1b" + description = "Your Az1, use AWS CLI to find your account specific" } variable "az_2" { - default = "us-east-1c" - description = "Your Az2, use AWS CLI to find your account specific" + default = "us-east-1c" + description = "Your Az2, use AWS CLI to find your account specific" } variable "vpc_id" { - description = "Your VPC ID" + description = "Your VPC ID" } diff --git a/examples/aws-rds/subnets.tf b/examples/aws-rds/subnets.tf index 5de7d0d82..31e83a042 100644 --- a/examples/aws-rds/subnets.tf +++ b/examples/aws-rds/subnets.tf @@ -1,19 +1,19 @@ resource "aws_subnet" "subnet_1" { - vpc_id = "${var.vpc_id}" - cidr_block = "${var.subnet_1_cidr}" - availability_zone = "${var.az_1}" + vpc_id = "${var.vpc_id}" + cidr_block = "${var.subnet_1_cidr}" + availability_zone = "${var.az_1}" - tags { - Name = "main_subnet1" - } + tags { + Name = "main_subnet1" + } } resource "aws_subnet" "subnet_2" { - vpc_id = "${var.vpc_id}" - cidr_block = "${var.subnet_2_cidr}" - availability_zone = "${var.az_2}" + vpc_id = "${var.vpc_id}" + cidr_block = "${var.subnet_2_cidr}" + availability_zone = "${var.az_2}" - tags { - Name = "main_subnet2" - } + tags { + Name = "main_subnet2" + } } diff --git a/examples/aws-rds/variables.tf b/examples/aws-rds/variables.tf index ad3156b1b..ea8f5b9ab 100644 --- a/examples/aws-rds/variables.tf +++ b/examples/aws-rds/variables.tf @@ -1,41 +1,41 @@ variable "identifier" { - default = "mydb-rds" - description = "Identifier for your DB" + default = "mydb-rds" + description = "Identifier for your DB" } variable "storage" { - default = "10" - description = "Storage size in GB" + default = "10" + description = "Storage size in GB" } variable "engine" { - default = "postgres" - description = "Engine type, example values mysql, postgres" + default = "postgres" + description = "Engine type, example values mysql, postgres" } variable "engine_version" { - description = "Engine version" - default = { - mysql = "5.6.22" - postgres = "9.4.1" - } + description = "Engine version" + default = { + mysql = "5.6.22" + postgres = "9.4.1" + } } variable "instance_class" { - default = "db.t2.micro" - description = "Instance class" + default = "db.t2.micro" + description = "Instance class" } variable "db_name" { - default = "mydb" - description = "db name" + default = "mydb" + description = "db name" } variable "username" { - default = "myuser" - description = "User name" + default = "myuser" + description = "User name" } variable "password" { - description = "password, provide through your ENV variables" + description = "password, provide through your ENV variables" } diff --git a/examples/aws-s3-cross-account-access/main.tf b/examples/aws-s3-cross-account-access/main.tf index ffe565bef..5cc9b9638 100644 --- a/examples/aws-s3-cross-account-access/main.tf +++ b/examples/aws-s3-cross-account-access/main.tf @@ -1,54 +1,54 @@ provider "aws" { - alias = "prod" + alias = "prod" - region = "us-east-1" - access_key = "${var.prod_access_key}" - secret_key = "${var.prod_secret_key}" + region = "us-east-1" + access_key = "${var.prod_access_key}" + secret_key = "${var.prod_secret_key}" } resource "aws_s3_bucket" "prod" { - provider = "aws.prod" + provider = "aws.prod" - bucket = "${var.bucket_name}" - acl = "private" - policy = < /usr/share/nginx/www/index.html service nginx start SCRIPT - } + } - service_account { - scopes = ["https://www.googleapis.com/auth/compute.readonly"] - } + service_account { + scopes = ["https://www.googleapis.com/auth/compute.readonly"] + } } resource "google_compute_firewall" "default" { - name = "tf-www-firewall" - network = "default" + name = "tf-www-firewall" + network = "default" - allow { - protocol = "tcp" - ports = ["80"] - } + allow { + protocol = "tcp" + ports = ["80"] + } - source_ranges = ["0.0.0.0/0"] - target_tags = ["www-node"] + source_ranges = ["0.0.0.0/0"] + target_tags = ["www-node"] } diff --git a/examples/google-two-tier/output.tf b/examples/google-two-tier/output.tf index 98302c87d..1774c3bb8 100644 --- a/examples/google-two-tier/output.tf +++ b/examples/google-two-tier/output.tf @@ -1,7 +1,7 @@ output "pool_public_ip" { - value = "${google_compute_forwarding_rule.default.ip_address}" + value = "${google_compute_forwarding_rule.default.ip_address}" } output "instance_ips" { - value = "${join(" ", google_compute_instance.www.*.network_interface.0.access_config.0.nat_ip)}" + value = "${join(" ", google_compute_instance.www.*.network_interface.0.access_config.0.nat_ip)}" } diff --git a/examples/google-two-tier/variables.tf b/examples/google-two-tier/variables.tf index 8219fd7d0..9330adfdf 100644 --- a/examples/google-two-tier/variables.tf +++ b/examples/google-two-tier/variables.tf @@ -1,15 +1,15 @@ variable "region" { - default = "us-central1" + default = "us-central1" } variable "region_zone" { - default = "us-central1-f" + default = "us-central1-f" } variable "project_name" { - description = "The ID of the Google Cloud project" + description = "The ID of the Google Cloud project" } variable "account_file_path" { - description = "Path to the JSON file used to describe your account credentials" + description = "Path to the JSON file used to describe your account credentials" }