Cannot authenticate to Digital Ocean Kubernetes through Terraform

9/24/2019

I am working on a system that is spread across both Digital Ocean and AWS. Their Node.js instances are on a Kubernetes cluster on Digital Ocean and their databases and S3 spaces are hosted on AWS. I was able to connect to the Kubernetes cluster using kubectl. Then, I was able to do a 'terraform init' with no issues. But, when I tried to do a 'terraform plan', I got this error.

Error: Error retrieving Kubernetes cluster: GET https://api.digitalocean.com/v2/kubernetes/clusters/1234: 401 Unable to authenticate you.

I am new to both Kubernetes and Terraform. Does Terraform expect the Kubernetes config information to be in a different place then where kubectl expects it?

-- mikeb
amazon-web-services
digital-ocean
kubernetes
terraform

1 Answer

9/25/2019

You need a token so that Digital Ocean’s servers know that you have permission to access your account. Follow the steps in the instruction creating-access-token and copy the token to your clipboard.Remember to store it as an environment variable: export TF_VAR_do_token=your-token.

Set environment variables:

export TF_VAR_do_token=your_digital_ocean_token

export TF_VAR_do_cluster_name=your_cluster_name

Otherwise problem is with the API token. Create a new token and then the operation will succeeded.

Useful blog article about setting up Kuberenetes cluster wit Digital Ocena and Terraform" kubernetes-digitalocean-terraform.

-- MaggieO
Source: StackOverflow