Documentation
¶
Overview ¶
Package iac extracts resource definitions from Infrastructure-as-Code sources (Pulumi TypeScript, Terraform HCL) and provisions them in CloudMock.
This enables CloudMock to auto-provision DynamoDB tables, API Gateway routes, and other resources directly from IaC source code — no seed scripts needed.
Index ¶
- func DetectIaCType(dir string) string
- func FindSAMTemplate(dir string) string
- func ImportCDKDir(dir string, environment string, logger *slog.Logger) (*IaCImportResult, *DependencyGraph, error)
- func ImportDir(dir string, environment string, logger *slog.Logger) (*IaCImportResult, *DependencyGraph, error)
- func ImportSAMTemplate(path string, environment string, logger *slog.Logger) (*IaCImportResult, *DependencyGraph, error)
- func ImportTerraformDir(dir string, environment string, logger *slog.Logger) (*IaCImportResult, *DependencyGraph, error)
- func IsSAMTemplate(path string) bool
- func ProvisionAPIGateways(apis []APIGatewayDef, apigwSvc service.Service, logger *slog.Logger)
- func ProvisionCognitoPools(pools []CognitoDef, cognitoSvc service.Service, logger *slog.Logger)
- func ProvisionDynamoTables(tables []DynamoTableDef, dynamoSvc service.Service, logger *slog.Logger) error
- func ProvisionLambdas(lambdas []LambdaDef, lambdaSvc service.Service, accountID, region string, ...)
- func ProvisionS3Buckets(buckets []S3BucketDef, s3Svc service.Service, logger *slog.Logger)
- func ProvisionSNSTopics(topics []SNSTopicDef, snsSvc service.Service, logger *slog.Logger)
- func ProvisionSQSQueues(queues []SQSQueueDef, sqsSvc service.Service, logger *slog.Logger)
- func SetMicroserviceClasses(classes []string)
- type APIGatewayDef
- type AttributeDef
- type CognitoDef
- type DependencyEdge
- type DependencyGraph
- type DependencyNode
- type DiffEntry
- type DiffResult
- type DiffStatus
- type DiffSummary
- type DynamoTableDef
- type GSIDef
- type IaCImportResult
- type LSIDef
- type LambdaDef
- type MicroserviceDef
- type MicroserviceRoute
- type Reconciler
- type S3BucketDef
- type SNSTopicDef
- type SQSQueueDef
- type Watcher
- type WatcherOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectIaCType ¶
DetectIaCType returns "terraform", "pulumi", "sam", "cdk", or "" based on the files present in the given directory.
func FindSAMTemplate ¶
FindSAMTemplate searches a directory for a SAM/CloudFormation template file.
func ImportCDKDir ¶
func ImportCDKDir(dir string, environment string, logger *slog.Logger) (*IaCImportResult, *DependencyGraph, error)
ImportCDKDir scans a CDK project directory for TypeScript files containing AWS CDK construct instantiations (new dynamodb.Table, new lambda.Function, etc.) and extracts resource definitions + a dependency graph.
CDK patterns detected:
new dynamodb.Table(this, 'Id', { tableName: '...', partitionKey: { name: 'pk', type: ... } })
new lambda.Function(this, 'Id', { functionName: '...', runtime: ... })
new sqs.Queue(this, 'Id', { queueName: '...' })
new sns.Topic(this, 'Id', { topicName: '...' })
new s3.Bucket(this, 'Id', { bucketName: '...' })
func ImportDir ¶
func ImportDir(dir string, environment string, logger *slog.Logger) (*IaCImportResult, *DependencyGraph, error)
ImportDir auto-detects the IaC type and imports resources.
func ImportSAMTemplate ¶
func ImportSAMTemplate(path string, environment string, logger *slog.Logger) (*IaCImportResult, *DependencyGraph, error)
ImportSAMTemplate parses a SAM/CloudFormation template.yaml and extracts resource definitions into an IaCImportResult + DependencyGraph.
Supported resource types:
AWS::DynamoDB::Table AWS::Serverless::Function / AWS::Lambda::Function AWS::SQS::Queue AWS::SNS::Topic AWS::S3::Bucket AWS::Serverless::Api
func ImportTerraformDir ¶
func ImportTerraformDir(dir string, environment string, logger *slog.Logger) (*IaCImportResult, *DependencyGraph, error)
ImportTerraformDir scans a Terraform project directory for .tf files and extracts resource definitions into an IaCImportResult. It also builds a DependencyGraph from explicit depends_on and implicit reference patterns.
func IsSAMTemplate ¶
IsSAMTemplate checks if a file looks like a SAM or CloudFormation template.
func ProvisionAPIGateways ¶
func ProvisionAPIGateways(apis []APIGatewayDef, apigwSvc service.Service, logger *slog.Logger)
ProvisionAPIGateways creates API Gateway REST APIs in CloudMock.
func ProvisionCognitoPools ¶
func ProvisionCognitoPools(pools []CognitoDef, cognitoSvc service.Service, logger *slog.Logger)
ProvisionCognitoPools creates Cognito User Pools in CloudMock.
func ProvisionDynamoTables ¶
func ProvisionDynamoTables(tables []DynamoTableDef, dynamoSvc service.Service, logger *slog.Logger) error
ProvisionDynamoTables creates the parsed tables in CloudMock via its DynamoDB service.
func ProvisionLambdas ¶
func ProvisionLambdas(lambdas []LambdaDef, lambdaSvc service.Service, accountID, region string, logger *slog.Logger)
ProvisionLambdas creates Lambda functions in CloudMock.
func ProvisionS3Buckets ¶
func ProvisionS3Buckets(buckets []S3BucketDef, s3Svc service.Service, logger *slog.Logger)
ProvisionS3Buckets creates S3 buckets in CloudMock.
func ProvisionSNSTopics ¶
func ProvisionSNSTopics(topics []SNSTopicDef, snsSvc service.Service, logger *slog.Logger)
ProvisionSNSTopics creates SNS topics in CloudMock.
func ProvisionSQSQueues ¶
func ProvisionSQSQueues(queues []SQSQueueDef, sqsSvc service.Service, logger *slog.Logger)
ProvisionSQSQueues creates SQS queues in CloudMock.
func SetMicroserviceClasses ¶
func SetMicroserviceClasses(classes []string)
SetMicroserviceClasses configures which `new <Class>(...)` TypeScript invocations parseLambdaEndpoints should treat as microservice definitions. Pass nil or [] to disable microservice extraction. Safe to call once at startup.
Types ¶
type APIGatewayDef ¶
type APIGatewayDef struct {
Name string `json:"name"`
}
APIGatewayDef holds a parsed API Gateway definition.
type AttributeDef ¶
type CognitoDef ¶
type CognitoDef struct {
Name string `json:"name"`
}
CognitoDef holds a parsed Cognito User Pool definition.
type DependencyEdge ¶
type DependencyEdge struct {
Source string `json:"source"`
Target string `json:"target"`
Type string `json:"type"` // "parent", "dependsOn", "reference"
}
DependencyEdge represents a dependency between two IaC resources.
type DependencyGraph ¶
type DependencyGraph struct {
Nodes []DependencyNode `json:"nodes"`
Edges []DependencyEdge `json:"dependencyEdges"`
}
DependencyGraph holds the full IaC resource graph.
func ExtractDependencyGraph ¶
func ExtractDependencyGraph(src string, env string) *DependencyGraph
ExtractDependencyGraph parses Pulumi TypeScript source and returns a DependencyGraph with module nodes (ComponentResource classes) and resource nodes (aws.* constructors), plus parent and dependsOn edges.
func ExtractDependencyGraphFromDir ¶
func ExtractDependencyGraphFromDir(dir string, environment string) *DependencyGraph
ExtractDependencyGraphFromDir scans a Pulumi project directory and builds a DependencyGraph.
func NewDependencyGraph ¶
func NewDependencyGraph() *DependencyGraph
NewDependencyGraph creates an empty dependency graph.
func ParseStackState ¶
func ParseStackState(data []byte) (*DependencyGraph, error)
ParseStackState parses the JSON output of `pulumi stack export` into a DependencyGraph.
URN format: urn:pulumi:STACK::PROJECT::TYPE::NAME TYPE examples:
- pulumi:pulumi:Stack → type="stack", service=""
- aws:dynamodb/table:Table → service="dynamodb", type="table"
- app:modules:Tables → type="module", service="" (no aws: prefix)
func (*DependencyGraph) AddEdge ¶
func (g *DependencyGraph) AddEdge(e DependencyEdge)
AddEdge adds a dependency edge to the graph.
func (*DependencyGraph) AddNode ¶
func (g *DependencyGraph) AddNode(n DependencyNode)
AddNode adds a resource node to the graph.
func (*DependencyGraph) Hierarchy ¶
func (g *DependencyGraph) Hierarchy() map[string][]string
Hierarchy returns a map of parent ID → child IDs, derived from node Parent fields.
type DependencyNode ¶
type DependencyNode struct {
ID string `json:"id"`
Label string `json:"label"`
Type string `json:"type"` // "table", "function", "queue", "topic", "bucket", "module"
Service string `json:"service"` // AWS service name
Parent string `json:"parent"` // parent node ID (ComponentResource)
URN string `json:"urn,omitempty"`
}
DependencyNode represents a single IaC resource in the dependency graph.
type DiffEntry ¶
type DiffEntry struct {
Service string `json:"service"` // AWS service (dynamodb, lambda, sqs, etc.)
Name string `json:"name"` // Resource name
Type string `json:"type"` // Resource type (table, function, queue, etc.)
Status DiffStatus `json:"status"` // missing, orphaned, drift, synced
Details string `json:"details,omitempty"` // Human-readable drift description
}
DiffEntry describes one resource's comparison result.
type DiffResult ¶
type DiffResult struct {
Entries []DiffEntry `json:"entries"`
Summary DiffSummary `json:"summary"`
}
DiffResult holds the complete IaC-vs-runtime comparison.
func ComputeDiff ¶
func ComputeDiff(iac *IaCImportResult, registry serviceRegistry, logger *slog.Logger) *DiffResult
ComputeDiff compares an IaC scan result against what's currently running in the CloudMock service registry.
type DiffStatus ¶
type DiffStatus string
DiffStatus indicates the state of a resource in the IaC vs runtime comparison.
const ( DiffMissing DiffStatus = "missing" // In IaC but not provisioned DiffOrphaned DiffStatus = "orphaned" // Provisioned but not in IaC DiffDrift DiffStatus = "drift" // Provisioned but config differs from IaC DiffSynced DiffStatus = "synced" // Provisioned and matches IaC )
type DiffSummary ¶
type DiffSummary struct {
Total int `json:"total"`
Synced int `json:"synced"`
Missing int `json:"missing"`
Orphaned int `json:"orphaned"`
Drift int `json:"drift"`
}
DiffSummary counts resources by status.
type DynamoTableDef ¶
type DynamoTableDef struct {
Name string `json:"name"`
HashKey string `json:"hashKey"`
RangeKey string `json:"rangeKey,omitempty"`
Attributes []AttributeDef `json:"attributes"`
GSIs []GSIDef `json:"globalSecondaryIndexes,omitempty"`
LSIs []LSIDef `json:"localSecondaryIndexes,omitempty"`
StreamEnabled bool `json:"streamEnabled,omitempty"`
TTLAttribute string `json:"ttlAttribute,omitempty"`
}
DynamoTableDef holds a parsed DynamoDB table definition from IaC source.
type IaCImportResult ¶
type IaCImportResult struct {
Tables []DynamoTableDef `json:"tables"`
Lambdas []LambdaDef `json:"lambdas"`
CognitoPools []CognitoDef `json:"cognito_pools"`
SQSQueues []SQSQueueDef `json:"sqs_queues"`
SNSTopics []SNSTopicDef `json:"sns_topics"`
S3Buckets []S3BucketDef `json:"s3_buckets"`
APIGateways []APIGatewayDef `json:"api_gateways"`
Microservices []MicroserviceDef `json:"microservices"`
}
IaCImportResult holds all resources extracted from IaC source.
func ImportPulumiDir ¶
ImportPulumiDir scans a Pulumi project directory for resource definitions. It looks for TypeScript files containing aws.dynamodb.Table constructors and extracts the table schemas.
type LambdaDef ¶
type LambdaDef struct {
Name string `json:"name"`
Runtime string `json:"runtime"`
Handler string `json:"handler"`
Timeout int `json:"timeout"`
Memory int `json:"memory"`
}
LambdaDef holds a parsed Lambda function definition.
type MicroserviceDef ¶
type MicroserviceDef struct {
Name string `json:"name"`
Routes []MicroserviceRoute `json:"routes"`
Tables []string `json:"tables,omitempty"` // DynamoDB tables this service accesses
}
MicroserviceDef holds a parsed Lambda-backed microservice with its API routes.
type MicroserviceRoute ¶
MicroserviceRoute is an API route (method + path).
type Reconciler ¶
type Reconciler struct {
// contains filtered or unexported fields
}
Reconciler compares a new IaC scan result against what's currently provisioned in CloudMock services and adds/removes resources to match the IaC source of truth.
func NewReconciler ¶
func NewReconciler(registry serviceRegistry, logger *slog.Logger) *Reconciler
NewReconciler creates a reconciler that syncs IaC state into CloudMock services.
func (*Reconciler) Reconcile ¶
func (r *Reconciler) Reconcile(result *IaCImportResult)
Reconcile provisions new resources and removes stale ones based on the IaC scan.
type S3BucketDef ¶
type S3BucketDef struct {
Name string `json:"name"`
}
S3BucketDef holds a parsed S3 bucket definition.
type SNSTopicDef ¶
type SNSTopicDef struct {
Name string `json:"name"`
}
SNSTopicDef holds a parsed SNS topic definition.
type SQSQueueDef ¶
type SQSQueueDef struct {
Name string `json:"name"`
}
SQSQueueDef holds a parsed SQS queue definition.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher monitors an IaC project directory for file changes and triggers re-scans. It debounces rapid changes (e.g. editor save + format) into a single callback invocation.
func NewWatcher ¶
func NewWatcher(dir, env string, logger *slog.Logger, onChange func(*IaCImportResult), opts ...WatcherOption) (*Watcher, error)
NewWatcher creates a file watcher that re-scans the IaC directory on changes. The onChange callback receives the new IaCImportResult each time files change.
type WatcherOption ¶
type WatcherOption func(*Watcher)
WatcherOption configures a Watcher.
func WithDebounce ¶
func WithDebounce(d time.Duration) WatcherOption
WithDebounce sets the debounce interval (default 500ms).