provider

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: MIT Imports: 36 Imported by: 0

Documentation

Overview

Package provider provides the core interfaces of Terracognita by defining the Provider and Resource and also the main function named Impoort

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Import

func Import(ctx context.Context, p Provider, hcl, tfstate writer.Writer, f *filter.Filter, out io.Writer) error

Import imports from the Provider p all the resources filtered by f and writes the result to the hcl or tfstate if those are not nil

Types

type GRPCClient added in v0.7.0

type GRPCClient struct {
	// contains filtered or unexported fields
}

GRPCClient is an inmemory implementation of the TF GRPC This should implement the terraform/providers.Interface but TF is still on zclconf/go-cty and we need hashicorp/go-cty so it compiles

func NewGRPCClient added in v0.7.0

func NewGRPCClient(pv *schema.Provider) *GRPCClient

NewGRPCClient wraps the pv into a GRPCClient

func (*GRPCClient) ImportResourceState added in v0.7.0

func (c *GRPCClient) ImportResourceState(r ImportResourceStateRequest) (resp ImportResourceStateResponse)

ImportResourceState imports the state of the resource from the Provider

func (*GRPCClient) ReadResource added in v0.7.0

func (c *GRPCClient) ReadResource(r ReadResourceRequest) (resp ReadResourceResponse)

ReadResource reads the Resource from the Provider

type ImportResourceStateRequest added in v0.7.0

type ImportResourceStateRequest struct {
	// TypeName is the name of the resource type to be imported.
	TypeName string

	// ID is a string with which the provider can identify the resource to be
	// imported.
	ID string
}

ImportResourceStateRequest is the request sent to Import the Resource State copied from terraform/providers.ImportResourceStateRequest

type ImportResourceStateResponse added in v0.7.0

type ImportResourceStateResponse struct {
	// ImportedResources contains one or more state values related to the
	// imported resource. It is not required that these be complete, only that
	// there is enough identifying information for the provider to successfully
	// update the states in ReadResource.
	ImportedResources []ImportedResource

	// Diagnostics contains any warnings or errors from the method call.
	Diagnostics tfdiags.Diagnostics
}

ImportResourceStateResponse is the response from Importing the Resource State copied from terraform/providers.ImportResourceStateResponse

type ImportedResource added in v0.7.0

type ImportedResource struct {
	// TypeName is the name of the resource type associated with the
	// returned state. It's possible for providers to import multiple related
	// types with a single import request.
	TypeName string

	// State is the state of the remote object being imported. This may not be
	// complete, but must contain enough information to uniquely identify the
	// resource.
	State cty.Value

	// Private is an opaque blob that will be stored in state along with the
	// resource. It is intended only for interpretation by the provider itself.
	Private []byte
}

ImportedResource is the resource information to Import copied from terraform/providers.ImportedResource

type Provider

type Provider interface {
	// Region returns the actual region in which the
	// provider is based
	Region() string

	// ResourceTypes returns all the resource types from
	// the Provider
	ResourceTypes() []string

	// HasResourceType validates if the string t is a valid
	// resource type for this provider
	HasResourceType(t string) bool

	// Resources returns all the Resources of the resourceType
	// on the cloud provider
	Resources(ctx context.Context, resourceType string, f *filter.Filter) ([]Resource, error)

	// TFClient returns the Terraform client which may change
	// on the provider
	TFClient() interface{}

	// TFProvider returns the Terraform provider
	TFProvider() *schema.Provider

	// String returns the string representation of the Provider
	// which is the shorted version (Amazon Web Services = aws)
	String() string

	// TagKey returns the different name used to identify
	// tags on the cloud provider
	TagKey() string

	// Source is the source of the Provider used
	// to declare on the HCL
	Source() string

	// Configuration returns the Provider configuration
	// that may be interpolated with HCL when declaring
	// the provider. The keys have to be the Provider
	// attributes as defined on the TF Schema
	Configuration() map[string]interface{}

	// FixResource will try to fix some attributes that we know are wrong
	// and that we do not want to write or change the value they have
	// depending on other conditions.
	// This could also be issues that the Providers have and may not fix
	FixResource(t string, v cty.Value) (cty.Value, error)

	// FilterByTags will check the tags for autogenerated provider tags
	// that identify generated resources that should not be imported
	// like instances in autoscaling
	FilterByTags(tags interface{}) error
}

Provider is the general interface used to abstract a cloud provider from Terraform

type ReadResourceRequest added in v0.7.0

type ReadResourceRequest struct {
	// TypeName is the name of the resource type being read.
	TypeName string

	// PriorState contains the previously saved state value for this resource.
	PriorState cty.Value

	// Private is an opaque blob that will be stored in state along with the
	// resource. It is intended only for interpretation by the provider itself.
	Private []byte

	// ProviderMeta is the configuration for the provider_meta block for the
	// module and provider this resource belongs to. Its use is defined by
	// each provider, and it should not be used without coordination with
	// HashiCorp. It is considered experimental and subject to change.
	ProviderMeta cty.Value
}

ReadResourceRequest is the request sent to Read the Resource copied from terraform/providers.ReadResourceRequest

type ReadResourceResponse added in v0.7.0

type ReadResourceResponse struct {
	// NewState contains the current state of the resource.
	NewState cty.Value

	// Diagnostics contains any warnings or errors from the method call.
	Diagnostics tfdiags.Diagnostics

	// Private is an opaque blob that will be stored in state along with the
	// resource. It is intended only for interpretation by the provider itself.
	Private []byte
}

ReadResourceResponse is the response from Reading the Resource copied from terraform/providers.ReadResourceResponse

type Resource

type Resource interface {
	// ID is the ID of the Resource
	ID() string

	// Type is the type of resource (ex: aws_instance)
	Type() string

	// InstanceState is the Terraform state of the resource
	// it contains important elements like `Attributes`
	InstanceState() *terraform.InstanceState

	// Name is the resource name given by Terracognita
	Name() string

	// TFResource is the definition of that resource
	TFResource() *schema.Resource

	// SetImporter set schema.Resource.Importer
	// It defines the ResourceImporter implementation for this resource
	SetImporter(*schema.ResourceImporter)

	// Data is the actual data of the Resource
	Data() *schema.ResourceData

	// Provider is the Provider of that Resource
	Provider() Provider

	// ImportState imports the Resource state
	// to the Resource and could return []Resource if
	// it imported more than one state, this list does not
	// include the actual Resource on parameters, so if
	// len([]Resource) == 0 means only the Resource is imported
	ImportState() ([]Resource, error)

	// Read read the remote information of the Resource to the
	// state and calculates the ResourceInstanceObject
	Read(f *filter.Filter) error

	// State calculates the state of the Resource and
	// writes it to w
	State(w writer.Writer) error

	// HCL returns the HCL configuration of the Resource and
	// writes it to HCL
	HCL(w writer.Writer) error

	// InstanceInfo returns the InstanceInfo of this Resource
	InstanceInfo() *terraform.InstanceInfo

	// ImpliedType returns the cty.Type of the
	// Resource
	ImpliedType() cty.Type

	// ResourceInstanceObject is the calculated states.ResourceInstanceObject
	// after 'Read' has been called
	ResourceInstanceObject() *states.ResourceInstanceObject

	// AttributesReference return the list of possible value
	// to be interpolated with the resource
	AttributesReference() ([]string, error)

	// SetIgnoreTagFilter is to mark the resource as already filtered, so we do not try
	// to filter it again when reading it.
	// This is mostly used in case the API does not support filtering and we have to
	// do it manually
	SetIgnoreTagFilter(b bool)
}

Resource represents the minimal information needed to define a Provider resource

func NewResource

func NewResource(id, rt string, p Provider) Resource

NewResource returns an implementation of the Resource

Jump to

Keyboard shortcuts

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