add terraform scripts

This commit is contained in:
andreas.holzmann 2025-07-10 20:55:45 +02:00
parent 739685f1c2
commit edbb646281
3 changed files with 93 additions and 0 deletions

24
terraform/README.md Normal file
View file

@ -0,0 +1,24 @@
# Terraform Deployment
## Init and Plan the Terraform Deployment
```
terraform init
terraform plan \
-var="version=1.2.3" \
-var="environment=prod" \
-var="http_method=https" \
-var="public_url=mydomain.com" \
-var="default_language=de"
```
## Apply the Terrform Deployment
```
terraform apply \
-var="version=1.2.3" \
-var="environment=prod" \
-var="http_method=https" \
-var="public_url=mydomain.com" \
-var="default_language=de"
```

46
terraform/main.tf Normal file
View file

@ -0,0 +1,46 @@
resource "aws_instance" "docker_host" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.micro"
key_name = aws_key_pair.deployer.key_name
provisioner "file" {
source = "../install_docker.sh"
destination = "/home/ubuntu/install_docker.sh"
connection {
type = "ssh"
user = "ubuntu"
private_key = file(var.private_key_path)
host = self.public_ip
}
}
provisioner "file" {
source = "../setup.sh"
destination = "/home/ubuntu/setup.sh"
connection {
type = "ssh"
user = "ubuntu"
private_key = file(var.private_key_path)
host = self.public_ip
}
}
provisioner "remote-exec" {
inline = [
"chmod +x /home/ubuntu/install_docker.sh",
"sudo /home/ubuntu/install_docker.sh",
"chmod +x /home/ubuntu/setup.sh",
"sed -i '/^\s*read\b/ s/^/#/' /home/ubuntu/setup.sh",
"sudo VERSION=${var.version} ENVIRONMENT=${var.environment} HTTP_METHOD=${var.http_method} PUBLIC_URL=${var.public_url} default_language=${var.default_language} DOCKER_VOLUME_OWNER=${var.docker_volume_owner} /home/ubuntu/setup.sh"
]
connection {
type = "ssh"
user = "ubuntu"
private_key = file(var.private_key_path)
host = self.public_ip
}
}
}

23
terraform/variables.tf Normal file
View file

@ -0,0 +1,23 @@
variable "version" {
default = "latest"
}
variable "environment" {
default = "prod"
}
variable "http_method" {
default = "http"
}
variable "public_url" {
default = "dev.domain.de"
}
variable "default_language" {
default = "en"
}
variable "docker_volume_owner" {
default = "nobody"
}