Fixes Spot Prices Configuration and EC2 DNS Namespace

This commit is contained in:
2024-10-26 03:55:43 -03:00
parent 7e65d82e35
commit 0d8c55ffd0
5 changed files with 16 additions and 3 deletions

View File

@@ -49,6 +49,11 @@ variable "aws_ami" {
default = "ami-06a17a87e19be286a" default = "ami-06a17a87e19be286a"
} }
variable "aws_spot_price" {
type = number
default = 0.0028
}
variable "cloudflare_api_token" { variable "cloudflare_api_token" {
type = string type = string
sensitive = true sensitive = true

View File

@@ -25,7 +25,7 @@ resource "cloudflare_record" "default" {
zone_id = var.cloudflare_zone_id zone_id = var.cloudflare_zone_id
name = var.environment_name == "prod" ? "@" : "staging" name = var.environment_name == "prod" ? "@" : "staging"
value = var.public_ip content = var.public_ip
type = "A" type = "A"
ttl = 3600 ttl = 3600
proxied = false proxied = false
@@ -36,7 +36,7 @@ resource "cloudflare_record" "api" {
zone_id = var.cloudflare_zone_id zone_id = var.cloudflare_zone_id
name = var.environment_name == "prod" ? "api" : "api.staging" name = var.environment_name == "prod" ? "api" : "api.staging"
value = var.public_ip content = var.public_ip
type = "A" type = "A"
ttl = 3600 ttl = 3600
proxied = false proxied = false

View File

@@ -33,6 +33,11 @@ variable "aws_ami" {
default = "ami-06a17a87e19be286a" default = "ami-06a17a87e19be286a"
} }
variable "aws_spot_price" {
type = number
default = 0.0028
}
variable "ssh_public_key_main" { variable "ssh_public_key_main" {
type = string type = string
} }

View File

@@ -97,6 +97,7 @@ resource "aws_instance" "main" {
} }
inline = [ inline = [
"sudo sed -i '1s/^/nameserver 1.1.1.1\\n/' /etc/resolv.conf",
"sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024", "sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024",
"sudo /sbin/mkswap /var/swap.1", "sudo /sbin/mkswap /var/swap.1",
"sudo chmod 600 /var/swap.1", "sudo chmod 600 /var/swap.1",
@@ -118,7 +119,7 @@ resource "aws_instance" "worker" {
instance_market_options { instance_market_options {
market_type = "spot" market_type = "spot"
spot_options { spot_options {
max_price = 0.0020 max_price = var.aws_spot_price
instance_interruption_behavior = "stop" instance_interruption_behavior = "stop"
spot_instance_type = "persistent" spot_instance_type = "persistent"
} }
@@ -146,6 +147,7 @@ resource "aws_instance" "worker" {
} }
inline = [ inline = [
"sudo sed -i '1s/^/nameserver 1.1.1.1\\n/' /etc/resolv.conf",
"sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024", "sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024",
"sudo /sbin/mkswap /var/swap.1", "sudo /sbin/mkswap /var/swap.1",
"sudo chmod 600 /var/swap.1", "sudo chmod 600 /var/swap.1",

View File

@@ -66,6 +66,7 @@ module "instances" {
ssh_public_key_ci_cd = var.ssh_public_key_ci_cd ssh_public_key_ci_cd = var.ssh_public_key_ci_cd
aws_instance_type = var.aws_instance_type aws_instance_type = var.aws_instance_type
aws_ami = var.aws_ami aws_ami = var.aws_ami
aws_spot_price = var.aws_spot_price
} }
module "dns" { module "dns" {