Coder Social home page Coder Social logo

Comments (2)

Boes-man avatar Boes-man commented on August 15, 2024

This was fixed in my case by upgrading ansible community.general by running ansible-galaxy collection install community.general --upgrade --ignore-certs on my macOS

from workshops.

Boes-man avatar Boes-man commented on August 15, 2024

Updates to use new packer image in the terraform apply stage:

❯ cat main.tf
#module "vm-image" {
#  source   = "./gce/vm-image"
#  for_each = var.environments

#  prefix       = each.key
#  vm_image     = lookup(each.value, "vm_image", var.vm_image)
#  project      = lookup(each.value, "project", var.project)
#  machine_type = lookup(each.value, "machine_type", var.machine_type)
#  zone         = lookup(each.value, "zone", var.zone)
#  source_machine_image = lookup(each.value, "source_machine_image", "")
#}

module "vm-replica" {
  source   = "./gce/vm-replica"
  for_each = var.environments

  prefix               = each.key
  project              = lookup(each.value, "project", var.project)
  machine_type         = lookup(each.value, "machine_type", var.machine_type)
  zone                 = lookup(each.value, "zone", var.zone)
  num_instances        = lookup(each.value, "num_instances", var.num_instances)
  source_machine_image = var.source_machine_image #module.vm-image[each.key].gce_vm_name
}

#module "eks-cluster" {
#  source   = "./aws/eks"
#  for_each = var.eks_clusters
#
#  prefix             = each.key
#  num_instances      = lookup(each.value, "num_instances", var.num_instances)
#  azs_controlplane   = lookup(each.value, "azs_controlplane", var.azs_controlplane)
#  azs_workers        = lookup(each.value, "azs_workers", var.azs_workers)
#  eks_version        = lookup(each.value, "eks_version", var.eks_version)
#  node_instance_type = lookup(each.value, "node_instance_type", var.node_instance_type)
  # An exact number of 3 kubeconfigs per vm is the only supported choice, as we must use these names: [mgmt, cluster1, cluster2]
#  vm_merge_kubeconfig     = length(lookup(each.value, "include_vm", var.include_vm)) > 0 ? 3 : -1
#  vm_machine_type         = lookup(lookup(each.value, "include_vm", var.include_vm), "machine_type", var.machine_type)
#  vm_source_machine_image = lookup(lookup(each.value, "include_vm", var.include_vm), "source_machine_image", var.vm_image)
#  vm_project              = lookup(lookup(each.value, "include_vm", var.include_vm), "project", var.project)
#  vm_zone                 = lookup(lookup(each.value, "include_vm", var.include_vm), "zone", var.zone)
#}

#module "gke-cluster" {
#  source   = "./gce/gke"
#  for_each = var.gke_clusters

#  prefix        = each.key
#  project       = lookup(each.value, "project", var.project)
#  region        = lookup(each.value, "region", var.region)
#  zone          = lookup(each.value, "zone", var.zone)
#  preemptible   = lookup(each.value, "preemptible", var.preemptible)
#  num_instances = lookup(each.value, "num_instances", var.num_instances)
#}

```

```
❯ cat configuration.auto.tfvars
# Copy this file to configuration.auto.tfvars and uncomment values
# If you use any other name, please make sure you DONT commit/push the file with credentials

#######################################################################
# GCP
 project       = "solo-test-236622"
 region        = "australia-southeast1"
 zone          = "australia-southeast1-c"

#######################################################################
# AWS
 default_region = "eu-west-1"

# And don't forget to provide credentials:
# gcloud auth application-default login
# aws configure

#######################################################################
# GCP Virtual Machines
 machine_type  = "n1-standard-8"
 source_machine_image      = "workshop-generic-v20211021"
 num_instances = 0

environments = {
  workshopau1 = {
##    machine_type  = "n1-standard-8"
    region        = "australia-southeast1"
    zone          = "australia-southeast1-c"
    num_instances =  10 
#    vm_image      = "workshop-generic-v20211021"
  }
##  workshopas1 = {
#    machine_type  = "n1-standard-8"
##    region        = "asia-south1"
##   zone          = "asia-south1-a"
##    num_instances =  35
#    vm_image      = "ubuntu-2004-focal-v20210510"
##  }
##  workshopeu1 = {
#    machine_type  = "n1-standard-8"
##    region        = "europe-west1"
##    zone          = "europe-west1-c"
##    num_instances =  10
#    vm_image      = "ubuntu-2004-focal-v20210510"
##  }
##  workshopus1 = {
#    machine_type  = "n1-standard-8"
##    region        = "us-central1"
##    zone          = "us-central1-c"
##    num_instances =  10
#    vm_image      = "ubuntu-2004-focal-v20210510"
##  }
  personal1 = {
    num_instances = 1 
##    machine_type  = "n1-standard-8"
  }
}

#######################################################################
# GKE
# preemptible = true # to build clusters that live mostly for 24h, cheaper

#gke_clusters = {
#  workshop-b = {
#    num_instances = 1 
#    zone          = "australia-southeast1-c"
#  }
#}

#######################################################################
# EKS
#azs_controlplane   = ["ap-southeast-2a", "ap-southeast-2b", "ap-southeast-2c"]
#azs_workers        = ["ap-southeast-2a", "ap-southeast-2b", "ap-southeast-2c"]
#eks_version        = "1.20"
#node_instance_type = "t3.small"
#include_vm         = {}
#
#eks_clusters = {
#  eks-batch1 = {
#    num_instances      = 3
#    node_instance_type = "t3.micro"
#    include_vm = {
#      machine_type         = "n1-standard-1"
#      source_machine_image = "jesus-test-personal1-source-image"
#      region               = "ap-southeast-2"
#      zone                 = "ap-southeast-2c"
#    }
#  }
#}
```

```
❯ cat inputs.tf outputs.tf
variable "project" {
  type = string
}

variable "machine_type" {
  type = string
}

variable "zone" {
  type = string
}

variable "region" {
  type = string
}

variable "azs_controlplane" {
  type = list(string)
}

variable "azs_workers" {
  type = list(string)
}

variable "source_machine_image" {
  type = string
}

variable "num_instances" {
  type = string
}

variable "environments" {
  type    = map(any)
  default = {}
}

variable "eks_clusters" {
  type    = map(any)
  default = {}
}

variable "gke_clusters" {
  type    = map(any)
  default = {}
}

variable "eks_version" {
  type = string
}

variable "node_instance_type" {
  type = string
}

variable "preemptible" {
  type = bool
}

variable "include_vm" {
  type    = map(any)
  default = {}
}

variable "default_region" {
  type = string
}
output "workshop_credentials" {
  value = {
    user : "solo"
    password : "Workshop1#"
  }
}

output "gce_replicas_public_ip" {
  value = {
    for k, v in module.vm-replica : k => v.gce_public_ip
  }
}
```

```
❯ cat gce/vm-replica/main.tf outputs.tf inputs.tf
resource "google_compute_instance" "vm" {
  project      = var.project
  count        = var.num_instances
  name         = "${terraform.workspace}-${var.prefix}-${count.index + 1}"
  machine_type = var.machine_type
  zone         = var.zone

  tags = [var.prefix]

  labels = local.common_tags

  boot_disk {
    initialize_params {
      image = var.source_machine_image
    }
  }

  network_interface {
    network = "default"

    access_config {
      // Ephemeral IP
    }
  }

  metadata = {
    enable-oslogin = "FALSE"
    ssh-keys       = "solo:${file(local.ssh_file)}"
  }

  # Wait until ip is available
#  provisioner "local-exec" {
#    command = "echo 'waiting for ip ${self.network_interface.0.access_config.0.nat_ip}' && until nc -z ${self.network_interface.0.access_config.0.nat_ip} 22; do sleep 1; done && sleep 10"
#  }

  # Re-Provision machine with ansible (update git repos mostly)
#  provisioner "local-exec" {
#    command = "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u solo -i '${self.network_interface.0.access_config.0.nat_ip},' ansible-playbook.yml -v -e provision=no -e reboot_vm_machine=no"
#  }

}

resource "google_compute_firewall" "default" {
  project = var.project
  name    = "${terraform.workspace}-${var.prefix}-firewall"
  network = "default"

  allow {
    protocol = "icmp"
  }

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

  source_ranges = ["0.0.0.0/0"]
  target_tags   = [var.prefix]
}
output "workshop_credentials" {
  value = {
    user : "solo"
    password : "Workshop1#"
  }
}

output "gce_replicas_public_ip" {
  value = {
    for k, v in module.vm-replica : k => v.gce_public_ip
  }
}

variable "project" {
  type = string
}

variable "machine_type" {
  type = string
}

variable "zone" {
  type = string
}

variable "region" {
  type = string
}

variable "azs_controlplane" {
  type = list(string)
}

variable "azs_workers" {
  type = list(string)
}

variable "source_machine_image" {
  type = string
}

variable "num_instances" {
  type = string
}

variable "environments" {
  type    = map(any)
  default = {}
}

variable "eks_clusters" {
  type    = map(any)
  default = {}
}

variable "gke_clusters" {
  type    = map(any)
  default = {}
}

variable "eks_version" {
  type = string
}

variable "node_instance_type" {
  type = string
}

variable "preemptible" {
  type = bool
}

variable "include_vm" {
  type    = map(any)
  default = {}
}

variable "default_region" {
  type = string
}
```

from workshops.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.