Skip to content

Commit

Permalink
TER-412 regenerate platform metadata on lint
Browse files Browse the repository at this point in the history
change the behavior of lint command to always regenerate the
platform metadata file (terrarium.yaml) on every lint command execution

This implies that the manual changes in platform metadata file are not
acceptable now.
this also impacts the behavior of terrarium generate command such that
it doesn't respect the manual changes in the platform metadata file

This also impacts the example platform since it was not
actually implementing the dependencies and it was only
added to the metadata file to bypass the errors.
Therefore this change also has updates the the `example/platform`
such that now it implements each dependency in terraform and doesn't
have manually adjusted metadata.
Although the `example/platform` contains working mock implementation
such that it can be used to test the t8 lint & generate command and can
also run terraform plan and apply successfully but it'll generate
random mock values for output instead of actually provisioning resources
on cloud.
  • Loading branch information
Kanak Singhal committed Dec 21, 2023
1 parent 640b4dd commit 7e3ed32
Show file tree
Hide file tree
Showing 26 changed files with 1,179 additions and 439 deletions.
45 changes: 0 additions & 45 deletions examples/platform/.terraform.lock.hcl

This file was deleted.

39 changes: 39 additions & 0 deletions examples/platform/component_job.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module "job_queue_runner" {
source = "./mock-modules/k8s-service"

for_each = local.tr_component_job_queue

name = "queue_watcher_${each.key}"
cluster_id = module.k8s_cluster.cluster_id
}

module "job_scheduled_runner" {
source = "./mock-modules/k8s-service"

for_each = local.tr_component_job_scheduled

name = "scheduler_${each.key}"
cluster_id = module.k8s_cluster.cluster_id
}

# A job that performs tasks in the queue.
# @title: Queue Job
module "tr_component_job_queue" {
source = "./mock-modules/pubsub-queue"

for_each = local.tr_component_job_queue

event_receiver_url = module.job_queue_runner[each.key].host
name = each.key
}

# A job that is run at scheduled intervals.
# @title: Scheduled Job
module "tr_component_job_scheduled" {
source = "./mock-modules/cloud-scheduler"

for_each = local.tr_component_job_scheduled

event_receiver_url = module.job_scheduled_runner[each.key].host
name = each.key
}
4 changes: 2 additions & 2 deletions examples/platform/component_postgres.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# A relational database management system using SQL.
# @title: PostgreSQL Database
module "tr_component_postgres" {
source = "terraform-aws-modules/rds/aws"
source = "./mock-modules/rds"

for_each = local.tr_component_postgres

Expand All @@ -18,7 +18,7 @@ module "tr_component_postgres" {
}

module "postgres_security_group" {
source = "terraform-aws-modules/security-group/aws"
source = "./mock-modules/security-group"

name = "postgres_sg"
vpc_id = module.core_vpc.vpc_id
Expand Down
15 changes: 2 additions & 13 deletions examples/platform/component_redis.tf
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
# An in-memory data structure store used as a cache or message broker.
# @title: Redis Cache
module "tr_component_redis" {
source = "cloudposse/elasticache-redis/aws"
source = "./mock-modules/elasticache-redis"

for_each = local.tr_component_redis

availability_zones = local.azs
vpc_id = module.core_vpc.default_vpc_id
vpc_id = module.core_vpc.vpc_id
allowed_security_group_ids = [module.core_vpc.default_security_group_id]
subnets = module.core_vpc.elasticache_subnets
apply_immediately = true
automatic_failover_enabled = false
engine_version = each.value.version

context = module.this.context
}

module "this" {
source = "cloudposse/label/null"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "var.namespace"
stage = "var.stage"
name = "var.name"
}
39 changes: 39 additions & 0 deletions examples/platform/component_server.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# A server that hosts and serves static files.
# @title: Static Server
module "tr_component_server_static" {
source = "./mock-modules/bucket-static-site"

for_each = local.tr_component_server_static

bucket_name = each.key
}

module "k8s_cluster" {
source = "./mock-modules/k8s-cluster"
}

# A server that hosts web applications and handles HTTP requests.
# @title: Web Server
module "tr_component_server_web" {
source = "./mock-modules/k8s-service"

for_each = local.tr_component_server_web

cluster_id = module.k8s_cluster.cluster_id
is_public = true
name = each.key
port = each.value.port
}

# A server that is not exposed to the public internet.
# @title: Private Server
module "tr_component_server_private" {
source = "./mock-modules/k8s-service"

for_each = local.tr_component_server_private

cluster_id = module.k8s_cluster.cluster_id
is_public = false
name = each.key
port = each.value.port
}
26 changes: 26 additions & 0 deletions examples/platform/mock-modules/bucket-static-site/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
variable "bucket_name" {
description = "Name of the bucket"
type = string
default = "by_bucket"
}

variable "index_document" {
description = "Index document for the website"
type = string
default = "index.html"
}

variable "error_document" {
description = "Error document for the website"
type = string
default = "error.html"
}

resource "random_pet" "random" {
length = 2
}

output "website_endpoint" {
description = "The website endpoint URL"
value = "http://${random_pet.random.id}.mocksite.com"
}
20 changes: 20 additions & 0 deletions examples/platform/mock-modules/cloud-scheduler/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
variable "name" {
type = string
description = "Name of the scheduler"
default = "default"
}

variable "event_receiver_url" {
type = string
description = "URL to push the events to"
default = ""
}

resource "random_id" "random" {
byte_length = 8
}

output "scheduler_id" {
description = "Id of the scheduler"
value = random_id.random.id
}
72 changes: 72 additions & 0 deletions examples/platform/mock-modules/elasticache-redis/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# --- Input

variable "availability_zones" {
type = list(string)
description = "A list of availability zones in which to place the cluster"
default = ["us-west-1a", "us-west-1b"]
}

variable "vpc_id" {
type = string
description = "The VPC ID where the cluster is created"
default = "vpc-12345678"
}

variable "allowed_security_group_ids" {
type = list(string)
description = "A list of Security Group IDs that are allowed to access the cluster"
default = ["sg-12345678"]
}

variable "subnets" {
type = list(string)
description = "A list of subnet IDs for the cluster"
default = ["subnet-12345678", "subnet-23456789"]
}

variable "apply_immediately" {
type = bool
description = "Specifies whether any modifications are applied immediately, or during the next maintenance window"
default = true
}

variable "automatic_failover_enabled" {
type = bool
description = "Specifies whether a read-only replica will be automatically promoted to primary if the existing primary fails"
default = false
}

variable "engine_version" {
type = string
description = "The version number of the cache engine to use"
default = "6.x"
}

# --- Config

resource "random_pet" "redis_instance" {
length = 2
}

resource "random_password" "redis_password" {
length = 16
special = true
}

# --- Output

output "host" {
description = "The DNS name of the cache instance"
value = "${random_pet.redis_instance.id}.mock-elasticache.com"
}

output "port" {
description = "The port number on which each of the cache nodes will accept connections"
value = "6379" # Default Redis port
}

output "password" {
description = "The password used to access a password-protected Redis server"
value = random_password.redis_password.result
sensitive = true
}
14 changes: 14 additions & 0 deletions examples/platform/mock-modules/k8s-cluster/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "name" {
type = string
description = "Name cluster name"
default = ""
}

resource "random_id" "random" {
byte_length = 8
}

output "cluster_id" {
description = "cluster id"
value = random_id.random.id
}
32 changes: 32 additions & 0 deletions examples/platform/mock-modules/k8s-service/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
variable "name" {
type = string
description = "Name of the service"
default = ""
}

variable "port" {
type = number
description = "Port to bind the service at"
default = 80
}

variable "cluster_id" {
type = string
description = "ID of the cluster"
default = ""
}

variable "is_public" {
type = bool
description = "Should this service be exposed to the public network"
default = false
}

resource "random_pet" "random" {
length = 2
}

output "host" {
description = "The service host"
value = "${random_pet.random.id}.mocksite.com"
}
25 changes: 25 additions & 0 deletions examples/platform/mock-modules/pubsub-queue/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
variable "name" {
type = string
description = "Name of the queue"
default = "default"
}

variable "event_receiver_url" {
type = string
description = "URL for push based model where the events are sent to the given url"
default = ""
}

resource "random_id" "random" {
byte_length = 8
}

output "queue_id" {
description = "Id of the queue"
value = random_id.random.id
}

output "queue_url" {
description = "URL of the queue to send events at and query for messages using sdk"
value = "http://${random_id.random.id}.mockqueue.com"
}
Loading

1 comment on commit 7e3ed32

@code-pipes
Copy link

@code-pipes code-pipes bot commented on 7e3ed32 Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Job Name terrarium-cli-test-on-pr-sqlite
Job Status failed
Total Steps 2
Progress 1
Message An unexpected error occurred: build has finished with status: Failure
View on Code Pipes

Please sign in to comment.