pgocomp

package module
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: MIT Imports: 2 Imported by: 0

README

pulumi-components-go

This repository hosts pulumi-components-go, a library that enables better organization and utilization of Pulumi Infrastructure as Code (IaC) patterns. Pulumi is a powerful tool allowing developers to define infrastructure as code using programming languages of their choice.

Problem Statement

During an analysis of Pulumi code written in Go, it was observed that components were created alongside your functions and subsequently utilized in later component configurations. This made it difficult, especially for newcomers, to identify the dependencies each component had on others.

Moreover, the need for a library providing basic setups was felt. While awsx exists for this purpose, the belief was that creating basic libraries using the 'Component' approach could lead to more concise code and easier Infrastructure as Code reviews.

Solution

To address these challenges, the pgocomp library was developed. pgocomp turns Pulumi objects into Components, offering an easy and organized way to define infrastructure as code in Go.

Here is a sample code snippet illustrating how you can use pgocomp:

package main

import (
	"fpco-internal/pgocomp/pkg/awsc/awscnet"

	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		return awscnet.NewBasicNetworkComponent(
			"my-network",
			awscnet.BasicNetworkParameters{
				Vpc: awscnet.VpcParameters{
					Region:    "us-east-2",
					CidrBlock: "10.0.0.0/16",
				},
				PublicSubnet: awscnet.SubnetParameters{
					AvailabilityZone: "us-east-2a",
					CidrBlock:        "10.0.0.0/24",
				},
				PrivateSubnet: awscnet.SubnetParameters{
					AvailabilityZone: "us-east-2b",
					CidrBlock:        "10.0.1.0/24",
				},
			}).Apply(ctx)
	})

}

Running the samples

  1. Setup a pulumi account at https://app.pulumi.com
  2. Setup an aws cli with you credentials
  3. Cd into a sample directory. eg: "cd cmd/samples/aws-basic-network"
  4. Run the command pulumi up

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyAll

func ApplyAll(ctx *pulumi.Context, appliers ...Applier) error

ApplyAll is a function that takes a variadic list of appliers and calls the Apply method on each on of them

func ExportURNWithMeta

func ExportURNWithMeta[T pulumi.Resource](ctx *pulumi.Context, name string, r T)

ExportURNWithMeta exports the URN of pulumi Resource

Types

type Applier

type Applier interface {
	//Apply is a function that executes using a pulumi context and that returns an error
	Apply(ctx *pulumi.Context) error
}

Applier is an interface created for the ApplyAll function

type Component

type Component[T any] struct {
	// contains filtered or unexported fields
}

Component is a generic struct that allows for a diffent way to write Lazy and Idempotent Pulumi components.

func NewComponent

func NewComponent[T any](name string, apply func(ctx *pulumi.Context, name string) (T, error)) *Component[T]

NewComponent is a generic function that takes a name and an apply function and returns a Component

func NewInactiveComponent

func NewInactiveComponent[T any](name string) *Component[T]

NewInactiveComponent returns a nil internal component

func NewPulumiComponent

func NewPulumiComponent[R any, A any, O pulumi.ResourceOption](
	fn func(ctx *pulumi.Context, name string, args A, opts ...O) (R, error),
	name string,
	args A,
	opts ...O,
) *Component[R]

NewPulumiComponent is a generic function that takes a pulumi "New" function, and all its parameters and returns a component

func (*Component[T]) Apply

func (c *Component[T]) Apply(ctx *pulumi.Context) error

Apply takes a pulumi context, gets the internal component and return error if any. The internal component is discarded. Can be called multiple times, because it is cached and the component is created only once

func (*Component[T]) Get

func (c *Component[T]) Get(ctx *pulumi.Context) (*GetComponentResponse[T], error)

Get takes a pulumi context, gets the internal component and return error if any. The internal component is discarded. Can be called multiple times, because it is cached and the component is created only once

func (*Component[T]) GetAndThen

func (c *Component[T]) GetAndThen(ctx *pulumi.Context, fn func(*GetComponentResponse[T]) error) error

GetAndThen takes a pulumi context and a function that takes a generic item, gets the internal component and apply the received function with its internal component Can be called multiple times, because it is cached and the component is created only once

type ComponentWithMeta

type ComponentWithMeta[T any] struct {
	*Meta
	*Component[T]
}

ComponentWithMeta is a component created using a meta struct

func NewComponentWithMeta

func NewComponentWithMeta[T any](meta Meta, apply func(ctx *pulumi.Context, name string) (T, error)) *ComponentWithMeta[T]

NewComponentWithMeta is a generic function that takes a name and an apply function and returns a Component

func NewPulumiComponentWithMeta

func NewPulumiComponentWithMeta[R pulumi.Resource, A any, O pulumi.ResourceOption](
	fn func(ctx *pulumi.Context, name string, args A, opts ...O) (R, error),
	meta Meta,
	args A,
	opts ...O,
) *ComponentWithMeta[R]

NewPulumiComponentWithMeta is a generic function that takes a pulumi "New" function, and all its parameters and returns a component

func (*ComponentWithMeta[T]) Apply

func (c *ComponentWithMeta[T]) Apply(ctx *pulumi.Context) error

Apply takes a pulumi context, gets the internal component and return error if any. The internal component is discarded. Can be called multiple times, because it is cached and the component is created only once

func (*ComponentWithMeta[T]) GetAndThen

func (c *ComponentWithMeta[T]) GetAndThen(ctx *pulumi.Context, fn func(*GetComponentWithMetaResponse[T]) error) error

GetAndThen takes a pulumi context and a function that takes a generic item, gets the internal component and apply the received function with its internal component Can be called multiple times, because it is cached and the component is created only once

type GetComponentResponse

type GetComponentResponse[T any] struct {
	Name      string
	Component T
}

GetComponentResponse collect the name and the object of created infrastructure components

func ExportURN

ExportURN exports the URN of pulumi Resource

type GetComponentWithMetaResponse

type GetComponentWithMetaResponse[T any] struct {
	*Meta
	*GetComponentResponse[T]
}

GetComponentWithMetaResponse collect the name and the object of created infrastructure components

type Meta

type Meta struct {
	Inactive bool
	Name     string
	Tags     map[string]string
	Protect  bool
}

Meta Provides more information to the component

func (*Meta) FullName

func (m *Meta) FullName() string

FullName is a composition of the NamePrefix and the Name

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

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