Merge pull request #63 from HideyoshiSolutions/feature/better-kubeconfig-managment
feat: better kubeconfig managment
This commit is contained in:
17
config.tf
17
config.tf
@@ -39,7 +39,12 @@ variable "aws_secret" {
|
|||||||
sensitive = true
|
sensitive = true
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "aws_instance_type" {
|
variable "aws_main_instance_type" {
|
||||||
|
type = string
|
||||||
|
default = "t4g.small"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "aws_worker_instance_type" {
|
||||||
type = string
|
type = string
|
||||||
default = "t4g.micro"
|
default = "t4g.micro"
|
||||||
}
|
}
|
||||||
@@ -84,7 +89,11 @@ variable "github_token" {
|
|||||||
sensitive = true
|
sensitive = true
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "github_repository" {
|
variable "github_repositories" {
|
||||||
type = string
|
type = list(string)
|
||||||
default = "infra-hideyoshi.com"
|
default = [
|
||||||
|
"frontend-hideyoshi.com",
|
||||||
|
"backend-hideyoshi.com",
|
||||||
|
"storage-hideyoshi.com",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
@@ -4,12 +4,10 @@ variable "environment_name" {
|
|||||||
|
|
||||||
variable "github_owner" {
|
variable "github_owner" {
|
||||||
type = string
|
type = string
|
||||||
default = "HideyoshiSolutions"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "github_repository" {
|
variable "github_repositories" {
|
||||||
type = string
|
type = list(string)
|
||||||
default = "infra-hideyoshi.com"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,17 +7,15 @@ terraform {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data "github_user" "current" {
|
|
||||||
username = ""
|
data "github_repository" "repos" {
|
||||||
|
for_each = toset(var.github_repositories)
|
||||||
|
full_name = "${var.github_owner}/${each.value}"
|
||||||
}
|
}
|
||||||
|
|
||||||
data "github_repository" "infra_hideyoshi_com" {
|
resource "github_actions_organization_secret" "cluster_kubeconfig" {
|
||||||
full_name = "${var.github_owner}/${var.github_repository}"
|
visibility = "selected"
|
||||||
}
|
selected_repository_ids = [for repo in data.github_repository.repos : repo.repo_id]
|
||||||
|
secret_name = "PORTFOLIO_KUBECONFIG"
|
||||||
resource "github_actions_environment_secret" "cluster_kubeconfig" {
|
|
||||||
repository = data.github_repository.infra_hideyoshi_com.name
|
|
||||||
environment = var.environment_name
|
|
||||||
secret_name = "KUBECONFIG"
|
|
||||||
plaintext_value = chomp(var.cluster_kubeconfig)
|
plaintext_value = chomp(var.cluster_kubeconfig)
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
variable "project_name" {
|
variable "project_name" {
|
||||||
type = string
|
type = string
|
||||||
default = "hideyoshi-portifolio"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "project_domain" {
|
variable "project_domain" {
|
||||||
@@ -20,17 +19,18 @@ variable "number_of_workers" {
|
|||||||
|
|
||||||
variable "aws_region" {
|
variable "aws_region" {
|
||||||
type = string
|
type = string
|
||||||
default = "sa-east-1"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "aws_instance_type" {
|
variable "aws_main_instance_type" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "aws_worker_instance_type" {
|
||||||
type = string
|
type = string
|
||||||
default = "t4g.micro"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "aws_ami" {
|
variable "aws_ami" {
|
||||||
type = string
|
type = string
|
||||||
default = "ami-06a17a87e19be286a"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "aws_spot_price" {
|
variable "aws_spot_price" {
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ resource "aws_security_group" "project_pool" {
|
|||||||
|
|
||||||
resource "aws_instance" "main" {
|
resource "aws_instance" "main" {
|
||||||
ami = var.aws_ami
|
ami = var.aws_ami
|
||||||
instance_type = var.aws_instance_type
|
instance_type = var.aws_main_instance_type
|
||||||
vpc_security_group_ids = [aws_security_group.project_pool.id]
|
vpc_security_group_ids = [aws_security_group.project_pool.id]
|
||||||
|
|
||||||
key_name = aws_key_pair.ssh_key_main.key_name
|
key_name = aws_key_pair.ssh_key_main.key_name
|
||||||
@@ -112,7 +112,7 @@ resource "aws_instance" "main" {
|
|||||||
|
|
||||||
resource "aws_instance" "worker" {
|
resource "aws_instance" "worker" {
|
||||||
ami = var.aws_ami
|
ami = var.aws_ami
|
||||||
instance_type = var.aws_instance_type
|
instance_type = var.aws_worker_instance_type
|
||||||
vpc_security_group_ids = [aws_security_group.project_pool.id]
|
vpc_security_group_ids = [aws_security_group.project_pool.id]
|
||||||
count = var.number_of_workers
|
count = var.number_of_workers
|
||||||
|
|
||||||
|
|||||||
5
main.tf
5
main.tf
@@ -64,7 +64,8 @@ module "instances" {
|
|||||||
aws_region = var.aws_region
|
aws_region = var.aws_region
|
||||||
ssh_public_key_main = var.ssh_public_key_main
|
ssh_public_key_main = var.ssh_public_key_main
|
||||||
ssh_public_key_ci_cd = var.ssh_public_key_ci_cd
|
ssh_public_key_ci_cd = var.ssh_public_key_ci_cd
|
||||||
aws_instance_type = var.aws_instance_type
|
aws_main_instance_type = var.aws_main_instance_type
|
||||||
|
aws_worker_instance_type = var.aws_worker_instance_type
|
||||||
aws_ami = var.aws_ami
|
aws_ami = var.aws_ami
|
||||||
aws_spot_price = var.aws_spot_price
|
aws_spot_price = var.aws_spot_price
|
||||||
}
|
}
|
||||||
@@ -98,7 +99,7 @@ module "github" {
|
|||||||
}
|
}
|
||||||
environment_name = var.environment_name
|
environment_name = var.environment_name
|
||||||
github_owner = var.github_owner
|
github_owner = var.github_owner
|
||||||
github_repository = var.github_repository
|
github_repositories = var.github_repositories
|
||||||
cluster_kubeconfig = module.kubernetes.cluster_kubeconfig
|
cluster_kubeconfig = module.kubernetes.cluster_kubeconfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user