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 ¶
- Variables
- func AzureSubscription(ctx context.Context, given string) (string, error)
- func LooksPersonal(id string) bool
- func ResourceName(name string) string
- func WriteImports(w io.Writer, header string, resources []Resource) ([]string, error)
- type ARN
- type AWSClients
- type AWSOptions
- type AzureLister
- type AzureResource
- type CloudControlAPI
- type Resource
- func MapARN(s string) (r Resource, ok bool, reason string)
- func MapAzure(id, resourceType, name, kind string) (r Resource, ok bool, reason string)
- func MapCloudControl(t cloudControlType, region, account, identifier, name string) (r Resource, matchName string, ok bool, reason string)
- func ResourceGroup(subscription, name string) Resource
- type Result
- type Skipped
- type TaggingAPI
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
LooksPersonal reports whether an ID contains something personal, such as an email address.
func ResourceName ¶
ResourceName turns an object's name into a valid, readable resource name.
Types ¶
type ARN ¶
type ARN struct {
Partition, Service, Region, Account, Resource string
}
ARN is a parsed Amazon Resource Name.
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 ¶
MapARN maps an ARN to the resource that manages it. ok is false if adopt doesn't support it, with the reason.
func MapAzure ¶
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 ¶
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 ¶
DiscoverAzure finds the resources in a resource group, and the group itself.
type TaggingAPI ¶
type TaggingAPI interface {
GetResources(context.Context, *resourcegroupstaggingapi.GetResourcesInput, ...func(*resourcegroupstaggingapi.Options)) (*resourcegroupstaggingapi.GetResourcesOutput, error)
}
TaggingAPI is the part of the Resource Groups Tagging API that adopt uses.