From 80bcd07c67ecf945c15e9cce64dc5091caff925d Mon Sep 17 00:00:00 2001 From: lolli001 Date: Wed, 24 Jul 2024 14:07:48 -0400 Subject: [PATCH] Updated --- buildspec.yml | 29 ++++++++++++++++++++++++---- main.tf | 2 +- modules/image-pipeline/build.pkr.hcl | 2 +- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/buildspec.yml b/buildspec.yml index b7c5348..c4870b1 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -9,13 +9,34 @@ phases: - pyenv global $PYTHON_311_VERSION - echo "Installing Ansible ..." - pip3 install ansible + pre_build: + commands: + - echo "Setting up environment ..." + - which pip3 || curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py + - which pip3 || python3 get-pip.py --user + - stat $(python -m site --user-base)/bin/ansible-playbook || python3 -m pip install --user ansible pywinrm + - export PATH=$PATH:$(python -m site --user-base)/bin + - stat /bin/packer || curl -s -qL -o packer.zip https://releases.hashicorp.com/packer/1.10.3/packer_1.10.3_linux_amd64.zip + - stat /bin/packer || unzip -o packer.zip && mv packer /bin && rm packer.zip + - stat ${CODEBUILD_SRC_DIR_SourceAnsibleOutput}/init.sh && bash ${CODEBUILD_SRC_DIR_SourceAnsibleOutput}/init.sh ${CODEBUILD_SRC_DIR_SourceAnsibleOutput} || echo "No init.sh script found" build: commands: - - echo "Building with Packer ..." - - packer init build.pkr.hcl - - packer build -var project_name=rhel-arm-image-pipeline-demo -var ansible_dir=${CODEBUILD_SRC_DIR}/ansible build.pkr.hcl + - echo "Configuring AWS credentials" + - curl -qL -o aws_credentials.json http://169.254.170.2/${AWS_CONTAINER_CREDENTIALS_RELATIVE_URI} > aws_credentials.json + - aws configure set region $AWS_REGION + - aws configure set aws_access_key_id `jq -r '.AccessKeyId' aws_credentials.json` + - export AWS_ACCESS_KEY_ID=`jq -r '.AccessKeyId' aws_credentials.json` + - aws configure set aws_secret_access_key `jq -r '.SecretAccessKey' aws_credentials.json` + - export AWS_SECRET_ACCESS_KEY=`jq -r '.SecretAccessKey' aws_credentials.json` + - aws configure set aws_session_token `jq -r '.Token' aws_credentials.json` + - export AWS_SESSION_TOKEN=`jq -r '.Token' aws_credentials.json` + - echo "Building HashiCorp Packer template, build.pkr.hcl" + - cd ${CODEBUILD_SRC_DIR} + - /bin/packer init build.pkr.hcl + - ln -s ${CODEBUILD_SRC_DIR}/roles + - /bin/packer build -var project_name=rhel-arm-image-pipeline-demo -var ansible_dir=${CODEBUILD_SRC_DIR} build.pkr.hcl post_build: commands: - echo "Saving AMI ID ..." - - packer build -machine-readable build.pkr.hcl | tee >(grep 'artifact,0,id' | cut -d, -f6 | cut -d: -f2 > ami_id.txt) + - /bin/packer build -machine-readable build.pkr.hcl | tee >(grep 'artifact,0,id' | cut -d, -f6 | cut -d: -f2 > ami_id.txt) - test -s ami_id.txt || exit 1 \ No newline at end of file diff --git a/main.tf b/main.tf index 442c96c..2010187 100644 --- a/main.tf +++ b/main.tf @@ -143,7 +143,7 @@ module "rhel-arm" { state = local.state_config vpc_config = local.vpc_config source_ami = "ami-03f5c6b8195c66b04" - instance_type = "t4g.micro" + instance_type = "t3.micro" } resource "random_password" "winrm" { diff --git a/modules/image-pipeline/build.pkr.hcl b/modules/image-pipeline/build.pkr.hcl index b1677f5..d6efea1 100644 --- a/modules/image-pipeline/build.pkr.hcl +++ b/modules/image-pipeline/build.pkr.hcl @@ -1,6 +1,6 @@ source "amazon-ebs" "rhel" { ami_name = "rhel-arm-{{timestamp}}" - instance_type = "t4g.micro" # Ensure the instance type is ARM64 compatible + instance_type = "t3.micro" # Ensure the instance type is ARM64 compatible region = "us-gov-west-1" source_ami = "ami-03f5c6b8195c66b04" # Updated AMI ID for RHEL 9 ARM ssh_username = "ec2-user"