Skip to content
Snippets Groups Projects
main.tf 2.58 KiB
Newer Older
  • Learn to ignore specific revisions
  • Nathan Rodet's avatar
    Nathan Rodet committed
    ############
    # 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
    
    Nathan Rodet's avatar
    Nathan Rodet committed
      name                    = "security-group-lab-daag-${var.ENVIRONMENT}"
    
    Nathan Rodet's avatar
    Nathan Rodet committed
      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
    
    Nathan Rodet's avatar
    Nathan Rodet committed
      name              = "instance-${count.index}-lab-daag-${var.ENVIRONMENT}"
    
    Nathan Rodet's avatar
    Nathan Rodet committed
      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
    
    
    Nathan Rodet's avatar
    Nathan Rodet committed
      user_data = {
    
    Nathan Rodet's avatar
    Nathan Rodet committed
        atrium_private_ip = scaleway_instance_ip.public_ip[count.index].address
        atrium_count_index = count.index
    
    Nathan Rodet's avatar
    Nathan Rodet committed
        atrium_hostname = scaleway_domain_record.subdomain_record[count.index].name
    
    Nathan Rodet's avatar
    Nathan Rodet committed
        atrium_letsencrypt_email = var.LETSENCRYPT_EMAIL
    
        user_password = var.USER_PASSWORD
    
    Nathan Rodet's avatar
    Nathan Rodet committed
        cloud-init = file("../server-scripts/cloud-init.yml")
    
    Nathan Rodet's avatar
    Nathan Rodet committed
      }
    
    Nathan Rodet's avatar
    Nathan Rodet committed
      depends_on = [
    
    Nathan Rodet's avatar
    Nathan Rodet committed
        scaleway_instance_ip.public_ip,
        scaleway_instance_security_group.www,
        scaleway_domain_record.host_subdomain_record,
        scaleway_domain_record.subdomain_record
    
    Nathan Rodet's avatar
    Nathan Rodet committed
      ]