Skip to content

Commit

Permalink
fixup! init tf module
Browse files Browse the repository at this point in the history
  • Loading branch information
elchead committed Oct 23, 2023
1 parent bdea091 commit 8c81d44
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 27 deletions.
4 changes: 2 additions & 2 deletions cli/internal/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ func (h *HexBytes) UnmarshalYAML(unmarshal func(any) error) error {

bytes, err := hex.DecodeString(hexString)
if err != nil {
return fmt.Errorf("decoding hex bytes: %w", err)
*h = []byte(hexString) // was not hex encoded in Terraform
return nil // TODO fix: encode in terraform?
}

*h = bytes
return nil
}
Expand Down
13 changes: 11 additions & 2 deletions cli/internal/terraform/terraform/constellation-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ resource "terraform_data" "prepare_config" {
#} // TODO only once
provisioner "local-exec" {
command = <<EOT
rm constellation-conf.yaml constellation-state.yaml
./constellation config generate ${var.csp}
yq eval '.image = "${var.image}"' --inplace constellation-conf.yaml
yq eval '.name = "${var.name}"' --inplace constellation-conf.yaml
yq eval '.kubernetesVersion = "${var.kubernetes_version}"' --inplace constellation-conf.yaml
yq eval '.microserviceVersion = "${var.microservice_version}"' --inplace constellation-conf.yaml
yq eval '.provider.aws.region = "${var.region}"' --inplace constellation-conf.yaml
yq eval '.provider.aws.zone = "${var.zone}"' --inplace constellation-conf.yaml
yq eval '.provider.aws.zone = "${var.zone}"' --inplace constellation-conf.yaml
Expand All @@ -30,6 +33,7 @@ resource "terraform_data" "prepare_config" {
resource "terraform_data" "infra" {
provisioner "local-exec" {
command = <<EOT
./constellation config fetch-measurements
yq eval '.infrastructure.uid = "${var.uid}"' --inplace constellation-state.yaml
yq eval '.infrastructure.inClusterEndpoint = "${var.inClusterEndpoint}"' --inplace constellation-state.yaml
yq eval '.infrastructure.clusterEndpoint = "${var.clusterEndpoint}"' --inplace constellation-state.yaml
Expand All @@ -47,7 +51,12 @@ resource "terraform_data" "infra" {

resource "terraform_data" "apply" {
provisioner "local-exec" {
command = "./constellation init" # TODO use apply --yes
command = "./constellation init --force" # TODO use apply --yes
}

provisioner "local-exec" {
when = destroy
command = "./constellation terminate --yes"
}

depends_on = [
Expand Down
36 changes: 16 additions & 20 deletions cli/internal/terraform/terraform/constellation-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ variable "csp" {
default = "aws"
}

variable "name" {
type = string
description = "Name used in the cluster's named resources / cluster name"
}

# STATE related
variable "uid" {
Expand Down Expand Up @@ -35,10 +39,6 @@ variable "apiServerCertSANs" {
description = "List of additional SANs for the Kubernetes API server certificate"
}

variable "name" {
type = string
description = "Name used in the cluster's named resources"
}

# CONFIG related

Expand All @@ -62,26 +62,22 @@ variable "iam_instance_profile_control_plane" {
description = "Name of the IAM instance profile for control plane nodes"
}

#variable "image" {
# type = string
# description = "Node image version"
#}
variable "image" {
type = string
description = "Node image version"
}

#variable "kubernetes_version" {
# type = string
# description = "Kubernetes version"
#}
variable "kubernetes_version" {
type = string
description = "Kubernetes version"
}

#variable "microservice_version" {
# type = string
# description = "Microservice version"
#}
variable "microservice_version" {
type = string
description = "Microservice version"
}

#variable "name" {
# type = string
# description = "Name of your Constellation"
# validation {
# condition = length(var.name) <= 10 # TODO only checked AWS condition
# error_message = "The length of the name of the Constellation must be <= 10 characters"
# }
#}
3 changes: 3 additions & 0 deletions cli/internal/terraform/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ module "constellation" {
source = "./constellation-cluster"
csp = "aws"
name = var.name
image = var.image
microservice_version = var.microservice_version
kubernetes_version = var.kubernetes_version
uid = module.aws.uid
clusterEndpoint = module.aws.out_of_cluster_endpoint
inClusterEndpoint = module.aws.in_cluster_endpoint # TODO after apply rebased on main
Expand Down
25 changes: 22 additions & 3 deletions cli/internal/terraform/terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,25 @@ variable "name" {
}
}

variable "name_prefix" {
type = string
description = "Prefix for all resources"
variable "image" {
type = string
description = "Node image version"
default = "v2.12.0"
}

variable "microservice_version" {
type = string
description = "Microservice version"
default = "v2.12.0"
}

variable "kubernetes_version" {
type = string
description = "Kubernetes version"
default = "v1.26.9"
}


variable "node_groups" {
type = map(object({
role = string
Expand Down Expand Up @@ -89,3 +103,8 @@ variable "internal_load_balancer" {
default = false
description = "Use an internal load balancer."
}

variable "name_prefix" {
type = string
description = "Prefix for all resources"
}

0 comments on commit 8c81d44

Please sign in to comment.