NOKEY Error while using Terraform on AWS

When creating Amazon 2 Linux server with Terraform code the following error messages are received:

null_resource.name (remote-exec): warning: /var/cache/yum/x86_64/2/jenkins/packages/jenkins-2.462-1.1.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID ef5975ca: NOKEY
null_resource.name (remote-exec): Public key for jenkins-2.462-1.1.noarch.rpm is not installed
null_resource.name (remote-exec): jenkins-2.462-1.1. |  89 MB   00:03
null_resource.name (remote-exec): Public key for jenkins-2.462-1.1.noarch.rpm is not installed

How can I resolve this issue?

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