-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kubernetes: Expand example to show best practices for interacting with k8s provider. #564
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this improvement! I have a few questions the answers to which might also help other newbies with DOKS and Terraform.
examples/kubernetes/README.md
Outdated
Optionally, this example can generate a kubeconfig file in the current working | ||
directory. However, the token in this config will expire. The token can be | ||
refreshed by running `terraform apply` again and setting `write_kubeconfig` to | ||
`true`. | ||
|
||
``` | ||
terraform apply -var="write_kubeconfig=true" | ||
export KUBECONFIG=$(terraform output -raw kubeconfig_path | ||
kubectl get pods -n test | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use a combination of terraform refresh
and terraform output kubeconfig > .../kubeconfig
. That seems less intimidating (i.e. potentially destructive) that terraform apply
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this creates a local_file resource, apply is needed to replace the file if new credentials are needed.
Co-authored-by: Dennis Schridde <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome @andrewsomething
…h k8s provider. (#564) * kubernetes: Expand example to show best practices for interacting with k8s provider. * Add README to the kubernetes example. * Update Kubernetes provider interoperability acceptance test for 2.0.x * kubernetes: Update documentation. * Update examples/kubernetes/README.md Co-authored-by: Dennis Schridde <[email protected]> * Update examples/kubernetes/README.md Co-authored-by: Samuel Guyah <[email protected]> * k8s: Replace the interpolation example with one using the data source. * Document using the exec plugin w/ doctl. Co-authored-by: Dennis Schridde <[email protected]> Co-authored-by: Samuel Guyah <[email protected]>
As seen in #562, using interpolation to pass credentials to the Kubernetes provider from other resources can cause some issues due to the order in which Terraform evaluates the provider blocks vs. actual resources. In fact, the Kubernetes provider docs have added a warning to discourage using interpolation to pass credentials:
https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs#stacking-with-managed-kubernetes-cluster-resources
This PR expands the Kubernetes example in this repo to be more complete and better adhere to best practices for interacting with the Kubernetes provider. It also adds a notes to the Kubernetes cluster resource docs addressing the issue and linking to that example. Finally, it updates usage of the Kubernetes provider for it 2.0.x release (specifically the removal of the
load_config_file
attribute).Fixes: #562