Implementing Cloud Design Patterns for AWS(Second Edition)
上QQ阅读APP看书,第一时间看更新

Regions

So far, all of our work has been done in the US-East region of AWS. The following map shows that there are a few other options too:  https://aws.amazon.com/about-aws/global-infrastructure/.

To increase the availability of our product, we'll add another region at the bottom of our main.tf file:

provider "aws" {
region = "us-west-2"
alias = "west"
}

A new VPC will allow us to further isolate our resources from tenants within our own organization. Let's create a vpc.tf file as follows. We'll keep the network address space the same for simplicity for the moment:

resource "aws_vpc" "mainvpc" {
cidr_block = "10.1.0.0/16"
}

resource "aws_vpc" "mainvpc_west" {
provider = "aws.west"
cidr_block = "10.2.0.0/16"
}

Now, let's create some new instance resources. We will use the same base AMI in both areas, but put these virtual machines in different regions, also in vpc.tf:

# Virginia
resource "aws_instance" "cheap_worker" {
# the below ami is for the latest Bitnami Wordpress East
ami = "ami-001e1c1159ccfe992"
instance_type = "t2.micro"
availability_zone = "us-east-1d"
associate_public_ip_address = true

tags {
Name = "CheapWorker"
}
}
output "id" {
value = "${aws_instance.cheap_worker.id}"
}
output "ip" {
value = "${aws_instance.cheap_worker.public_ip}"
}

# Oregon
resource "aws_instance" "cheap_worker_west" {
# the below ami is for the latest Bitnami Wordpress West
ami = "ami-000ce50ab0df5943f"
provider = "aws.west"
instance_type = "t2.micro"
availability_zone = "us-west-2c"
associate_public_ip_address = true

tags {
Name = "CheapWorker"
}
}
output "id_west" {
value = "${aws_instance.cheap_worker_west.id}"
}
output "ip_west" {
value = "${aws_instance.cheap_worker_west.public_ip}"
}
Notice that, even though we are using the same version of WordPress provided by Bitnami, the AMIs are different in the east and west catalogs.