Managing security groups with Terraform
Security groups, as you learned in the previous chapter, allow you to control what is able to communicate with your resources. In the previous section, we reused the security group that we've created last time, but it would be useful to understand how to create one from scratch.
Here's the example Terraform file again, with some new code added:
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "my-server-1" {
ami = "ami-0dba2cb6798deb6d8"
associate_public_ip_address = "true"
instance_type = "t2.micro"
key_name = "jay_ssh"
vpc_security_group_ids = [ "${aws_security_group.external_access.id}" ]
tags = {
Name = "Web Server 1"
}
}
resource "aws_security_group" "external_access" {
...