https://developer.hashicorp.com/terraform/tutorials/kubernetes/eks contain the walk through on how to provision an AWS Elastic Kubernetes Service (EKS) Cluster using Terraform. However, when I tried, I ran into problems, so here is what I did.
On a Linux EC2 instances, I cloned the learn-terraform-provision-eks-cluster repo.
git clone https://github.com/hashicorp/learn-terraform-provision-eks-cluster
And then move into the learn-terraform-provision-eks-cluster directory.
cd learn-terraform-provision-eks-cluster
The next step is to use the export command to set the TF_CLOUD_ORGANIZATION variable. But first, you'll need a Terraform Cloud Organization. So I had to first create a Terraform Cloud Organization at https://app.terraform.io/. Let's say you've a Terraform Cloud Organization named myOrganization. Then, I was able to use the export command to create the TF_CLOUD_ORGANIZATION variable.
export TF_CLOUD_ORGANIZATION=myOrganization
And then use the terraform login command to log into Terraform Cloud. I got a prompt with a URL to get a token, I went to the URL, got a token, and pasted the token in the prompt, and was successfully logged into Terraform Cloud.
terraform login
At this point, I went added and used the terraform init command, and there were no problems.
terraform init
However, when I would issue the terraform plan or terraform apply command, something like this would be returned.
Error: no EC2 IMDS role found, operation error ec2imds: GetMetadata, canceled, context deadline exceeded
I had to also add my AWS Access Key and Secret Key in Terraform Cloud.
- After logging into Terraform Cloud, in the left panel, select Settings.
- Select Variable sets.
- Select Create variable set.
- Name the variable set AWS Credentials
- Select Add Variable
- Key = AWS_ACCESS_KEY_ID
- Value = your AWS access key ID
- Checkmark Sensitive
- Select Add variable
- Select Add Variable
- Key = AWS_SECRET_ACCESS_KEY
- Value = your AWS secret access key
- Checkmark Sensitive
- Select Add variable
- Select Create variable set
And unfortunately, I had to update main.tf to include my access key and secret key.
provider "aws" {
access_key = "abcdefg123456789"
secret_key = "abcdefg123456789abcdefg123456789"
region = "us-east-1"
}
Then terraform apply ran successfully and the Elastic Kubernetes Service (EKS) Cluster was created.
And in Terraform Cloud > Workspaces > your_workspace, the Run List should display the state of the Run.
Did you find this article helpful?
If so, consider buying me a coffee over at