# local_file.ansible_cfg:
resource "local_file" "ansible_cfg" {
    content              = <<-EOT
        [defaults]
        host_key_checking = False
        inventory = gcp_compute.yml
        interpreter_python = auto_silent
        remote_user = raphael_hochlaf_gmail_com
        
        [inventory]
        enable_plugins = gcp_compute, auto, host_list, yaml, ini, toml, script
    EOT
    content_base64sha256 = "jrenWIt9x2qGTdaqfpoAXEPXp7W4PHNnMzZ1/BZJYns="
    content_base64sha512 = "dgn+L1rht/fRumwaypMMlHKC3lsrqYdxzk27xWmuSISFvL3TsdfTm/dYY2V71oKW6IVUsQImRPjrxB5te0wfSQ=="
    content_md5          = "3557d21f3c6acecb25e483bba22f03b8"
    content_sha1         = "04395fb39a5be06e2479845d3dd450cb3d47f779"
    content_sha256       = "8eb7a7588b7dc76a864dd6aa7e9a005c43d7a7b5b83c7367333675fc1649627b"
    content_sha512       = "7609fe2f5ae1b7f7d1ba6c1aca930c947282de5b2ba98771ce4dbbc569ae488485bcbdd3b1d7d39bf75863657bd68296e88554b1022644f8ebc41e6d7b4c1f49"
    directory_permission = "0777"
    file_permission      = "0777"
    filename             = "./ansible.cfg"
    id                   = "04395fb39a5be06e2479845d3dd450cb3d47f779"
}


# module.compute.google_compute_instance.backend:
resource "google_compute_instance" "backend" {
    can_ip_forward             = false
    cpu_platform               = "Intel Broadwell"
    creation_timestamp         = "2025-12-04T02:54:13.023-08:00"
    current_status             = "RUNNING"
    deletion_protection        = false
    description                = null
    effective_labels           = {
        "goog-terraform-provisioned" = "true"
    }
    enable_display             = false
    hostname                   = null
    id                         = "projects/empanada-478713/zones/europe-west1-b/instances/backend"
    instance_id                = "7268827977958086331"
    key_revocation_action_type = null
    label_fingerprint          = "vezUS-42LLM="
    machine_type               = "e2-medium"
    metadata                   = {
        "enable-oslogin" = "TRUE"
    }
    metadata_fingerprint       = "OS1a23tpOhg="
    min_cpu_platform           = null
    name                       = "backend"
    project                    = "empanada-478713"
    self_link                  = "https://www.googleapis.com/compute/v1/projects/empanada-478713/zones/europe-west1-b/instances/backend"
    tags                       = [
        "backend",
        "ssh",
    ]
    tags_fingerprint           = "N2bbCLFli_k="
    terraform_labels           = {
        "goog-terraform-provisioned" = "true"
    }
    zone                       = "europe-west1-b"

    boot_disk {
        auto_delete                = true
        device_name                = "persistent-disk-0"
        disk_encryption_key_raw    = (sensitive value)
        disk_encryption_key_sha256 = null
        interface                  = null
        kms_key_self_link          = null
        mode                       = "READ_WRITE"
        source                     = "https://www.googleapis.com/compute/v1/projects/empanada-478713/zones/europe-west1-b/disks/backend"

        initialize_params {
            enable_confidential_compute = false
            image                       = "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-11-bullseye-v20251111"
            labels                      = {}
            provisioned_iops            = 0
            provisioned_throughput      = 0
            resource_policies           = []
            size                        = 10
            storage_pool                = null
            type                        = "pd-standard"
        }
    }

    network_interface {
        internal_ipv6_prefix_length = 0
        ipv6_access_type            = null
        ipv6_address                = null
        name                        = "nic0"
        network                     = "https://www.googleapis.com/compute/v1/projects/empanada-478713/global/networks/test-vpc"
        network_ip                  = "10.0.2.2"
        nic_type                    = null
        queue_count                 = 0
        stack_type                  = "IPV4_ONLY"
        subnetwork                  = "https://www.googleapis.com/compute/v1/projects/empanada-478713/regions/europe-west1/subnetworks/test-backend"
        subnetwork_project          = "empanada-478713"
    }

    scheduling {
        automatic_restart           = true
        instance_termination_action = null
        min_node_cpus               = 0
        on_host_maintenance         = "MIGRATE"
        preemptible                 = false
        provisioning_model          = "STANDARD"
    }

    shielded_instance_config {
        enable_integrity_monitoring = true
        enable_secure_boot          = false
        enable_vtpm                 = true
    }
}

# module.compute.google_compute_instance.database:
resource "google_compute_instance" "database" {
    can_ip_forward             = false
    cpu_platform               = "Intel Broadwell"
    creation_timestamp         = "2025-12-04T02:54:12.862-08:00"
    current_status             = "RUNNING"
    deletion_protection        = false
    description                = null
    effective_labels           = {
        "goog-terraform-provisioned" = "true"
    }
    enable_display             = false
    hostname                   = null
    id                         = "projects/empanada-478713/zones/europe-west1-b/instances/database"
    instance_id                = "2945101980376028859"
    key_revocation_action_type = null
    label_fingerprint          = "vezUS-42LLM="
    machine_type               = "e2-medium"
    metadata                   = {
        "enable-oslogin" = "TRUE"
    }
    metadata_fingerprint       = "OS1a23tpOhg="
    min_cpu_platform           = null
    name                       = "database"
    project                    = "empanada-478713"
    self_link                  = "https://www.googleapis.com/compute/v1/projects/empanada-478713/zones/europe-west1-b/instances/database"
    tags                       = [
        "database",
        "ssh",
    ]
    tags_fingerprint           = "22sTRfPQYj4="
    terraform_labels           = {
        "goog-terraform-provisioned" = "true"
    }
    zone                       = "europe-west1-b"

    boot_disk {
        auto_delete                = true
        device_name                = "persistent-disk-0"
        disk_encryption_key_raw    = (sensitive value)
        disk_encryption_key_sha256 = null
        interface                  = null
        kms_key_self_link          = null
        mode                       = "READ_WRITE"
        source                     = "https://www.googleapis.com/compute/v1/projects/empanada-478713/zones/europe-west1-b/disks/database"

        initialize_params {
            enable_confidential_compute = false
            image                       = "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-11-bullseye-v20251111"
            labels                      = {}
            provisioned_iops            = 0
            provisioned_throughput      = 0
            resource_policies           = []
            size                        = 20
            storage_pool                = null
            type                        = "pd-standard"
        }
    }

    network_interface {
        internal_ipv6_prefix_length = 0
        ipv6_access_type            = null
        ipv6_address                = null
        name                        = "nic0"
        network                     = "https://www.googleapis.com/compute/v1/projects/empanada-478713/global/networks/test-vpc"
        network_ip                  = "10.0.3.2"
        nic_type                    = null
        queue_count                 = 0
        stack_type                  = "IPV4_ONLY"
        subnetwork                  = "https://www.googleapis.com/compute/v1/projects/empanada-478713/regions/europe-west1/subnetworks/test-database"
        subnetwork_project          = "empanada-478713"
    }

    scheduling {
        automatic_restart           = true
        instance_termination_action = null
        min_node_cpus               = 0
        on_host_maintenance         = "MIGRATE"
        preemptible                 = false
        provisioning_model          = "STANDARD"
    }

    shielded_instance_config {
        enable_integrity_monitoring = true
        enable_secure_boot          = false
        enable_vtpm                 = true
    }
}

# module.compute.google_compute_instance.frontend:
resource "google_compute_instance" "frontend" {
    can_ip_forward             = false
    cpu_platform               = "Intel Broadwell"
    creation_timestamp         = "2025-12-04T02:54:12.928-08:00"
    current_status             = "RUNNING"
    deletion_protection        = false
    description                = null
    effective_labels           = {
        "goog-terraform-provisioned" = "true"
    }
    enable_display             = false
    hostname                   = null
    id                         = "projects/empanada-478713/zones/europe-west1-b/instances/frontend"
    instance_id                = "6460546696565544635"
    key_revocation_action_type = null
    label_fingerprint          = "vezUS-42LLM="
    machine_type               = "e2-medium"
    metadata                   = {
        "enable-oslogin" = "TRUE"
    }
    metadata_fingerprint       = "OS1a23tpOhg="
    min_cpu_platform           = null
    name                       = "frontend"
    project                    = "empanada-478713"
    self_link                  = "https://www.googleapis.com/compute/v1/projects/empanada-478713/zones/europe-west1-b/instances/frontend"
    tags                       = [
        "frontend",
        "ssh",
    ]
    tags_fingerprint           = "sermMtqzdso="
    terraform_labels           = {
        "goog-terraform-provisioned" = "true"
    }
    zone                       = "europe-west1-b"

    boot_disk {
        auto_delete                = true
        device_name                = "persistent-disk-0"
        disk_encryption_key_raw    = (sensitive value)
        disk_encryption_key_sha256 = null
        interface                  = null
        kms_key_self_link          = null
        mode                       = "READ_WRITE"
        source                     = "https://www.googleapis.com/compute/v1/projects/empanada-478713/zones/europe-west1-b/disks/frontend"

        initialize_params {
            enable_confidential_compute = false
            image                       = "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-11-bullseye-v20251111"
            labels                      = {}
            provisioned_iops            = 0
            provisioned_throughput      = 0
            resource_policies           = []
            size                        = 10
            storage_pool                = null
            type                        = "pd-standard"
        }
    }

    network_interface {
        internal_ipv6_prefix_length = 0
        ipv6_access_type            = null
        ipv6_address                = null
        name                        = "nic0"
        network                     = "https://www.googleapis.com/compute/v1/projects/empanada-478713/global/networks/test-vpc"
        network_ip                  = "10.0.1.2"
        nic_type                    = null
        queue_count                 = 0
        stack_type                  = "IPV4_ONLY"
        subnetwork                  = "https://www.googleapis.com/compute/v1/projects/empanada-478713/regions/europe-west1/subnetworks/test-frontend"
        subnetwork_project          = "empanada-478713"

        access_config {
            nat_ip                 = "35.195.55.14"
            network_tier           = "PREMIUM"
            public_ptr_domain_name = null
        }
    }

    scheduling {
        automatic_restart           = true
        instance_termination_action = null
        min_node_cpus               = 0
        on_host_maintenance         = "MIGRATE"
        preemptible                 = false
        provisioning_model          = "STANDARD"
    }

    shielded_instance_config {
        enable_integrity_monitoring = true
        enable_secure_boot          = false
        enable_vtpm                 = true
    }
}


# module.iam.google_os_login_ssh_public_key.ssh_key:
resource "google_os_login_ssh_public_key" "ssh_key" {
    expiration_time_usec = null
    fingerprint          = "238c4233ae44a42898ee67df3e9032da4d8880d2f8bff47e230e5465da05d045"
    id                   = "users/raphael.hochlaf@gmail.com/sshPublicKeys/238c4233ae44a42898ee67df3e9032da4d8880d2f8bff47e230e5465da05d045"
    key                  = <<-EOT
        ssh-rsa   raphael_hochlaf_gmail_com
    EOT
    project              = "empanada-478713"
    user                 = "raphael.hochlaf@gmail.com"
}

# module.iam.google_project_iam_member.terraform_roles:
resource "google_project_iam_member" "terraform_roles" {
    etag    = "BwZFHiSfH3c="
    id      = "empanada-478713/roles/owner/serviceAccount:terraform-admin@empanada-478713.iam.gserviceaccount.com"
    member  = "serviceAccount:terraform-admin@empanada-478713.iam.gserviceaccount.com"
    project = "empanada-478713"
    role    = "roles/owner"
}

# module.iam.google_service_account.terraform_sa:
resource "google_service_account" "terraform_sa" {
    account_id   = "terraform-admin"
    description  = null
    disabled     = false
    display_name = "Terraform Admin"
    email        = "terraform-admin@empanada-478713.iam.gserviceaccount.com"
    id           = "projects/empanada-478713/serviceAccounts/terraform-admin@empanada-478713.iam.gserviceaccount.com"
    member       = "serviceAccount:terraform-admin@empanada-478713.iam.gserviceaccount.com"
    name         = "projects/empanada-478713/serviceAccounts/terraform-admin@empanada-478713.iam.gserviceaccount.com"
    project      = "empanada-478713"
    unique_id    = "115350139325023114837"
}

# module.iam.google_service_account_key.terraform_sa_key:
resource "google_service_account_key" "terraform_sa_key" {
    id                 = "projects/empanada-478713/serviceAccounts/terraform-admin@empanada-478713.iam.gserviceaccount.com/keys/50102f288f97ba639600524552aa753f202a92a7"
    key_algorithm      = "KEY_ALG_RSA_2048"
    name               = "projects/empanada-478713/serviceAccounts/terraform-admin@empanada-478713.iam.gserviceaccount.com/keys/50102f288f97ba639600524552aa753f202a92a7"
    private_key        = (sensitive value)
    private_key_type   = "TYPE_GOOGLE_CREDENTIALS_FILE"
    public_key         = " "
    public_key_type    = "TYPE_X509_PEM_FILE"
    service_account_id = "projects/empanada-478713/serviceAccounts/terraform-admin@empanada-478713.iam.gserviceaccount.com"
    valid_after        = "2025-12-04T10:53:41Z"
    valid_before       = "9999-12-31T23:59:59Z"
}


# module.network.google_compute_firewall.backend_database:
resource "google_compute_firewall" "backend_database" {
    creation_timestamp = "2025-12-04T02:53:50.655-08:00"
    description        = null
    destination_ranges = []
    direction          = "INGRESS"
    disabled           = false
    id                 = "projects/empanada-478713/global/firewalls/test-backend-to-database"
    name               = "test-backend-to-database"
    network            = "https://www.googleapis.com/compute/v1/projects/empanada-478713/global/networks/test-vpc"
    priority           = 1000
    project            = "empanada-478713"
    self_link          = "https://www.googleapis.com/compute/v1/projects/empanada-478713/global/firewalls/test-backend-to-database"
    source_tags        = [
        "backend",
    ]
    target_tags        = [
        "database",
    ]

    allow {
        ports    = [
            "3306",
        ]
        protocol = "tcp"
    }
}

# module.network.google_compute_firewall.frontend_backend:
resource "google_compute_firewall" "frontend_backend" {
    creation_timestamp = "2025-12-04T02:53:50.936-08:00"
    description        = null
    destination_ranges = []
    direction          = "INGRESS"
    disabled           = false
    id                 = "projects/empanada-478713/global/firewalls/test-frontend-to-backend"
    name               = "test-frontend-to-backend"
    network            = "https://www.googleapis.com/compute/v1/projects/empanada-478713/global/networks/test-vpc"
    priority           = 1000
    project            = "empanada-478713"
    self_link          = "https://www.googleapis.com/compute/v1/projects/empanada-478713/global/firewalls/test-frontend-to-backend"
    source_tags        = [
        "frontend",
    ]
    target_tags        = [
        "backend",
    ]

    allow {
        ports    = [
            "8000",
        ]
        protocol = "tcp"
    }
}

# module.network.google_compute_firewall.frontend_http:
resource "google_compute_firewall" "frontend_http" {
    creation_timestamp = "2025-12-04T02:53:50.682-08:00"
    description        = null
    destination_ranges = []
    direction          = "INGRESS"
    disabled           = false
    id                 = "projects/empanada-478713/global/firewalls/test-frontend-http"
    name               = "test-frontend-http"
    network            = "https://www.googleapis.com/compute/v1/projects/empanada-478713/global/networks/test-vpc"
    priority           = 1000
    project            = "empanada-478713"
    self_link          = "https://www.googleapis.com/compute/v1/projects/empanada-478713/global/firewalls/test-frontend-http"
    source_ranges      = [
        "0.0.0.0/0",
    ]
    target_tags        = [
        "frontend",
    ]

    allow {
        ports    = [
            "80",
            "443",
        ]
        protocol = "tcp"
    }
}

# module.network.google_compute_firewall.ssh:
resource "google_compute_firewall" "ssh" {
    creation_timestamp = "2025-12-04T02:53:50.638-08:00"
    description        = null
    destination_ranges = []
    direction          = "INGRESS"
    disabled           = false
    id                 = "projects/empanada-478713/global/firewalls/test-ssh"
    name               = "test-ssh"
    network            = "https://www.googleapis.com/compute/v1/projects/empanada-478713/global/networks/test-vpc"
    priority           = 1000
    project            = "empanada-478713"
    self_link          = "https://www.googleapis.com/compute/v1/projects/empanada-478713/global/firewalls/test-ssh"
    source_ranges      = [
        "0.0.0.0/0",
    ]
    target_tags        = [
        "ssh",
    ]

    allow {
        ports    = [
            "22",
        ]
        protocol = "tcp"
    }
}

# module.network.google_compute_network.vpc:
resource "google_compute_network" "vpc" {
    auto_create_subnetworks                   = false
    delete_default_routes_on_create           = false
    description                               = null
    enable_ula_internal_ipv6                  = false
    gateway_ipv4                              = null
    id                                        = "projects/empanada-478713/global/networks/test-vpc"
    internal_ipv6_range                       = null
    mtu                                       = 0
    name                                      = "test-vpc"
    network_firewall_policy_enforcement_order = "AFTER_CLASSIC_FIREWALL"
    numeric_id                                = "498726034919446214"
    project                                   = "empanada-478713"
    routing_mode                              = "REGIONAL"
    self_link                                 = "https://www.googleapis.com/compute/v1/projects/empanada-478713/global/networks/test-vpc"
}

# module.network.google_compute_subnetwork.backend:
resource "google_compute_subnetwork" "backend" {
    creation_timestamp         = "2025-12-04T02:53:50.902-08:00"
    description                = null
    external_ipv6_prefix       = null
    gateway_address            = "10.0.2.1"
    id                         = "projects/empanada-478713/regions/europe-west1/subnetworks/test-backend"
    internal_ipv6_prefix       = null
    ip_cidr_range              = "10.0.2.0/24"
    ipv6_access_type           = null
    ipv6_cidr_range            = null
    name                       = "test-backend"
    network                    = "https://www.googleapis.com/compute/v1/projects/empanada-478713/global/networks/test-vpc"
    private_ip_google_access   = false
    private_ipv6_google_access = "DISABLE_GOOGLE_ACCESS"
    project                    = "empanada-478713"
    purpose                    = "PRIVATE"
    region                     = "europe-west1"
    reserved_internal_range    = null
    role                       = null
    self_link                  = "https://www.googleapis.com/compute/v1/projects/empanada-478713/regions/europe-west1/subnetworks/test-backend"
    stack_type                 = "IPV4_ONLY"
}

# module.network.google_compute_subnetwork.database:
resource "google_compute_subnetwork" "database" {
    creation_timestamp         = "2025-12-04T02:53:50.867-08:00"
    description                = null
    external_ipv6_prefix       = null
    gateway_address            = "10.0.3.1"
    id                         = "projects/empanada-478713/regions/europe-west1/subnetworks/test-database"
    internal_ipv6_prefix       = null
    ip_cidr_range              = "10.0.3.0/24"
    ipv6_access_type           = null
    ipv6_cidr_range            = null
    name                       = "test-database"
    network                    = "https://www.googleapis.com/compute/v1/projects/empanada-478713/global/networks/test-vpc"
    private_ip_google_access   = false
    private_ipv6_google_access = "DISABLE_GOOGLE_ACCESS"
    project                    = "empanada-478713"
    purpose                    = "PRIVATE"
    region                     = "europe-west1"
    reserved_internal_range    = null
    role                       = null
    self_link                  = "https://www.googleapis.com/compute/v1/projects/empanada-478713/regions/europe-west1/subnetworks/test-database"
    stack_type                 = "IPV4_ONLY"
}

# module.network.google_compute_subnetwork.frontend:
resource "google_compute_subnetwork" "frontend" {
    creation_timestamp         = "2025-12-04T02:53:51.584-08:00"
    description                = null
    external_ipv6_prefix       = null
    gateway_address            = "10.0.1.1"
    id                         = "projects/empanada-478713/regions/europe-west1/subnetworks/test-frontend"
    internal_ipv6_prefix       = null
    ip_cidr_range              = "10.0.1.0/24"
    ipv6_access_type           = null
    ipv6_cidr_range            = null
    name                       = "test-frontend"
    network                    = "https://www.googleapis.com/compute/v1/projects/empanada-478713/global/networks/test-vpc"
    private_ip_google_access   = false
    private_ipv6_google_access = "DISABLE_GOOGLE_ACCESS"
    project                    = "empanada-478713"
    purpose                    = "PRIVATE"
    region                     = "europe-west1"
    reserved_internal_range    = null
    role                       = null
    self_link                  = "https://www.googleapis.com/compute/v1/projects/empanada-478713/regions/europe-west1/subnetworks/test-frontend"
    stack_type                 = "IPV4_ONLY"
}


Outputs:

iam_info = "terraform-admin@empanada-478713.iam.gserviceaccount.com"
instance_info = {
    frontend_public_ip = "35.195.55.14"
    instance_names     = [
        "frontend",
        "backend",
        "database",
    ]
    internal_ips       = {
        backend  = "10.0.2.2"
        database = "10.0.3.2"
        frontend = "10.0.1.2"
    }
}
network_info = {
    subnet_ids = {
        backend  = "projects/empanada-478713/regions/europe-west1/subnetworks/test-backend"
        database = "projects/empanada-478713/regions/europe-west1/subnetworks/test-database"
        frontend = "projects/empanada-478713/regions/europe-west1/subnetworks/test-frontend"
    }
    vpc_id     = "projects/empanada-478713/global/networks/test-vpc"
}