Skip to content

Commit

Permalink
chore[eip]: config eip association
Browse files Browse the repository at this point in the history
fixes issue #10
  • Loading branch information
sydrawat01 authored and rishabNeu committed Sep 29, 2023
1 parent 1fb4130 commit 04413f4
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 32 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ terraform -install-autocomplete
3. Validate the terraform configuration

```bash
terraform validate
terraform validate
```

4. Plan the cloud infrastructure
Expand Down Expand Up @@ -136,3 +136,9 @@ terraform {
}
}
```

## 🔌 Elastic IP

We will manually configure the elastic IP that we will associate and disassociate the IP with our Jenkins instance. To associate this with our `doman.tld`, we will also create an entry in our hosted zone for `A record`, which will contain the elastic IP configured in the previous step.

This will enable our EC2 instance to be associated to the manually configured elastic IP everytime we setup our infrastructure using Terrform, and disassociate the elastic IP when we tear down our Infrastructure using Terraform.
24 changes: 16 additions & 8 deletions modules/ec2/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ resource "aws_security_group" "jenkins_sg" {
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
description = "SSH"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
description = "HTTPS"
from_port = 443
Expand Down Expand Up @@ -60,14 +68,15 @@ resource "aws_network_interface" "jenkins_server_nic" {
}
}

resource "aws_eip" "jenkins_server_eip" {
domain = "vpc"

# instance = aws_instance.jenkins_server.id
network_interface = aws_network_interface.jenkins_server_nic.id
depends_on = [var.igw_id]
data "aws_eip" "jenkins_server_eip" {
tags = {
Name = "jenkins-server-eip"
}
}

# TODO: tags
resource "aws_eip_association" "jenkins_server_eip_association" {
network_interface_id = aws_network_interface.jenkins_server_nic.id
allocation_id = data.aws_eip.jenkins_server_eip.id
}

resource "aws_instance" "jenkins_server" {
Expand All @@ -87,4 +96,3 @@ resource "aws_instance" "jenkins_server" {
Name = "Jenkins Server"
}
}

3 changes: 0 additions & 3 deletions modules/ec2/output.tf
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
output "jenkins_server_eip_public_ip" {
value = aws_eip.jenkins_server_eip.public_ip
}
12 changes: 0 additions & 12 deletions modules/route53/main.tf

This file was deleted.

Empty file removed modules/route53/output.tf
Empty file.
2 changes: 0 additions & 2 deletions modules/route53/variables.tf

This file was deleted.

6 changes: 0 additions & 6 deletions root/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,3 @@ module "ec2" {
igw_id = module.vpc.igw_id
vpc_id = module.vpc.vpc_id
}

module "route_53" {
source = "../modules/route53"
domain_name = var.domain_name
jenkins_server_eip_public_ip = module.ec2.jenkins_server_eip_public_ip
}

0 comments on commit 04413f4

Please sign in to comment.