'Cannot authenticate to Digital Ocean Kubernetes through Terraform

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?



Solution 1:[1]

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 Kubernetes cluster wit Digital Ocean and Terraform.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Veve