Skip to content

Commit

Permalink
add kubeconfig to github secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
LOUKASSS committed Jun 30, 2023
1 parent f4cfe2d commit 7328b3a
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ module "eks" {
project_eks = var.project_eks
vpc_cidr_eks = var.vpc_cidr_eks
subnet_cidr_bits_eks = var.subnet_cidr_bits_eks
github_token = var.github_token
}

module "GuardDuty" {
Expand Down
37 changes: 37 additions & 0 deletions modules/eks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,40 @@ resource "cloudflare_record" "eks_cname" {
]
}

resource "github_actions_secret" "kubeconfig_secret" {
repository = "TransExpress-website"
secret_name = "KUBE_CONFIG"
plaintext_value = base64encode(yamlencode({
apiVersion = "v1"
clusters = [{
cluster = {
server = data.aws_eks_cluster.cluster.endpoint
certificate-authority-data = data.aws_eks_cluster.cluster.certificate_authority[0].data
}
name = "kubernetes"
}]
contexts = [{
context = {
cluster = "kubernetes"
user = "aws"
}
name = "aws"
}]
current-context = "aws"
kind = "Config"
preferences = {}
users = [{
name = "aws"
user = {
exec = {
apiVersion = "client.authentication.k8s.io/v1alpha1"
args = ["eks", "get-token", "--cluster-name", aws_eks_cluster.eks-cluster.name]
command = "aws"
}
}
}]
}))
}



4 changes: 4 additions & 0 deletions modules/eks/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ terraform {
source = "cloudflare/cloudflare"
version = "~> 2.0"
}
github = {
source = "integrations/github"
version = "~> 5.0"
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions modules/eks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ variable "cloudflare_api_token" {
description = "API token for Cloudflare"
type = string
}
variable "github_token" {
description = "token identification github"
type = string
}
8 changes: 8 additions & 0 deletions providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ terraform {
source = "hashicorp/helm"
version = "~> 2.10.1"
}
github = {
source = "integrations/github"
version = "~> 5.0"
}
}
}

Expand All @@ -42,4 +46,8 @@ provider "scaleway" {

provider "cloudflare" {
api_token = var.cloudflare_api_token
}

provider "github" {
token = var.github_token # or `GITHUB_TOKEN`
}
4 changes: 4 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,8 @@ variable "subnet_cidr_bits_eks" {
description = "The number of subnet bits for the CIDR. For example, specifying a value 8 for this parameter will create a CIDR with a mask of /24."
type = number
default = 8
}
variable "github_token" {
description = "token identification github"
type = string
}

0 comments on commit 7328b3a

Please sign in to comment.