Skip to content

Instantly share code, notes, and snippets.

@kluu1
Last active October 6, 2020 15:43
Show Gist options
  • Select an option

  • Save kluu1/e30b577bdb8cb5846f5f2552860b4b74 to your computer and use it in GitHub Desktop.

Select an option

Save kluu1/e30b577bdb8cb5846f5f2552860b4b74 to your computer and use it in GitHub Desktop.

Revisions

  1. kluu1 revised this gist Oct 6, 2020. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions main.tf
    Original file line number Diff line number Diff line change
    @@ -42,10 +42,10 @@ data "aws_ami" "ubuntu" {
    }

    resource "aws_instance" "jenkins" {
    ami = data.aws_ami.ubuntu.id
    instance_type = "t2.micro"
    ami = data.aws_ami.ubuntu.id
    instance_type = "t2.micro"
    security_groups = [aws_security_group.web_traffic.name]
    key_name = "kluu"
    key_name = "kluu"

    tags = {
    "Name" = "Jenkins_Server"
  2. kluu1 revised this gist Oct 6, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions main.tf
    Original file line number Diff line number Diff line change
    @@ -45,6 +45,7 @@ resource "aws_instance" "jenkins" {
    ami = data.aws_ami.ubuntu.id
    instance_type = "t2.micro"
    security_groups = [aws_security_group.web_traffic.name]
    key_name = "kluu"

    tags = {
    "Name" = "Jenkins_Server"
  3. kluu1 revised this gist Oct 6, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions main.tf
    Original file line number Diff line number Diff line change
    @@ -5,12 +5,12 @@ provider "aws" {

    variable "ingressrules" {
    type = list(number)
    default = [80, 443]
    default = [80, 443, 22]
    }

    resource "aws_security_group" "web_traffic" {
    name = "Allow web traffic"
    description = "Allow standard http/https ports inbound and everything outbound"
    description = "Allow ssh and standard http/https ports inbound and everything outbound"

    dynamic "ingress" {
    iterator = port
  4. kluu1 revised this gist Oct 6, 2020. 1 changed file with 6 additions and 5 deletions.
    11 changes: 6 additions & 5 deletions main.tf
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,8 @@ variable "ingressrules" {
    default = [80, 443]
    }

    resource "aws_security_group" "prod_web" {
    name = "prod_web"
    resource "aws_security_group" "web_traffic" {
    name = "Allow web traffic"
    description = "Allow standard http/https ports inbound and everything outbound"

    dynamic "ingress" {
    @@ -36,15 +36,16 @@ resource "aws_security_group" "prod_web" {
    }

    data "aws_ami" "ubuntu" {
    most_recent = true

    ...

    }

    resource "aws_instance" "jenkins" {
    ami = data.aws_ami.ubuntu.id
    instance_type = "t2.micro"
    security_groups = [aws_security_group.prod_web.id]
    security_groups = [aws_security_group.web_traffic.name]

    tags = {
    "Name" = "Jenkins_Server"
    "Terraform" = "true"
  5. kluu1 revised this gist Oct 6, 2020. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion main.tf
    Original file line number Diff line number Diff line change
    @@ -38,4 +38,15 @@ resource "aws_security_group" "prod_web" {
    data "aws_ami" "ubuntu" {
    most_recent = true

    ...
    ...

    resource "aws_instance" "jenkins" {
    ami = data.aws_ami.ubuntu.id
    instance_type = "t2.micro"
    security_groups = [aws_security_group.prod_web.id]

    tags = {
    "Name" = "Jenkins_Server"
    "Terraform" = "true"
    }
    }
  6. kluu1 revised this gist Oct 6, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion main.tf
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ variable "ingressrules" {

    resource "aws_security_group" "prod_web" {
    name = "prod_web"
    description = "Allow standard http port inbound and everything outbound"
    description = "Allow standard http/https ports inbound and everything outbound"

    dynamic "ingress" {
    iterator = port
  7. kluu1 revised this gist Oct 6, 2020. 1 changed file with 17 additions and 8 deletions.
    25 changes: 17 additions & 8 deletions main.tf
    Original file line number Diff line number Diff line change
    @@ -3,21 +3,30 @@ provider "aws" {
    region = "us-east-1"
    }

    variable "ingressrules" {
    type = list(number)
    default = [80, 443]
    }

    resource "aws_security_group" "prod_web" {
    name = "prod_web"
    description = "Allow standard http port inbound and everything outbound"

    ingress {
    from_port = 80
    to_port = 80
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
    dynamic "ingress" {
    iterator = port
    for_each = var.ingressrules
    content {
    from_port = port.value
    to_port = port.value
    protocol = "TCP"
    cidr_blocks = ["0.0.0.0/0"]
    }
    }

    egress {
    from_port = 0
    to_port = 0
    protocol = "-1"
    from_port = 0
    to_port = 0
    protocol = "-1"
    cidr_blocks = ["0.0.0.0/0"]
    }

  8. kluu1 revised this gist Oct 6, 2020. 1 changed file with 1 addition and 7 deletions.
    8 changes: 1 addition & 7 deletions main.tf
    Original file line number Diff line number Diff line change
    @@ -5,20 +5,14 @@ provider "aws" {

    resource "aws_security_group" "prod_web" {
    name = "prod_web"
    description = "Allow standard http/https ports inbound and everything outbound"
    description = "Allow standard http port inbound and everything outbound"

    ingress {
    from_port = 80
    to_port = 80
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
    }
    ingress {
    from_port = 443
    to_port = 443
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
    }

    egress {
    from_port = 0
  9. kluu1 revised this gist Oct 6, 2020. 1 changed file with 1 addition and 21 deletions.
    22 changes: 1 addition & 21 deletions main.tf
    Original file line number Diff line number Diff line change
    @@ -35,24 +35,4 @@ resource "aws_security_group" "prod_web" {
    data "aws_ami" "ubuntu" {
    most_recent = true

    filter {
    name = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
    }

    filter {
    name = "virtualization-type"
    values = ["hvm"]
    }

    owners = ["099720109477"]
    }

    resource "aws_instance" "jenkins" {
    ami = data.aws_ami.ubuntu.id
    instance_type = "t2.micro"
    tags = {
    "Name" = "Jenkins_Server"
    "Terraform" = "true"
    }
    }
    ...
  10. kluu1 created this gist Oct 6, 2020.
    58 changes: 58 additions & 0 deletions main.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    provider "aws" {
    profile = "default"
    region = "us-east-1"
    }

    resource "aws_security_group" "prod_web" {
    name = "prod_web"
    description = "Allow standard http/https ports inbound and everything outbound"

    ingress {
    from_port = 80
    to_port = 80
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
    }
    ingress {
    from_port = 443
    to_port = 443
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
    }

    egress {
    from_port = 0
    to_port = 0
    protocol = "-1"
    cidr_blocks = ["0.0.0.0/0"]
    }

    tags = {
    "Terraform" = "true"
    }
    }

    data "aws_ami" "ubuntu" {
    most_recent = true

    filter {
    name = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
    }

    filter {
    name = "virtualization-type"
    values = ["hvm"]
    }

    owners = ["099720109477"]
    }

    resource "aws_instance" "jenkins" {
    ami = data.aws_ami.ubuntu.id
    instance_type = "t2.micro"
    tags = {
    "Name" = "Jenkins_Server"
    "Terraform" = "true"
    }
    }