How Do You Write a Terraform Module in AWS?

Problem scenario
You want to write a Terraform module in AWS. What do you do?

Solution
You will use the keyword “module” in a .tf file, and you will use either “terraform init” or “terraform get” to install the module. The directions below were adapted from https://www.howtoforge.com/how-to-create-a-terraform-module/.

Prerequisite
You need to have Terraform installed;

How Do You Troubleshoot the yum Repository “Errors during downloading metadata for repository”?

Problem scenario
You try to use a yum command on RHEL 8.2. But you get this error:

Docker Repository 0.0 B/s | 0 B 00:00 Errors during downloading metadata for repository ‘foobar’: – Curl error (6): Couldn’t resolve host name for https://yum.dockerproject.org/repo/main/centos/7/repodata/repomd.xml [Could not resolve host: yum.dockerproject.org] Error: Failed to download metadata for repo ‘foobar’: Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

What should you do?

How Do You Troubleshoot the InsufficientFreeAddressSpaceInVpc Error?

Problem scenario
You run an AWS CLI command. But you get this message:

An error occurred (InsufficientFreeAddressSpaceInVpc) when calling the CreateDefaultSubnet operation: The VPC ‘vpc-123abcd’ does not have enough free address space to allocate an additional /20 subnet.

How do you troubleshoot this AWS CLI error?

Solution
Go to the VPC section of AWS. Find the VPC in the error and click on it.

How Do You Troubleshoot the kubectl ‘version “extensions/v1beta1″‘ Error Message?

Problem scenario
You run a kubectl command, but you get this problem: ‘error: unable to recognize “foobar.yaml”: no matches for kind “Deployment” in version “extensions/v1beta1″‘

What should you do?

Solution
Change your yaml file so the apiVersion setting/value works. To learn more about the acceptable values, see this posting.

How Do You Replace a Pattern with a String in Bash?

Problem scenario
You have a .txt file. You know Linux can support substitutions of strings with some type of expression. You want to use Bash to replace every occurrence in the file with a string. What should you do?

Solution
Let’s assume the file you have is called coolfile.txt. Run these two commands to replace “foo” with “bar” every time “foo” is found in the file named coolfile.txt:

oldfile=$(cat coolfile.txt)
echo “${oldfile//’foo’/bar}” > …

How Do You Escape or Break from a Method in Python?

Problem scenario
You want to quit a function, or return out of it, when a certain condition is met. How do you do this?

Solution
This program illustrates how it is done. You will want to run the program twice, once by leaving the “5” as it is, and a second time by changing the “5” to “6”.

def cool(x):
if x == 5:
return “There was equivalence”
else:
y = x
print(“This statement is printing as an illustration”)
return “The comparison was NOT equivalent”

var1 = cool(5)
print(var1) …

How Do You Troubleshoot a C Program That Prints a Warning Message like “expects argument of type ‘int’, but argument 2 has type ‘char *’ [-Wformat=]”?

Problem scenario
You compile a C program (with gcc foobar.cc) but you get an error message like this:

basicprog.c:5:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘char *’ [-Wformat=]
printf (“y is a %d\n”,y);

What do you do to not get this error?

Solution
While the code compiles, the executable may not run.  A compilation error can be benign. 

How Do You Use Terraform and Kubernetes in a Simple Way (as a Proof of Concept)?

Problem scenario
You want to use Terraform and Kubernetes (in EKS). How do you do this in a simple way to test it out?

Solution
Prerequisite

This assumes you have deployed EKS. If you need assistance, see this posting.
This assumes you have installed Terraform. If you need assistance, see this posting.

Procedures

  1. This first step is optional.

How Do You Fix the AWS CLI Error “Following required service principals [eks.amazonaws.com] were not found in the trust relationships”?

Problem scenario
You run an AWS CLI command, but you get this error:

An error occurred (InvalidParameterException) when calling the CreateNodegroup operation: Following required service principals [eks.amazonaws.com] were not found in the trust relationships of clusterRole arn:aws:iam::12345678910:role/foobar

How do you fix this?

Solution
Draft a command like this (but replace “12345677810:role/foobar” with the equivalent string in the error, and replace foobar.amazonaws.com with the service principal in the error):

aws iam list-roles –query ‘Roles[?Arn==arn:aws:iam::12345678910:role/foobar]’ | grep foobar.amazonaws.com

If the above command returns nothing,