NOKEY Error while using Terraform on AWS

Amazon Linux 2 is no longer supported by the Jenkins project. A May 2023 blog post announced that derivatives of Red Hat Enterprise Linux 7 would no longer be supported by the Jenkins project after 16 Nov 2023.

Amazon has stated that “Amazon Linux 2 offers will be supported until June 30, 2025 with security and maintenance updates” . Installing Amazon Linux 2 now means that the Jenkins project does not support or test that operating system and that in less than 12 months the operating system vendor will stop supporting it. Please use a newer operating system like Amazon Linux 2023 or Red Hat Enterprise Linux 9 or AlmaLinux 9 or Rocky Linux 9.

That indicates that yum cannot find the public key for the RPM package that you are trying to install. The Jenkins installation guide for Red Hat / Alma / Rocky says that you need to run the following commands:

sudo wget -O /etc/yum.repos.d/jenkins.repo \
    https://pkg.jenkins.io/redhat/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io-2023.key
sudo yum upgrade
# Add required dependencies for the jenkins package
sudo yum install fontconfig java-17-openjdk
sudo yum install jenkins