feat(Packer): Introduce AMI packer images 65/34065/1
authorpmikus <pmikus@cisco.com>
Wed, 6 Oct 2021 12:53:37 +0000 (12:53 +0000)
committerPeter Mikus <pmikus@cisco.com>
Thu, 14 Oct 2021 10:31:56 +0000 (10:31 +0000)
Signed-off-by: pmikus <pmikus@cisco.com>
Change-Id: I471069fd4cc10a0627434a60b4627d1bd0e192b8
(cherry picked from commit 6f9f70d7bb1bbed37ff1495c20d11a03b82b9951)

fdio.infra.packer/2n_aws_c5n/ubuntu_focal.pkr.hcl [new file with mode: 0644]
fdio.infra.packer/3n_aws_c5n/ubuntu_focal.pkr.hcl [new file with mode: 0644]
fdio.infra.terraform/2n_aws_c5n/deploy/main.tf
fdio.infra.terraform/2n_aws_c5n/deploy/variables.tf
fdio.infra.terraform/2n_aws_c5n/main.tf
fdio.infra.terraform/2n_aws_c5n/variables.tf
fdio.infra.terraform/3n_aws_c5n/deploy/main.tf
fdio.infra.terraform/3n_aws_c5n/deploy/variables.tf
fdio.infra.terraform/3n_aws_c5n/main.tf
fdio.infra.terraform/3n_aws_c5n/variables.tf

diff --git a/fdio.infra.packer/2n_aws_c5n/ubuntu_focal.pkr.hcl b/fdio.infra.packer/2n_aws_c5n/ubuntu_focal.pkr.hcl
new file mode 100644 (file)
index 0000000..0fc3f36
--- /dev/null
@@ -0,0 +1,114 @@
+packer {
+  required_plugins {
+    amazon = {
+      version = ">= 1.0.1"
+      source  = "github.com/hashicorp/amazon"
+    }
+  }
+}
+
+variable "first_run_commands" {
+  description = "Commands to run after deployment via remote-exec"
+  type        = list(string)
+  default     = [
+    ""
+  ]
+}
+
+variable "ansible_file_path" {
+  description = "Path to Ansible playbook"
+  type        = string
+  default     = "../../fdio.infra.ansible/site.yaml"
+}
+
+variable "ansible_python_executable" {
+  description = "Path to Python interpreter"
+  type        = string
+  default     = "/usr/bin/python3"
+}
+
+variable "ansible_topology_path" {
+  description = "Path to Ansible playbook which creates a topology file"
+  type        = string
+  default     = "../../fdio.infra.ansible/cloud_topology.yaml"
+}
+
+variable "ansible_provision_pwd" {
+  description = "Password used for ansible provisioning (ansible_ssh_pass)"
+  type        = string
+  default     = "Csit1234"
+}
+
+source "amazon-ebs" "csit_c5n_ubuntu_focal_sut" {
+  ami_name         = "csit_c5n_ubuntu_focal_sut"
+  ami_description  = "CSIT SUT image based on Ubuntu Focal"
+  ena_support      = true
+  instance_type    = "c5n.9xlarge"
+  launch_block_device_mappings {
+    device_name = "/dev/sda1"
+    volume_size = 40
+    volume_type = "gp2"
+  }
+  force_deregister = true
+  region           = "eu-central-1"
+  skip_create_ami  = false
+  source_ami       = "ami-0a875db8a031a9efb"
+  ssh_username     = "ubuntu"
+}
+
+source "amazon-ebs" "csit_c5n_ubuntu_focal_tg" {
+  ami_name         = "csit_c5n_ubuntu_focal_tg"
+  ami_description  = "CSIT TG image based on Ubuntu Focal"
+  ena_support      = true
+  instance_type    = "c5n.9xlarge"
+  launch_block_device_mappings {
+    device_name = "/dev/sda1"
+    volume_size = 40
+    volume_type = "gp2"
+  }
+  force_deregister = true
+  region           = "eu-central-1"
+  skip_create_ami  = false
+  source_ami       = "ami-0a875db8a031a9efb"
+  ssh_username     = "ubuntu"
+}
+
+build {
+  name = "csit_c5n_ubuntu_focal_sut-packer"
+  sources = [
+    "source.amazon-ebs.csit_c5n_ubuntu_focal_sut"
+  ]
+  provisioner "shell" {
+    inline = var.first_run_commands
+  }
+  provisioner "ansible" {
+    playbook_file = var.ansible_file_path
+    user          = "ubuntu"
+    groups        = ["sut_aws"]
+    extra_arguments = [
+      "--extra-vars", "ansible_ssh_pass=${var.ansible_provision_pwd}",
+      "--extra-vars", "ansible_python_interpreter=${var.ansible_python_executable}",
+      "--extra-vars", "aws=true"
+    ]
+  }
+}
+
+build {
+  name = "csit_c5n_ubuntu_focal_tg-packer"
+  sources = [
+    "source.amazon-ebs.csit_c5n_ubuntu_focal_tg"
+  ]
+  provisioner "shell" {
+    inline = var.first_run_commands
+  }
+  provisioner "ansible" {
+    playbook_file = var.ansible_file_path
+    user          = "ubuntu"
+    groups        = ["tg_aws"]
+    extra_arguments = [
+      "--extra-vars", "ansible_ssh_pass=${var.ansible_provision_pwd}",
+      "--extra-vars", "ansible_python_interpreter=${var.ansible_python_executable}",
+      "--extra-vars", "aws=true"
+    ]
+  }
+}
diff --git a/fdio.infra.packer/3n_aws_c5n/ubuntu_focal.pkr.hcl b/fdio.infra.packer/3n_aws_c5n/ubuntu_focal.pkr.hcl
new file mode 100644 (file)
index 0000000..0fc3f36
--- /dev/null
@@ -0,0 +1,114 @@
+packer {
+  required_plugins {
+    amazon = {
+      version = ">= 1.0.1"
+      source  = "github.com/hashicorp/amazon"
+    }
+  }
+}
+
+variable "first_run_commands" {
+  description = "Commands to run after deployment via remote-exec"
+  type        = list(string)
+  default     = [
+    ""
+  ]
+}
+
+variable "ansible_file_path" {
+  description = "Path to Ansible playbook"
+  type        = string
+  default     = "../../fdio.infra.ansible/site.yaml"
+}
+
+variable "ansible_python_executable" {
+  description = "Path to Python interpreter"
+  type        = string
+  default     = "/usr/bin/python3"
+}
+
+variable "ansible_topology_path" {
+  description = "Path to Ansible playbook which creates a topology file"
+  type        = string
+  default     = "../../fdio.infra.ansible/cloud_topology.yaml"
+}
+
+variable "ansible_provision_pwd" {
+  description = "Password used for ansible provisioning (ansible_ssh_pass)"
+  type        = string
+  default     = "Csit1234"
+}
+
+source "amazon-ebs" "csit_c5n_ubuntu_focal_sut" {
+  ami_name         = "csit_c5n_ubuntu_focal_sut"
+  ami_description  = "CSIT SUT image based on Ubuntu Focal"
+  ena_support      = true
+  instance_type    = "c5n.9xlarge"
+  launch_block_device_mappings {
+    device_name = "/dev/sda1"
+    volume_size = 40
+    volume_type = "gp2"
+  }
+  force_deregister = true
+  region           = "eu-central-1"
+  skip_create_ami  = false
+  source_ami       = "ami-0a875db8a031a9efb"
+  ssh_username     = "ubuntu"
+}
+
+source "amazon-ebs" "csit_c5n_ubuntu_focal_tg" {
+  ami_name         = "csit_c5n_ubuntu_focal_tg"
+  ami_description  = "CSIT TG image based on Ubuntu Focal"
+  ena_support      = true
+  instance_type    = "c5n.9xlarge"
+  launch_block_device_mappings {
+    device_name = "/dev/sda1"
+    volume_size = 40
+    volume_type = "gp2"
+  }
+  force_deregister = true
+  region           = "eu-central-1"
+  skip_create_ami  = false
+  source_ami       = "ami-0a875db8a031a9efb"
+  ssh_username     = "ubuntu"
+}
+
+build {
+  name = "csit_c5n_ubuntu_focal_sut-packer"
+  sources = [
+    "source.amazon-ebs.csit_c5n_ubuntu_focal_sut"
+  ]
+  provisioner "shell" {
+    inline = var.first_run_commands
+  }
+  provisioner "ansible" {
+    playbook_file = var.ansible_file_path
+    user          = "ubuntu"
+    groups        = ["sut_aws"]
+    extra_arguments = [
+      "--extra-vars", "ansible_ssh_pass=${var.ansible_provision_pwd}",
+      "--extra-vars", "ansible_python_interpreter=${var.ansible_python_executable}",
+      "--extra-vars", "aws=true"
+    ]
+  }
+}
+
+build {
+  name = "csit_c5n_ubuntu_focal_tg-packer"
+  sources = [
+    "source.amazon-ebs.csit_c5n_ubuntu_focal_tg"
+  ]
+  provisioner "shell" {
+    inline = var.first_run_commands
+  }
+  provisioner "ansible" {
+    playbook_file = var.ansible_file_path
+    user          = "ubuntu"
+    groups        = ["tg_aws"]
+    extra_arguments = [
+      "--extra-vars", "ansible_ssh_pass=${var.ansible_provision_pwd}",
+      "--extra-vars", "ansible_python_interpreter=${var.ansible_python_executable}",
+      "--extra-vars", "aws=true"
+    ]
+  }
+}
index 1ea7e50..db1463e 100644 (file)
@@ -220,7 +220,7 @@ data "aws_network_interface" "tg_if2" {
 # Instances
 resource "aws_instance" "tg" {
   depends_on                           = [aws_vpc.CSITVPC, aws_placement_group.CSITPG]
-  ami                                  = var.ami_image
+  ami                                  = var.ami_image_tg
   availability_zone                    = var.avail_zone
   instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior
   instance_type                        = var.instance_type
@@ -245,7 +245,7 @@ resource "aws_instance" "tg" {
 
 resource "aws_instance" "dut1" {
   depends_on                           = [aws_vpc.CSITVPC, aws_placement_group.CSITPG, aws_instance.tg]
-  ami                                  = var.ami_image
+  ami                                  = var.ami_image_sut
   availability_zone                    = var.avail_zone
   instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior
   instance_type                        = var.instance_type
@@ -307,29 +307,29 @@ resource "null_resource" "deploy_tg" {
     private_key = tls_private_key.CSITTLS.private_key_pem
   }
 
-  provisioner "remote-exec" {
-    inline = var.first_run_commands
-  }
-
-  provisioner "ansible" {
-    plays {
-      playbook {
-        file_path      = var.ansible_file_path
-        force_handlers = true
-      }
-      hosts = ["tg_aws"]
-      extra_vars = {
-        ansible_ssh_pass           = var.ansible_provision_pwd
-        ansible_python_interpreter = var.ansible_python_executable
-        aws                        = true
-      }
-    }
-  }
-
-  provisioner "remote-exec" {
-    on_failure = continue
-    inline     = ["sudo reboot"]
-  }
+#  provisioner "remote-exec" {
+#    inline = var.first_run_commands
+#  }
+#
+#  provisioner "ansible" {
+#    plays {
+#      playbook {
+#        file_path      = var.ansible_file_path
+#        force_handlers = true
+#      }
+#      hosts = ["tg_aws"]
+#      extra_vars = {
+#        ansible_ssh_pass           = var.ansible_provision_pwd
+#        ansible_python_interpreter = var.ansible_python_executable
+#        aws                        = true
+#      }
+#    }
+#  }
+#
+#  provisioner "remote-exec" {
+#    on_failure = continue
+#    inline     = ["sudo reboot"]
+#  }
 }
 
 resource "null_resource" "deploy_dut1" {
@@ -348,29 +348,29 @@ resource "null_resource" "deploy_dut1" {
     private_key = tls_private_key.CSITTLS.private_key_pem
   }
 
-  provisioner "remote-exec" {
-    inline = var.first_run_commands
-  }
-
-  provisioner "ansible" {
-    plays {
-      playbook {
-        file_path      = var.ansible_file_path
-        force_handlers = true
-      }
-      hosts = ["sut_aws"]
-      extra_vars = {
-        ansible_ssh_pass           = var.ansible_provision_pwd
-        ansible_python_interpreter = var.ansible_python_executable
-        aws                        = true
-      }
-    }
-  }
-
-  provisioner "remote-exec" {
-    on_failure = continue
-    inline     = ["sudo reboot"]
-  }
+#  provisioner "remote-exec" {
+#    inline = var.first_run_commands
+#  }
+#
+#  provisioner "ansible" {
+#    plays {
+#      playbook {
+#        file_path      = var.ansible_file_path
+#        force_handlers = true
+#      }
+#      hosts = ["sut_aws"]
+#      extra_vars = {
+#        ansible_ssh_pass           = var.ansible_provision_pwd
+#        ansible_python_interpreter = var.ansible_python_executable
+#        aws                        = true
+#      }
+#    }
+#  }
+#
+#  provisioner "remote-exec" {
+#    on_failure = continue
+#    inline     = ["sudo reboot"]
+#  }
 }
 
 resource "null_resource" "deploy_topology" {
index 6e9ffd1..57c5b69 100644 (file)
@@ -7,8 +7,13 @@ variable "vault-name" {
   default = "dynamic-aws-creds-vault-admin"
 }
 
-variable "ami_image" {
-  description = "AWS AMI image name"
+variable "ami_image_tg" {
+  description = "AWS AMI image name for TG"
+  type        = string
+}
+
+variable "ami_image_sut" {
+  description = "AWS AMI image name for SUT"
   type        = string
 }
 
index 44ec177..45b597d 100644 (file)
@@ -13,7 +13,8 @@ module "deploy" {
   region        = var.region
   avail_zone    = var.avail_zone
   instance_type = var.instance_type
-  ami_image     = var.ami_image
+  ami_image_tg  = var.ami_image_tg
+  ami_image_sut = var.ami_image_sut
 
   # AWS Network
   vpc_cidr_mgmt = "192.168.0.0/24"
index c3d81bf..62a7de4 100644 (file)
@@ -14,12 +14,26 @@ variable "avail_zone" {
   default     = "eu-central-1a"
 }
 
-variable "ami_image" {
+variable "ami_image_tg" {
   # eu-central-1/focal-20.04-amd64-hvm-ssd-20210119.1
   # kernel 5.4.0-1035-aws (~5.4.0-65)
   description = "AWS AMI image ID"
   type        = string
-  default     = "ami-0a875db8a031a9efb"
+  default     = "ami-0d6bc0344dc036b9d"
+}
+
+variable "ami_image_sut" {
+  # eu-central-1/focal-20.04-amd64-hvm-ssd-20210119.1
+  # kernel 5.4.0-1035-aws (~5.4.0-65)
+  description = "AWS AMI image ID"
+  type        = string
+  default     = "ami-012c9c631964367be"
+}
+
+variable "instance_initiated_shutdown_behavior" {
+  description = "Shutdown behavior for the instance"
+  type        = string
+  default     = "terminate"
 }
 
 variable "instance_type" {
index 0969ca4..073768d 100644 (file)
@@ -263,7 +263,7 @@ data "aws_network_interface" "tg_if2" {
 
 # Instances
 resource "aws_instance" "tg" {
-  ami                                  = var.ami_image
+  ami                                  = var.ami_image_tg
   availability_zone                    = var.avail_zone
   instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior
   instance_type                        = var.instance_type
@@ -292,7 +292,7 @@ resource "aws_instance" "tg" {
 }
 
 resource "aws_instance" "dut1" {
-  ami                                  = var.ami_image
+  ami                                  = var.ami_image_sut
   availability_zone                    = var.avail_zone
   instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior
   instance_type                        = var.instance_type
@@ -322,17 +322,18 @@ resource "aws_instance" "dut1" {
 }
 
 resource "aws_instance" "dut2" {
-  ami                         = var.ami_image
-  availability_zone           = var.avail_zone
-  instance_type               = var.instance_type
-  key_name                    = aws_key_pair.CSITKP.key_name
-  associate_public_ip_address = true
-  subnet_id                   = aws_subnet.mgmt.id
-  private_ip                  = var.dut2_mgmt_ip
-  vpc_security_group_ids      = [aws_security_group.CSITSG.id]
-  placement_group             = aws_placement_group.CSITPG.id
-  source_dest_check           = false
-  # host_id                   = "3"
+  ami                                  = var.ami_image_sut
+  availability_zone                    = var.avail_zone
+  instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior
+  instance_type                        = var.instance_type
+  key_name                             = aws_key_pair.CSITKP.key_name
+  associate_public_ip_address          = true
+  subnet_id                            = aws_subnet.mgmt.id
+  private_ip                           = var.dut2_mgmt_ip
+  vpc_security_group_ids               = [aws_security_group.CSITSG.id]
+  placement_group                      = aws_placement_group.CSITPG.id
+  source_dest_check                    = false
+  # host_id                            = "3"
 
   depends_on = [
     aws_vpc.CSITVPC,
@@ -435,29 +436,29 @@ resource "null_resource" "deploy_dut1" {
     private_key = tls_private_key.CSITTLS.private_key_pem
   }
 
-  provisioner "remote-exec" {
-    inline = var.first_run_commands
-  }
-
-  provisioner "ansible" {
-    plays {
-      playbook {
-        file_path      = var.ansible_file_path
-        force_handlers = true
-      }
-      hosts = ["sut_aws"]
-      extra_vars = {
-        ansible_ssh_pass           = var.ansible_provision_pwd
-        ansible_python_interpreter = var.ansible_python_executable
-        aws                        = true
-      }
-    }
-  }
-
-  provisioner "remote-exec" {
-    on_failure = continue
-    inline     = ["sudo reboot"]
-  }
+#  provisioner "remote-exec" {
+#    inline = var.first_run_commands
+#  }
+#
+#  provisioner "ansible" {
+#    plays {
+#      playbook {
+#        file_path      = var.ansible_file_path
+#        force_handlers = true
+#      }
+#      hosts = ["sut_aws"]
+#      extra_vars = {
+#        ansible_ssh_pass           = var.ansible_provision_pwd
+#        ansible_python_interpreter = var.ansible_python_executable
+#        aws                        = true
+#      }
+#    }
+#  }
+#
+#  provisioner "remote-exec" {
+#    on_failure = continue
+#    inline     = ["sudo reboot"]
+#  }
 }
 
 resource "null_resource" "deploy_dut2" {
@@ -479,29 +480,29 @@ resource "null_resource" "deploy_dut2" {
     private_key = tls_private_key.CSITTLS.private_key_pem
   }
 
-  provisioner "remote-exec" {
-    inline = var.first_run_commands
-  }
-
-  provisioner "ansible" {
-    plays {
-      playbook {
-        file_path      = var.ansible_file_path
-        force_handlers = true
-      }
-      hosts = ["sut_aws"]
-      extra_vars = {
-        ansible_ssh_pass           = var.ansible_provision_pwd
-        ansible_python_interpreter = var.ansible_python_executable
-        aws                        = true
-      }
-    }
-  }
-
-  provisioner "remote-exec" {
-    on_failure = continue
-    inline     = ["sudo reboot"]
-  }
+#  provisioner "remote-exec" {
+#    inline = var.first_run_commands
+#  }
+#
+#  provisioner "ansible" {
+#    plays {
+#      playbook {
+#        file_path      = var.ansible_file_path
+#        force_handlers = true
+#      }
+#      hosts = ["sut_aws"]
+#      extra_vars = {
+#        ansible_ssh_pass           = var.ansible_provision_pwd
+#        ansible_python_interpreter = var.ansible_python_executable
+#        aws                        = true
+#      }
+#    }
+#  }
+#
+#  provisioner "remote-exec" {
+#    on_failure = continue
+#    inline     = ["sudo reboot"]
+#  }
 }
 
 resource "null_resource" "deploy_topology" {
index aa78462..ffd1a35 100644 (file)
@@ -7,8 +7,13 @@ variable "vault-name" {
   default = "dynamic-aws-creds-vault-admin"
 }
 
-variable "ami_image" {
-  description = "AWS AMI image name"
+variable "ami_image_tg" {
+  description = "AWS AMI image name for TG"
+  type        = string
+}
+
+variable "ami_image_sut" {
+  description = "AWS AMI image name for SUT"
   type        = string
 }
 
index abb60ce..5ad8601 100644 (file)
@@ -13,7 +13,8 @@ module "deploy" {
   region        = var.region
   avail_zone    = var.avail_zone
   instance_type = var.instance_type
-  ami_image     = var.ami_image
+  ami_image_tg  = var.ami_image_tg
+  ami_image_sut = var.ami_image_sut
 
   # AWS Network
   vpc_cidr_mgmt = "192.168.0.0/24"
index 29a611a..129d5dc 100644 (file)
@@ -4,18 +4,30 @@ variable "region" {
   default     = "eu-central-1"
 }
 
+variable "vault-name" {
+  default = "dynamic-aws-creds-vault-admin"
+}
+
 variable "avail_zone" {
   description = "AWS availability zone"
   type        = string
   default     = "eu-central-1a"
 }
 
-variable "ami_image" {
+variable "ami_image_tg" {
+  # eu-central-1/focal-20.04-amd64-hvm-ssd-20210119.1
+  # kernel 5.4.0-1035-aws (~5.4.0-65)
+  description = "AWS AMI image ID"
+  type        = string
+  default     = "ami-0d6bc0344dc036b9d"
+}
+
+variable "ami_image_sut" {
   # eu-central-1/focal-20.04-amd64-hvm-ssd-20210119.1
   # kernel 5.4.0-1035-aws (~5.4.0-65)
   description = "AWS AMI image ID"
   type        = string
-  default     = "ami-0a875db8a031a9efb"
+  default     = "ami-012c9c631964367be"
 }
 
 variable "instance_initiated_shutdown_behavior" {