From fac4a8d5f5ff3a979b371a17c1fd961bda50f238 Mon Sep 17 00:00:00 2001 From: Nick Babcock Date: Sat, 28 Oct 2023 14:22:52 -0500 Subject: [PATCH] Add aarch64 testing terraform config When testing the linux aarch64 code on a real platform (AWS graviton), it is a bit of a hassle walking through all the steps to instantiate, configure, and then run the test suite. So I created a terraform configuration that does it all for me (a la infrastructure as code). Right now, the config is a too tailored to me (assumes the default network policy allows inbound ssh and the ssh key is named "me"). But, I'm a terraform noob, so I welcome implementation suggestions. --- .gitignore | 8 ++++++++ assets/.terraform.lock.hcl | 25 +++++++++++++++++++++++++ assets/aarch64.sh | 24 ++++++++++++++++++++++++ assets/aarch64.tf | 22 ++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 assets/.terraform.lock.hcl create mode 100755 assets/aarch64.sh create mode 100644 assets/aarch64.tf diff --git a/.gitignore b/.gitignore index fdc1c35..f5ba9f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,11 @@ **/target **/*.rs.bk Cargo.lock + +### Terraform ### +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* diff --git a/assets/.terraform.lock.hcl b/assets/.terraform.lock.hcl new file mode 100644 index 0000000..78715c7 --- /dev/null +++ b/assets/.terraform.lock.hcl @@ -0,0 +1,25 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.23.1" + constraints = "~> 5.0" + hashes = [ + "h1:s23thJVPJHUdS7ESZHoeMkxNcTeaqWvg2usv8ylFVL4=", + "zh:024a188ad3c979a9ec0d7d898aaa90a3867a8839edc8d3543ea6155e6e010064", + "zh:05b73a04c58534a7527718ef55040577d5c573ea704e16a813e7d1b18a7f4c26", + "zh:13932cdee2fa90f40ebaa783f033752864eb6899129e055511359f8d1ada3710", + "zh:3500f5febc7878b4426ef89a16c0096eefd4dd0c5b0d9ba00f9ed54387df5d09", + "zh:394a48dea7dfb0ae40e506ccdeb5387829dbb8ab00fb64f41c347a1de092aa00", + "zh:51a57f258b3bce2c167b39b6ecf486f72f523da05d4c92adc6b697abe1c5ff1f", + "zh:7290488a96d8d10119b431eb08a37407c0812283042a21b69bcc2454eabc08ad", + "zh:7545389dbbba624c0ffa72fa376b359b27f484aba02139d37ee5323b589e0939", + "zh:92266ac6070809e0c874511ae93097c8b1eddce4c0213e487c5439e89b6ad64d", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:9c3841bd650d6ba471c7159bcdfa35200e5e49c2ea11032c481a33cf7875879d", + "zh:bd103c46a16e7f9357e08d6427c316ccc56d203452130eed8e36ede3afa3322c", + "zh:cab0a16e320c6ca285a3a51f40c8f46dbaa0712856594819b415b4d8b3e63910", + "zh:e8adedcda4d6ff47dcae9c9bb884da26ca448fb6f7436be95ad6a341e4d8094a", + "zh:fc23701a3723f50878f440dcdf8768ea96d60a0d7c351aa6dfb912ad832c8384", + ] +} diff --git a/assets/aarch64.sh b/assets/aarch64.sh new file mode 100755 index 0000000..7d73223 --- /dev/null +++ b/assets/aarch64.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -euxo pipefail + +terraform plan +terraform apply -auto-approve +public_ip=$(terraform output --raw public_ip) +sleep 30 +ssh ec2-user@$public_ip " + sudo yum update -y && + sudo yum groupinstall -y 'Development Tools' && + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --profile minimal -y && + source "\$HOME/.cargo/env" && + git clone https://github.com/nickbabcock/highway-rs.git && + cd highway-rs && + cargo test" + +if [[ $? = 0 ]]; then + read -p "Test successful, preserve instance? (y/N): " -n 1 -r -t 300 + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + terraform destroy -auto-approve + fi +else + echo "Test failed" +fi diff --git a/assets/aarch64.tf b/assets/aarch64.tf new file mode 100644 index 0000000..70a671c --- /dev/null +++ b/assets/aarch64.tf @@ -0,0 +1,22 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.0" + } + } +} + +provider "aws" { + region = "us-east-1" +} + +resource "aws_instance" "highway_aarch64" { + ami = "ami-055859c8e0f361065" + instance_type = "t4g.small" + key_name = "me" +} + +output "public_ip" { + value = aws_instance.highway_aarch64.public_ip +}