Skip to content

Commit 3ac53c2

Browse files
committed
use a data source instead of aws cli
1 parent 2982944 commit 3ac53c2

File tree

4 files changed

+23
-27
lines changed

4 files changed

+23
-27
lines changed

terraform/aws/aws-eks-operator/README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,17 @@ This example creates the following:
1717

1818
## Prerequisites
1919

20-
- The configuration as-is uses currently only works on macOS or Linux clients. Remove or comment out the `null_resource` provisioners that deploy `tailscale-api-server-ha-proxy.yaml` for the [high availability API server proxy](https://tailscale.com/kb/1437/kubernetes-operator-api-server-proxy#configuring-a-high-availability-api-server-proxy) to run from other platforms.
21-
- Requires the [AWS CLI](https://aws.amazon.com/cli/) for initial authentication to the created AWS EKS cluster.
22-
- Create a [Tailscale OAuth Client](https://tailscale.com/kb/1215/oauth-clients#setting-up-an-oauth-client) with appropriate scopes
23-
- Ensure you have AWS CLI configured with appropriate permissions for EKS
24-
- Install `kubectl` for cluster access after deployment
20+
- Follow the [Kubernetes Operator prerequisites](https://tailscale.com/kb/1236/kubernetes-operator#prerequisites).
21+
- For the [high availability API server proxy](https://tailscale.com/kb/1437/kubernetes-operator-api-server-proxy#configuring-a-high-availability-api-server-proxy):
22+
- The configuration as-is uses currently only works on macOS or Linux clients. Remove or comment out the `null_resource` provisioners that deploy `tailscale-api-server-ha-proxy.yaml` to run from other platforms.
23+
- Requires the [kubectl CLI](https://kubernetes.io/docs/reference/kubectl/) and [AWS CLI](https://aws.amazon.com/cli/).
24+
2525

2626
## To use
2727

2828
Follow the documentation to configure the Terraform providers:
2929

3030
- [AWS](https://registry.terraform.io/providers/hashicorp/aws/latest/docs)
31-
- [Kubernetes](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs)
32-
- [Helm](https://registry.terraform.io/providers/hashicorp/helm/latest/docs)
3331

3432
### Configure variables
3533

@@ -59,7 +57,7 @@ Check that the Tailscale operator is running:
5957

6058
```shell
6159
kubectl get pods -n tailscale
62-
kubectl logs -n tailscale -l app.kubernetes.io/name=tailscale-operator
60+
kubectl logs -n tailscale -l app.kubernetes.io/name=$(terraform output -raw operator_name)
6361
```
6462

6563
#### Verify connectivity via the [API server proxy](https://tailscale.com/kb/1437/kubernetes-operator-api-server-proxy)

terraform/aws/aws-eks-operator/data.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ data "aws_region" "current" {}
33
data "aws_eks_cluster_versions" "latest" {
44
default_only = true
55
}
6+
7+
data "aws_eks_cluster_auth" "this" {
8+
name = module.eks.cluster_name
9+
}

terraform/aws/aws-eks-operator/main.tf

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ locals {
1818

1919
# Tailscale Operator configuration
2020
namespace_name = "tailscale"
21-
operator_name = "${local.name}-${random_string.operator_name_suffix.result}"
21+
operator_name = "${local.name}-${random_integer.operator_name_suffix.result}"
2222
operator_version = "1.92.4"
2323
tailscale_oauth_client_id = var.tailscale_oauth_client_id
2424
tailscale_oauth_client_secret = var.tailscale_oauth_client_secret
@@ -28,11 +28,9 @@ locals {
2828
}
2929

3030
# This isn't required but helps avoid conflicts and Let's Encrypt throttling to make testing and iterating easier.
31-
resource "random_string" "operator_name_suffix" {
32-
length = 3
33-
numeric = false
34-
special = false
35-
upper = false
31+
resource "random_integer" "operator_name_suffix" {
32+
min = 100
33+
max = 999
3634
}
3735

3836
# Remove this to use your own VPC.
@@ -94,6 +92,10 @@ resource "kubernetes_namespace_v1" "tailscale_operator" {
9492
"pod-security.kubernetes.io/enforce" = "privileged"
9593
}
9694
}
95+
96+
depends_on = [
97+
module.eks,
98+
]
9799
}
98100

99101
#

terraform/aws/aws-eks-operator/versions.tf

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,19 @@ terraform {
2626
}
2727

2828
provider "kubernetes" {
29-
alias = "this"
29+
alias = "this"
30+
3031
host = module.eks.cluster_endpoint
3132
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
32-
33-
exec {
34-
api_version = "client.authentication.k8s.io/v1"
35-
command = "aws"
36-
args = ["eks", "get-token", "--cluster-name", module.eks.cluster_name]
37-
}
33+
token = data.aws_eks_cluster_auth.this.token
3834
}
3935

4036
provider "helm" {
4137
alias = "this"
38+
4239
kubernetes = {
4340
host = module.eks.cluster_endpoint
4441
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
45-
46-
exec = {
47-
api_version = "client.authentication.k8s.io/v1"
48-
command = "aws"
49-
args = ["eks", "get-token", "--cluster-name", module.eks.cluster_name]
50-
}
42+
token = data.aws_eks_cluster_auth.this.token
5143
}
5244
}

0 commit comments

Comments
 (0)