adopt

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MPL-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package adopt finds existing cloud resources and writes import blocks for them, so that a configuration can take over infrastructure that was created some other way.

Index

Constants

This section is empty.

Variables

View Source
var CloudControlTypes = []cloudControlType{
	{Name: "AWS::S3::Bucket", Global: true, /* contains filtered or unexported fields */},
	{Name: "AWS::Lambda::Function", /* contains filtered or unexported fields */},
	{Name: "AWS::IAM::Role", Global: true, /* contains filtered or unexported fields */},
	{Name: "AWS::DynamoDB::Table", /* contains filtered or unexported fields */},
	{Name: "AWS::Logs::LogGroup", /* contains filtered or unexported fields */},
	{Name: "AWS::SQS::Queue", /* contains filtered or unexported fields */},
	{Name: "AWS::SNS::Topic", /* contains filtered or unexported fields */},
	{Name: "AWS::ECR::Repository", /* contains filtered or unexported fields */},
	{Name: "AWS::RDS::DBInstance", /* contains filtered or unexported fields */},
	{Name: "AWS::SecretsManager::Secret", /* contains filtered or unexported fields */},
	{Name: "AWS::SES::EmailIdentity", /* contains filtered or unexported fields */},
	{Name: "AWS::ApiGatewayV2::Api", /* contains filtered or unexported fields */},
	{Name: "AWS::Route53::HostedZone", Global: true, /* contains filtered or unexported fields */},
	{Name: "AWS::StepFunctions::StateMachine", /* contains filtered or unexported fields */},
}

CloudControlTypes are listed for -prefix. Types whose IDs are generated, such as VPCs, are only found with -tag.

Functions

func AzureSubscription

func AzureSubscription(ctx context.Context, given string) (string, error)

AzureSubscription finds the subscription to use: the given one, AZURE_SUBSCRIPTION_ID or ARM_SUBSCRIPTION_ID, or the Azure CLI's current subscription.

func LooksPersonal

func LooksPersonal(id string) bool

LooksPersonal reports whether an ID contains something personal, such as an email address.

func ResourceName

func ResourceName(name string) string

ResourceName turns an object's name into a valid, readable resource name.

func WriteImports

func WriteImports(w io.Writer, header string, resources []Resource) ([]string, error)

WriteImports writes one import block for each resource, sorted by type and name, with unique resource names. It returns the addresses it used, in the same order as written.

Types

type ARN

type ARN struct {
	Partition, Service, Region, Account, Resource string
}

ARN is a parsed Amazon Resource Name.

func ParseARN

func ParseARN(s string) (ARN, error)

ParseARN splits an ARN into its parts.

type AWSClients

type AWSClients struct {
	Region, Account     string
	Tagging, GlobalTags TaggingAPI
	Cloud, GlobalCloud  CloudControlAPI
}

AWSClients are the API clients for one region, and for us-east-1, where global services live.

func NewAWSClients

func NewAWSClients(ctx context.Context, region string) (*AWSClients, error)

NewAWSClients creates clients from the default credential chain.

type AWSOptions

type AWSOptions struct {
	// Region is the region to search. Global services are always searched in us-east-1.
	Region string
	// Tags select resources that have all of these tags. A "" value matches any value.
	Tags map[string]string
	// Prefix selects resources whose names start with it.
	Prefix string
}

AWSOptions selects which AWS resources to adopt.

type AzureLister

type AzureLister interface {
	// ResourceGroup returns the group's name as Azure stores it.
	ResourceGroup(ctx context.Context, name string) (string, error)
	Resources(ctx context.Context, group string) ([]AzureResource, error)
}

AzureLister lists a resource group and its resources.

func NewAzureLister

func NewAzureLister(subscription string) (AzureLister, error)

NewAzureLister signs in with the default credential chain, which includes the Azure CLI's login, environment variables and managed identities.

type AzureResource

type AzureResource struct {
	ID, Type, Name, Kind string
}

AzureResource is a resource as Azure lists it.

type CloudControlAPI

type CloudControlAPI interface {
	ListResources(context.Context, *cloudcontrol.ListResourcesInput, ...func(*cloudcontrol.Options)) (*cloudcontrol.ListResourcesOutput, error)
}

CloudControlAPI is the part of the Cloud Control API that adopt uses.

type Resource

type Resource struct {
	// Type is the resource type, such as aws_s3_bucket.
	Type string
	// ImportID is the ID that the provider's importer expects.
	ImportID string
	// Name is a readable name for the object, used to choose the resource's name in configuration.
	Name string
	// Source identifies the object in its cloud, such as an ARN or an Azure resource ID.
	Source string
	// Note is shown above the import block, for anything the user should check.
	Note string
}

Resource is an existing object, mapped to the Terraform resource that manages it.

func MapARN

func MapARN(s string) (r Resource, ok bool, reason string)

MapARN maps an ARN to the resource that manages it. ok is false if adopt doesn't support it, with the reason.

func MapAzure

func MapAzure(id, resourceType, name, kind string) (r Resource, ok bool, reason string)

MapAzure maps an Azure resource to the azurerm resource that manages it. The import ID is the resource ID, with its type segments in the casing azurerm expects.

func MapCloudControl

func MapCloudControl(t cloudControlType, region, account, identifier, name string) (r Resource, matchName string, ok bool, reason string)

MapCloudControl maps a Cloud Control identifier to a resource. name is the object's name from its properties, if the type has a name property. It returns the name that -prefix should match.

func ResourceGroup

func ResourceGroup(subscription, name string) Resource

ResourceGroup returns the import block for a resource group.

type Result

type Result struct {
	Resources []Resource
	Skipped   []Skipped
	// Warnings are problems that didn't stop discovery, such as a service that couldn't be listed.
	Warnings []string
}

Result is what discovery found.

func DiscoverAWS

func DiscoverAWS(ctx context.Context, c *AWSClients, opts AWSOptions) (*Result, error)

DiscoverAWS finds resources by tag, by name prefix, or both. With both, a resource must match both.

func DiscoverAzure

func DiscoverAzure(ctx context.Context, l AzureLister, subscription, group string) (*Result, error)

DiscoverAzure finds the resources in a resource group, and the group itself.

type Skipped

type Skipped struct {
	Source string
	Reason string
}

Skipped is an object that was found but has no import block.

type TaggingAPI

TaggingAPI is the part of the Resource Groups Tagging API that adopt uses.

Jump to

Keyboard shortcuts

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