############ # Terraform SSH key ############ resource "scaleway_account_ssh_key" "ssh_key" { name = "FORGE alpha_project_manager" public_key = var.SCW_SSH_PUB_KEY } ############ # Public IP ############ resource "scaleway_instance_ip" "public_ip" { count = var.INSTANCES_COUNT project_id = var.SCW_PROJECT_ID } ################ # DOMAIN RECORD ################ resource "scaleway_domain_record" "subdomain_record" { count = var.INSTANCES_COUNT dns_zone = "daag.alpha.grandlyon.com" name = "lab-${count.index}-daag-${var.ENVIRONMENT}" type = "A" data = scaleway_instance_ip.public_ip[count.index].address ttl = 3600 } resource "scaleway_domain_record" "host_subdomain_record" { count = var.INSTANCES_COUNT dns_zone = "daag.alpha.grandlyon.com" name = "*.lab-${count.index}-daag-${var.ENVIRONMENT}" type = "A" data = scaleway_instance_ip.public_ip[count.index].address ttl = 3600 } ################################## ## Security group - Allowed ports ################################## resource "scaleway_instance_security_group" "www" { project_id = var.SCW_PROJECT_ID name = "security-group-daag-lab-${var.ENVIRONMENT}" inbound_default_policy = "drop" outbound_default_policy = "accept" inbound_rule { action = "accept" port = "22" } inbound_rule { action = "accept" port = "80" } inbound_rule { action = "accept" port = "8080" } inbound_rule { action = "accept" port = "443" } } ############################## ## VM Instance - User Machine ############################## resource "scaleway_instance_server" "user_instance_server" { count = var.INSTANCES_COUNT project_id = var.SCW_PROJECT_ID name = "instance-${count.index}-daag-lab-${var.ENVIRONMENT}" type = "DEV1-L" image = "ubuntu_jammy" ip_id = scaleway_instance_ip.public_ip[count.index].id security_group_id = scaleway_instance_security_group.www.id user_data = { user_password = var.USER_PASSWORD cloud-init = file("cloud-init.yml") } depends_on = [ scaleway_account_ssh_key.ssh_key, scaleway_instance_security_group.www ] }