importer

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MPL-2.0 Imports: 28 Imported by: 0

README

Polytomic Importer

The Polytomic Terraform Importer generates Terraform HCL documents which reflect the current in-app Polytomic configuration. This makes it suitable for generating a backup of Polytomic configuration and determining what's changed.

Installation

Download the appropriate binary for you architecture from the Releases page.

Usage

With API Key (single organization)
./polytomic-importer run --api-key $POLYTOMIC_API_KEY --output terraform-imports --replace
With Partner Key (multiple organizations)
./polytomic-importer run \
  --partner-key $POLYTOMIC_PARTNER_KEY \
  --organizations "org-id-1,org-id-2" \
  --output terraform-imports \
  --replace
With Deployment Key (multiple organizations)
./polytomic-importer run \
  --deployment-key $POLYTOMIC_DEPLOYMENT_KEY \
  --organizations "org-id-1,org-id-2" \
  --output terraform-imports \
  --replace
Options
  • --replace: Replace existing files (otherwise the command will fail if files exist)
  • --include-permissions: Include role and policy resources in the import

Authentication Options

The importer supports three authentication methods:

  1. API Key: For single organization access. The importer will automatically discover your organization.

  2. Partner Key: For multi-organization access.

    • --partner-key: Your Polytomic partner key
    • --organizations: Comma-separated list of organization IDs to import (optional)
  3. Deployment Key: For multi-organization access (same privileges as partner key).

    • --deployment-key: Your Polytomic deployment key
    • --organizations: Comma-separated list of organization IDs to import (optional)
Multi-Organization Mode

When using partner or deployment keys with multiple organizations:

  • If --organizations is not specified, the importer discovers all accessible organizations
  • With multiple organizations, each gets its own directory under the output path
  • The directory name is based on the organization name
  • Each directory contains its own set of .tf files and import.sh script
Organization Discovery

The importer automatically discovers organizations based on the authentication method:

  • API Key: Uses the organization associated with the API key
  • Partner/Deployment Key: Lists all accessible organizations, optionally filtered by --organizations

Automation

A Github Action, polytomic/terraform-sync, is available which allows the importer to be used in a Github Action workflow to automate updating the generated HCL files.

Documentation

Index

Constants

View Source
const (
	BulkSyncResourceFileName = "bulk_syncs.tf"
	BulkSyncResource         = "polytomic_bulk_sync"
)
View Source
const (
	GlobalErrorSubscribersResourceFileName = "global_error_subscribers.tf"
	GlobalErrorSubscribersResourceType     = "polytomic_global_error_subscribers"
)
View Source
const (
	UserAgent      = "polytomic-terraform-provider/importer"
	ImportFileName = "import.sh"
)
View Source
const (
	ModelsResourceFileName = "models.tf"
	ModelResource          = "polytomic_model"
)
View Source
const (
	PoliciesResourceFileName = "policies.tf"
	PolicyResource           = "polytomic_policy"
)
View Source
const (
	RolesResourceFileName = "roles.tf"
	RoleResource          = "polytomic_role"
)
View Source
const (
	SyncResourceFileName = "syncs.tf"
	SyncResource         = "polytomic_sync"
)
View Source
const (
	ConnectionsResourceFileName = "connections.tf"
)

Variables

This section is empty.

Functions

func Init

func Init(ctx context.Context, clientProvider *providerclient.Provider, organizations, outputPath string, recreate, includePermissions bool)

func ReplaceRefs added in v0.3.19

func ReplaceRefs(b []byte, refs map[string]string) []byte

ReplaceRefs takes in an array of bytes and a map of references It will parse the array of bytes and replace any reference byte sequences with the value from the map.

Types

type BulkSyncs

type BulkSyncs struct {
	Resources map[string]*polytomic.BulkSyncResponse
	// contains filtered or unexported fields
}

func NewBulkSyncs

func NewBulkSyncs(c *ptclient.Client) *BulkSyncs

func (*BulkSyncs) DatasourceRefs added in v0.3.19

func (b *BulkSyncs) DatasourceRefs() map[string]string

func (*BulkSyncs) Filename

func (b *BulkSyncs) Filename() string

func (*BulkSyncs) GenerateImports

func (b *BulkSyncs) GenerateImports(ctx context.Context, writer io.Writer) error

func (*BulkSyncs) GenerateTerraformFiles

func (b *BulkSyncs) GenerateTerraformFiles(ctx context.Context, writer io.Writer, refs map[string]string) error

func (*BulkSyncs) Init

func (b *BulkSyncs) Init(ctx context.Context) error

func (*BulkSyncs) ResourceRefs added in v0.3.19

func (b *BulkSyncs) ResourceRefs() map[string]string

func (*BulkSyncs) Variables added in v0.3.33

func (b *BulkSyncs) Variables() []Variable

type Connection

type Connection struct {
	ID            *string
	Type          *string
	Resource      string
	Name          *string
	Organization  *string
	Configuration interface{}
}

type Connections

type Connections struct {
	Resources   map[string]Connection
	Datasources map[string]Connection
	// contains filtered or unexported fields
}

func NewConnections

func NewConnections(c *ptclient.Client) *Connections

func (*Connections) DatasourceRefs added in v0.3.19

func (c *Connections) DatasourceRefs() map[string]string

func (*Connections) Filename

func (c *Connections) Filename() string

func (*Connections) GenerateImports

func (c *Connections) GenerateImports(ctx context.Context, writer io.Writer) error

func (*Connections) GenerateTerraformFiles

func (c *Connections) GenerateTerraformFiles(ctx context.Context, writer io.Writer, refs map[string]string) error

func (*Connections) Init

func (c *Connections) Init(ctx context.Context) error

func (*Connections) ResourceRefs added in v0.3.19

func (c *Connections) ResourceRefs() map[string]string

func (*Connections) Variables added in v0.3.33

func (c *Connections) Variables() []Variable

type GlobalErrorSubscribers added in v1.3.0

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

func NewGlobalErrorSubscribers added in v1.3.0

func NewGlobalErrorSubscribers(c *ptclient.Client) *GlobalErrorSubscribers

func (*GlobalErrorSubscribers) DatasourceRefs added in v1.3.0

func (g *GlobalErrorSubscribers) DatasourceRefs() map[string]string

func (*GlobalErrorSubscribers) Filename added in v1.3.0

func (g *GlobalErrorSubscribers) Filename() string

func (*GlobalErrorSubscribers) GenerateImports added in v1.3.0

func (g *GlobalErrorSubscribers) GenerateImports(ctx context.Context, writer io.Writer) error

func (*GlobalErrorSubscribers) GenerateTerraformFiles added in v1.3.0

func (g *GlobalErrorSubscribers) GenerateTerraformFiles(ctx context.Context, writer io.Writer, refs map[string]string) error

func (*GlobalErrorSubscribers) Init added in v1.3.0

func (*GlobalErrorSubscribers) ResourceRefs added in v1.3.0

func (g *GlobalErrorSubscribers) ResourceRefs() map[string]string

func (*GlobalErrorSubscribers) Variables added in v1.3.0

func (g *GlobalErrorSubscribers) Variables() []Variable

type Importable

type Importable interface {
	Init(ctx context.Context) error
	ResourceRefs() map[string]string
	DatasourceRefs() map[string]string
	GenerateTerraformFiles(ctx context.Context, writer io.Writer, refs map[string]string) error
	GenerateImports(ctx context.Context, writer io.Writer) error
	Filename() string
	Variables() []Variable
}

type Main

type Main struct {
	OrgResource bool
	ID          string
	Slug        string
	Name        string
}

func NewMain

func NewMain(org *polytomic.Organization, orgResource bool) *Main

func (*Main) DatasourceRefs added in v0.3.19

func (m *Main) DatasourceRefs() map[string]string

func (*Main) Filename

func (m *Main) Filename() string

func (*Main) GenerateImports

func (m *Main) GenerateImports(ctx context.Context, writer io.Writer) error

func (*Main) GenerateTerraformFiles

func (m *Main) GenerateTerraformFiles(ctx context.Context, writer io.Writer, refs map[string]string) error

func (*Main) Init

func (m *Main) Init(ctx context.Context) error

func (*Main) ResourceRefs added in v0.3.19

func (m *Main) ResourceRefs() map[string]string

func (*Main) Variables added in v0.3.33

func (m *Main) Variables() []Variable

type Models

type Models struct {
	Resources map[string]*polytomic.ModelResponse
	// contains filtered or unexported fields
}

func NewModels

func NewModels(c *ptclient.Client) *Models

func (*Models) DatasourceRefs added in v0.3.19

func (m *Models) DatasourceRefs() map[string]string

func (*Models) Filename

func (m *Models) Filename() string

func (*Models) GenerateImports

func (m *Models) GenerateImports(ctx context.Context, writer io.Writer) error

func (*Models) GenerateTerraformFiles

func (m *Models) GenerateTerraformFiles(ctx context.Context, writer io.Writer, refs map[string]string) error

func (*Models) Init

func (m *Models) Init(ctx context.Context) error

func (*Models) ResourceRefs added in v0.3.19

func (m *Models) ResourceRefs() map[string]string

func (*Models) Variables added in v0.3.33

func (m *Models) Variables() []Variable

type Policies added in v0.3.13

type Policies struct {
	Resources map[string]*polytomic.PolicyResponse
	// contains filtered or unexported fields
}

func NewPolicies added in v0.3.13

func NewPolicies(c *ptclient.Client) *Policies

func (*Policies) DatasourceRefs added in v0.3.19

func (p *Policies) DatasourceRefs() map[string]string

func (*Policies) Filename added in v0.3.13

func (p *Policies) Filename() string

func (*Policies) GenerateImports added in v0.3.13

func (p *Policies) GenerateImports(ctx context.Context, writer io.Writer) error

func (*Policies) GenerateTerraformFiles added in v0.3.13

func (p *Policies) GenerateTerraformFiles(ctx context.Context, writer io.Writer, refs map[string]string) error

func (*Policies) Init added in v0.3.13

func (p *Policies) Init(ctx context.Context) error

func (*Policies) ResourceRefs added in v0.3.19

func (p *Policies) ResourceRefs() map[string]string

func (*Policies) Variables added in v0.3.33

func (p *Policies) Variables() []Variable

type Roles added in v0.3.13

type Roles struct {
	Resources map[string]*polytomic.RoleResponse
	// contains filtered or unexported fields
}

func NewRoles added in v0.3.13

func NewRoles(c *ptclient.Client) *Roles

func (*Roles) DatasourceRefs added in v0.3.19

func (r *Roles) DatasourceRefs() map[string]string

func (*Roles) Filename added in v0.3.13

func (r *Roles) Filename() string

func (*Roles) GenerateImports added in v0.3.13

func (r *Roles) GenerateImports(ctx context.Context, writer io.Writer) error

func (*Roles) GenerateTerraformFiles added in v0.3.13

func (r *Roles) GenerateTerraformFiles(ctx context.Context, writer io.Writer, refs map[string]string) error

func (*Roles) Init added in v0.3.13

func (r *Roles) Init(ctx context.Context) error

func (*Roles) ResourceRefs added in v0.3.19

func (r *Roles) ResourceRefs() map[string]string

func (*Roles) Variables added in v0.3.33

func (r *Roles) Variables() []Variable

type SchemaValidator added in v1.1.0

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

SchemaValidator validates that field mappings match a provider resource schema

func NewSchemaValidator added in v1.1.0

func NewSchemaValidator(ctx context.Context, res resource.Resource) (*SchemaValidator, error)

NewSchemaValidator creates a validator from a provider resource

func (*SchemaValidator) ValidateMapping added in v1.1.0

func (v *SchemaValidator) ValidateMapping(mapping map[string]interface{}) error

ValidateMapping validates that a field mapping matches the schema structure mapping is a nested map[string]interface{} representing the HCL structure Returns an error if any field paths don't exist in the schema

type Syncs

type Syncs struct {
	Resources map[string]*polytomic.ModelSyncResponse
	// contains filtered or unexported fields
}

func NewSyncs

func NewSyncs(c *ptclient.Client) *Syncs

func (*Syncs) DatasourceRefs added in v0.3.19

func (s *Syncs) DatasourceRefs() map[string]string

func (*Syncs) Filename

func (s *Syncs) Filename() string

func (*Syncs) GenerateImports

func (s *Syncs) GenerateImports(ctx context.Context, writer io.Writer) error

func (*Syncs) GenerateTerraformFiles

func (s *Syncs) GenerateTerraformFiles(ctx context.Context, writer io.Writer, refs map[string]string) error

func (*Syncs) Init

func (s *Syncs) Init(ctx context.Context) error

func (*Syncs) ResourceRefs added in v0.3.19

func (s *Syncs) ResourceRefs() map[string]string

func (*Syncs) Variables added in v0.3.33

func (s *Syncs) Variables() []Variable

type Variable added in v0.3.33

type Variable struct {
	Name      string
	Default   any
	Type      string
	Sensitive bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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