platform

package
v0.0.0-...-7b190fc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 20 Imported by: 2

README

Terrarium Platform Metadata

The Terrarium Platform Metadata YAML format is used to declare information about the components and their relationships within the Terrarium platform template. It helps organize and describe various components and their dependencies, allowing Terrarium tools to understand and validate the platform's structure.

Components

The components section in the metadata defines the different dependency interfaces that are implemented in the Terrarium platform template. Each component is represented as a YAML object with the following properties:

  • id (string): A unique identifier for the component. It helps in referencing the component in other parts of the metadata or code. It also represents the dependency interface ID which is been implemented by this component. This helps in generalizing the inputs and outputs for the component. There can only be one implementation of a dependency in one platform.
  • title (string): A descriptive title for the component, providing a brief overview of its purpose.
  • description (string): A detailed description of the component's functionality and its significance within the platform.
  • inputs (JSON Schema): Defines the input parameters required by the component. It follows the JSON Schema format to specify the input properties, their data types, titles, and descriptions.
  • outputs (JSON Schema): Defines the output properties produced by the component. It also follows the JSON Schema format to specify the output properties, their data types, titles, and descriptions.

Graph

The graph section in the metadata defines the relationships between different terraform blocks in the Terrarium platform template. It represents a directed acyclic graph (DAG) of component dependencies. Each graph node is represented as a YAML object with the following properties:

  • id (string): A unique identifier for the graph node, typically corresponding to the component ID or resource name.
  • requirements (array of strings): Specifies the IDs of other graph nodes that the current node depends on. This indicates the dependencies between components and their order of execution during Terraform generation.

Example

Below is an example of a Terrarium Platform Metadata YAML file:

components:
  - id: postgres
    title: PostgreSQL Database
    description: A relational database management system using SQL.
    inputs:
      properties: # JSON schema format
        version:
          type: number
          title: Engine Version
          description: The version of PostgreSQL to use.
    outputs:
      properties:
        host:
          type: string
          title: Host
          description: The host address of the PostgreSQL server.
        port:
          type: number
          title: Port
          description: The port number on which the PostgreSQL server is listening.
        username:
          type: string
          title: Username
          description: The username for accessing the PostgreSQL database.
        password:
          type: string
          title: Password
          description: The password for accessing the PostgreSQL database.

graph:
    - id: module.tr_component_postgres
      requirements:
        - module.postgres_security_group
        - module.core_vpc
    - id: module.postgres_security_group
      requirements:
        - module.core_vpc
    - id: module.core_vpc
      requirements:
        - resource.random_string.random
    - id: resource.random_string.random
      requirements: []

In this example, the metadata defines a "postgres" component with its title, description, inputs, and outputs. Additionally, the graph section establishes the relationships between different terraform blocks using their IDs and their corresponding requirements.

By using the Terrarium Platform Metadata YAML format, DevOps professionals can create well-structured and organized Terrarium platforms with clear component definitions and their dependencies, facilitating better collaboration and understanding among team members.

Documentation

Index

Constants

View Source
const (
	ComponentDocPrefix = "component"     // Documentation comment prefix (i.e. "component[<name-override>]: <description>")
	ComponentPrefix    = "tr_component_" // Prefix for component identifiers in terraform code
)

Variables

This section is empty.

Functions

func GetDoc

func GetDoc(filename string, endBytePos int, reverse bool) (args map[string]string, err error)

GetDoc reads a given file and returns documentation when reverse is false the file is read from the beginning until the end byte position or the EOF (endBytePos < 0 reads the entire file) when reverse is true the file is read from the end byte position to the beginning.

func SetListFromDocIfFound

func SetListFromDocIfFound(values *[]interface{}, valueTagName string, fieldDoc map[string]string)

func SetValueFromDocIfFound

func SetValueFromDocIfFound(value *string, valueTagName string, fieldDoc map[string]string) (ok bool)

Types

type BlockDependencyGetter

type BlockDependencyGetter interface {
	GetDependencies() map[string]tfconfig.AttributeReference
}

type BlockID

type BlockID string

BlockID represents a unique identifier for a terraform block.

func NewBlockID

func NewBlockID(t BlockType, bKey string) BlockID

func (BlockID) FindRequirements

func (bID BlockID) FindRequirements(m *tfconfig.Module) (requirements []BlockID)

func (BlockID) GetBlock

func (bID BlockID) GetBlock(m *tfconfig.Module) (b ParsedBlock, found bool)

func (BlockID) Parse

func (bID BlockID) Parse() (t BlockType, bKey string)

func (BlockID) ParseComponent

func (b BlockID) ParseComponent() (bt BlockType, componentName string)

type BlockParentPosGetter

type BlockParentPosGetter interface {
	GetParentPos() *tfconfig.SourcePos
}

type BlockProviderGetter

type BlockProviderGetter interface {
	GeProviderName() string
}

type BlockType

type BlockType string

BlockType represents the type of a terraform block.

const (
	BlockType_Undefined  BlockType = ""         // Undefined block type
	BlockType_ModuleCall BlockType = "module"   // Module call block type
	BlockType_Resource   BlockType = "resource" // Resource block type
	BlockType_Data       BlockType = "data"     // Data block type
	BlockType_Local      BlockType = "local"    // Local block type
	BlockType_Variable   BlockType = "var"      // Variable block type
	BlockType_Output     BlockType = "output"   // Output block type
	BlockType_Provider   BlockType = "provider" // Provider block type
)

func GetBlockType

func GetBlockType(t string) BlockType

GetBlockType returns a BlockType from pre-defined set of constants. This would be similar to typecast except, it changes unrecognized values to BlockType_Undefined

type Component

type Component struct {
	ID          string           `yaml:",omitempty"` // Unique identifier for the component
	Title       string           `yaml:",omitempty"` // Descriptive title for the component
	Description string           `yaml:",omitempty"` // Detailed description of the component's functionality
	Inputs      *jsonschema.Node `yaml:",omitempty"` // Input parameters required by the component
	Outputs     *jsonschema.Node `yaml:",omitempty"` // Output properties produced by the component
}

Component represents an implementation of a dependency in the Terrarium platform.

type Components

type Components []Component

Components is a slice of Component objects.

func NewComponents

func NewComponents(platformModule *tfconfig.Module) Components

func (*Components) Append

func (cArr *Components) Append(c Component) *Component

func (Components) GetByID

func (cArr Components) GetByID(id string) *Component

func (*Components) Parse

func (cArr *Components) Parse(platformModule *tfconfig.Module)

type Graph

type Graph []GraphNode

Graph defines the relationships between terraform blocks.

func NewGraph

func NewGraph(platformModule *tfconfig.Module) Graph

func (*Graph) Append

func (g *Graph) Append(bID BlockID, requirements []BlockID) *GraphNode

func (Graph) GetByID

func (g Graph) GetByID(id BlockID) *GraphNode

func (*Graph) Parse

func (g *Graph) Parse(srcModule *tfconfig.Module)

func (*Graph) Walk

func (g *Graph) Walk(roots []BlockID, cb GraphWalkerCB) error

Walk a function to traverse all requirements starting from the given nodes and call cb exactly once for each node that is connected to the given set of nodes. Terraform Outputs are traversed differently in the end, such that, each output that is able to resolve with the blocks been traversed, are selected.

type GraphNode

type GraphNode struct {
	ID           BlockID   // Unique identifier for the graph node
	Requirements []BlockID // IDs of other graph nodes that the current node depends on
}

GraphNode represents a single node in the graph. It includes the node's ID and the IDs of the nodes it depends on.

type GraphWalkerCB

type GraphWalkerCB func(blockId BlockID) error

type LineReader

type LineReader interface {
	Read(lines *[]string) (err error)
}

func NewLineReader

func NewLineReader(fp *os.File, endBytePos int, reverse bool) LineReader

type ParsedBlock

type ParsedBlock interface {
	GetPos() tfconfig.SourcePos
}

type PlatformMetadata

type PlatformMetadata struct {
	Profiles   Profiles   // Configuration profiles in the platform
	Components Components // Components in the Terrarium platform
	Graph      Graph      // Graph defining the relationships between terraform blocks
}

PlatformMetadata represents the metadata for the Terrarium platform. It includes the components and the graph that defines the relationships between terraform blocks.

func NewPlatformMetadata

func NewPlatformMetadata(platformModule *tfconfig.Module, existingYaml []byte) (*PlatformMetadata, error)

NewPlatformMetadata creates a new PlatformMetadata object. It parses the platform module and existing YAML to create the components and the graph.

func (*PlatformMetadata) FromFileBytes

func (pm *PlatformMetadata) FromFileBytes(bytes []byte) error

type Profile

type Profile struct {
	ID          string `yaml:",omitempty"` // Unique identifier for the profile
	Title       string `yaml:",omitempty"` // Descriptive title for the profile
	Description string `yaml:",omitempty"` // Detailed description of the profile's properties
}

Profile represents a set of pre-set configuration variables that can be applied to generated Terraform code.

type Profiles

type Profiles []Profile

Profiles is a slice of Profile objects.

func (*Profiles) Append

func (pArr *Profiles) Append(p Profile) *Profile

func (Profiles) GetByID

func (pArr Profiles) GetByID(id string) *Profile

func (*Profiles) Parse

func (pArr *Profiles) Parse(platformModule *tfconfig.Module)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL