Skip to content

Commit

Permalink
Merge pull request #7 from OpsLevel/kr/domains-systems
Browse files Browse the repository at this point in the history
First pass at a hierarchy module
  • Loading branch information
rocktavious authored Aug 30, 2024
2 parents ea9f902 + 04f9e34 commit c1247b6
Show file tree
Hide file tree
Showing 21 changed files with 213 additions and 3 deletions.
2 changes: 1 addition & 1 deletion modules/filter/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
data "opslevel_filters" "all" {}

resource "opslevel_filter" "test" {
resource "opslevel_filter" "this" {
name = var.name
connective = var.connective

Expand Down
4 changes: 4 additions & 0 deletions modules/filter/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
output "all" {
value = data.opslevel_filters.all
}

output "this" {
value = opslevel_filter.this
}
7 changes: 7 additions & 0 deletions modules/hierarchy/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# OpsLevel Hierarchy Sub-Module

This module is used to model a hierarchy of domains, systems and services in OpsLevel.

## Inputs

## Outputs
7 changes: 7 additions & 0 deletions modules/hierarchy/domain/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# OpsLevel Domain Sub-Module

This module is used to create a 'domain' in OpsLevel.

## Inputs

## Outputs
18 changes: 18 additions & 0 deletions modules/hierarchy/domain/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
data "opslevel_domains" "all" {}

resource "opslevel_domain" "this" {
name = var.name
description = var.description
owner = local.owner
note = var.note
}

module "systems" {
source = "../system"
for_each = { for system in var.systems : system.name => system }
name = each.value.name
description = each.value.description
domain = opslevel_domain.this.id
owner = each.value.owner
services = each.value.services
}
11 changes: 11 additions & 0 deletions modules/hierarchy/domain/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "all" {
value = data.opslevel_domains.all.domains
}

output "this" {
value = opslevel_domain.this
}

output "systems" {
value = values(module.systems)
}
42 changes: 42 additions & 0 deletions modules/hierarchy/domain/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
variable "name" {
type = string
description = "The name of the domain."
}

variable "description" {
type = string
description = "The description of the domain."
default = null
}

variable "owner" {
type = string
description = "The team that owns the domain."
default = null
}

variable "note" {
type = string
description = "Additional information about the domain."
default = null
}

variable "systems" {
type = list(object({
name = string
description = optional(string)
owner = optional(string)
services = list(string)
}))
default = []
}

// TODO: This is us papering over the fact that we cannot use team alias for the owner field in domain - https://github.com/OpsLevel/team-platform/issues/461
data "opslevel_teams" "all" {}

locals {
owner = var.owner == null ? null : (startswith(var.owner, "Z2lkOi8v") ? var.owner : flatten([
for obj in data.opslevel_teams.all.teams :
obj.id if obj.alias == var.owner
])[0])
}
1 change: 1 addition & 0 deletions modules/hierarchy/domain/versions.tf
12 changes: 12 additions & 0 deletions modules/hierarchy/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
data "opslevel_domains" "all" {}

data "opslevel_systems" "all" {}

module "domains" {
source = "./domain"
for_each = { for domain in var.domains : domain.name => domain }
name = each.value.name
description = each.value.description
owner = each.value.owner
systems = each.value.systems
}
11 changes: 11 additions & 0 deletions modules/hierarchy/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output "all_domains" {
value = data.opslevel_domains.all.domains
}

output "all_systems" {
value = data.opslevel_systems.all.systems
}

output "this" {
value = values(module.domains)[*].this
}
7 changes: 7 additions & 0 deletions modules/hierarchy/system/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# OpsLevel System Sub-Module

This module is used to create a 'system' in OpsLevel.

## Inputs

## Outputs
16 changes: 16 additions & 0 deletions modules/hierarchy/system/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
data "opslevel_systems" "all" {}

resource "opslevel_system" "this" {
description = var.description
domain = var.domain
name = var.name
note = var.note
owner = local.owner
}

# TODO: This would be a really clean way to ensure service.parent is set via this module
#resource "opslevel_service_relationship" "this" {
# for_each = { for service in var.services : service => service }
# system = opslevel_system.this.id
# service = each.value
#}
7 changes: 7 additions & 0 deletions modules/hierarchy/system/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "all" {
value = data.opslevel_systems.all
}

output "this" {
value = opslevel_system.this
}
44 changes: 44 additions & 0 deletions modules/hierarchy/system/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
variable "name" {
type = string
description = "The name for the system."
}

variable "description" {
type = string
description = "The description for the system."
default = null
}

variable "domain" {
type = string
description = "The parent domain this system is a child of."
default = null
}

variable "note" {
type = string
description = "Additional information about the system."
default = null
}

variable "owner" {
type = string
description = "The team that owns the system."
default = null
}

variable "services" {
type = list(string)
description = "The services that this system is responsible for."
default = []
}

// TODO: This is us papering over the fact that we cannot use team alias for the owner field in system - https://github.com/OpsLevel/team-platform/issues/461
data "opslevel_teams" "all" {}

locals {
owner = var.owner == null ? null : (startswith(var.owner, "Z2lkOi8v") ? var.owner : flatten([
for obj in data.opslevel_teams.all.teams :
obj.id if obj.alias == var.owner
])[0])
}
1 change: 1 addition & 0 deletions modules/hierarchy/system/versions.tf
13 changes: 13 additions & 0 deletions modules/hierarchy/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
variable "domains" {
type = list(object({
name = string
description = optional(string)
owner = optional(string)
systems = list(object({
name = string
description = optional(string)
owner = optional(string)
services = list(string)
}))
}))
}
1 change: 1 addition & 0 deletions modules/hierarchy/versions.tf
2 changes: 1 addition & 1 deletion modules/team/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
data "opslevel_teams" "all" {}

resource "opslevel_team" "test" {
resource "opslevel_team" "this" {
aliases = var.aliases
name = var.name
parent = var.parent
Expand Down
4 changes: 4 additions & 0 deletions modules/team/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
output "all" {
value = data.opslevel_teams.all
}

output "this" {
value = opslevel_team.this
}
2 changes: 1 addition & 1 deletion modules/user/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
data "opslevel_users" "all" {}

resource "opslevel_user" "test" {
resource "opslevel_user" "this" {
email = var.email
name = var.name
role = var.role
Expand Down
4 changes: 4 additions & 0 deletions modules/user/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
output "all" {
value = data.opslevel_users.all
}

output "this" {
value = opslevel_user.this
}

0 comments on commit c1247b6

Please sign in to comment.