Skip to content

Commit

Permalink
refactor(terraform): use aws_eks_cluster data source for dynamic clus…
Browse files Browse the repository at this point in the history
…ter info

Replace hardcoded cluster endpoint and CA certificate variables with
dynamic retrieval using aws_eks_cluster data source. This change
removes the need for cluster_ca_certificate and cluster_endpoint
variables, simplifying configuration and reducing manual input.
  • Loading branch information
sachincool committed Oct 28, 2024
1 parent a90c72b commit 42474f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
9 changes: 7 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ data "aws_eks_cluster_auth" "cluster" {
name = var.cluster_name
}

data "aws_eks_cluster" "cluster" {

Check warning on line 5 in main.tf

View workflow job for this annotation

GitHub Actions / tflint (ubuntu-latest)

Missing version constraint for provider "aws" in `required_providers`

Check warning on line 5 in main.tf

View workflow job for this annotation

GitHub Actions / tflint (macos-latest)

Missing version constraint for provider "aws" in `required_providers`

Check warning on line 5 in main.tf

View workflow job for this annotation

GitHub Actions / tflint (windows-latest)

Missing version constraint for provider "aws" in `required_providers`
name = var.cluster_name
}


resource "null_resource" "helm_install" {

Check warning on line 10 in main.tf

View workflow job for this annotation

GitHub Actions / tflint (ubuntu-latest)

Missing version constraint for provider "null" in `required_providers`

Check warning on line 10 in main.tf

View workflow job for this annotation

GitHub Actions / tflint (macos-latest)

Missing version constraint for provider "null" in `required_providers`

Check warning on line 10 in main.tf

View workflow job for this annotation

GitHub Actions / tflint (windows-latest)

Missing version constraint for provider "null" in `required_providers`
triggers = {
chart_name = var.chart_name
Expand All @@ -25,8 +30,8 @@ resource "null_resource" "helm_install" {
kind: Config
clusters:
- cluster:
server: ${var.cluster_endpoint}
certificate-authority-data: ${var.cluster_ca_certificate}
server: ${data.aws_eks_cluster.cluster.endpoint}
certificate-authority-data: ${data.aws_eks_cluster.cluster.certificate_authority[0].data}
name: kubernetes
contexts:
- context:
Expand Down
10 changes: 0 additions & 10 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ variable "repo_url" {
description = "URL of the Helm repository"
}

variable "cluster_ca_certificate" {
type = string
description = "CA certificate of the cluster"
}

variable "cluster_endpoint" {
type = string
description = "Endpoint of the cluster"
}

variable "cluster_name" {
type = string
description = "Name of the cluster"
Expand Down

0 comments on commit 42474f3

Please sign in to comment.