provider

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2025 License: MPL-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SSHBastionAttr = rschema.SingleNestedAttribute{
	MarkdownDescription: "Bastion host configuration",
	Optional:            true,
	Attributes: map[string]rschema.Attribute{
		"host":        SSHConnectionSchema.Host,
		"port":        SSHConnectionSchema.Port,
		"user":        SSHConnectionSchema.User,
		"password":    SSHConnectionSchema.Password,
		"private_key": SSHConnectionSchema.PrivateKey,
	},
}
View Source
var SSHConnectionSchema = struct {
	Host                 rschema.StringAttribute
	User                 rschema.StringAttribute
	Password             rschema.StringAttribute
	PrivateKey           rschema.StringAttribute
	Port                 rschema.Int64Attribute
	UseProviderAsBastion rschema.BoolAttribute
	Bastion              rschema.SingleNestedAttribute
}{
	Host: rschema.StringAttribute{
		MarkdownDescription: "Override the provider's host configuration",
		Optional:            true,
	},
	User: rschema.StringAttribute{
		MarkdownDescription: "Override the provider's user configuration",
		Optional:            true,
	},
	Password: rschema.StringAttribute{
		MarkdownDescription: "Override the provider's password configuration",
		Optional:            true,
		Sensitive:           true,
	},
	PrivateKey: rschema.StringAttribute{
		MarkdownDescription: "Override the provider's private key configuration",
		Optional:            true,
		Sensitive:           true,
	},
	Port: rschema.Int64Attribute{
		MarkdownDescription: "The port number to connect to",
		Optional:            true,
	},
	UseProviderAsBastion: rschema.BoolAttribute{
		MarkdownDescription: "Use the provider's connection as a bastion host",
		Optional:            true,
	},
	Bastion: rschema.SingleNestedAttribute{
		MarkdownDescription: "Bastion host configuration",
		Optional:            true,
		Attributes: map[string]rschema.Attribute{
			"host": rschema.StringAttribute{
				MarkdownDescription: "The hostname or IP address of the bastion host",
				Required:            true,
			},
			"port": rschema.Int64Attribute{
				MarkdownDescription: "The port number of the bastion host",
				Optional:            true,
			},
			"user": rschema.StringAttribute{
				MarkdownDescription: "The username for bastion host authentication",
				Required:            true,
			},
			"password": rschema.StringAttribute{
				MarkdownDescription: "The password for bastion host authentication",
				Optional:            true,
				Sensitive:           true,
			},
			"private_key": rschema.StringAttribute{
				MarkdownDescription: "The private key for bastion host authentication",
				Optional:            true,
				Sensitive:           true,
			},
		},
	},
}
View Source
var SSHExecAttrs = struct {
	Command                   rschema.StringAttribute
	Output                    rschema.StringAttribute
	ExitCode                  rschema.Int64Attribute
	FailIfNonzero__Resource   rschema.BoolAttribute
	FailIfNonzero__DataSource rschema.BoolAttribute
	OnDestroy                 rschema.StringAttribute
	ID                        rschema.StringAttribute
}{
	Command: rschema.StringAttribute{
		MarkdownDescription: "Command to execute",
		Required:            true,
	},
	Output: rschema.StringAttribute{
		MarkdownDescription: "Output of the command",
		Computed:            true,
	},
	ExitCode: rschema.Int64Attribute{
		MarkdownDescription: "Exit code of the command",
		Computed:            true,
	},
	FailIfNonzero__Resource: rschema.BoolAttribute{
		MarkdownDescription: "Whether to fail if the command returns a non-zero exit code. Defaults to true if not specified.",
		Optional:            true,
		Computed:            true,
		Default:             booldefault.StaticBool(true),
	},
	FailIfNonzero__DataSource: rschema.BoolAttribute{
		MarkdownDescription: "Whether to fail if the command returns a non-zero exit code",
		Optional:            true,
	},
	OnDestroy: rschema.StringAttribute{
		MarkdownDescription: "Command to execute when the resource is destroyed",
		Optional:            true,
	},
	ID: rschema.StringAttribute{
		MarkdownDescription: "Unique identifier for this execution",
		Computed:            true,
	},
}
View Source
var SSHExecDataSourceSchema = dschema.Schema{
	MarkdownDescription: "Execute commands over SSH",
	Attributes: map[string]dschema.Attribute{
		"command":         SSHExecAttrs.Command,
		"output":          SSHExecAttrs.Output,
		"exit_code":       SSHExecAttrs.ExitCode,
		"fail_if_nonzero": SSHExecAttrs.FailIfNonzero__DataSource,
		"id":              SSHExecAttrs.ID,

		"host":                    SSHConnectionSchema.Host,
		"user":                    SSHConnectionSchema.User,
		"password":                SSHConnectionSchema.Password,
		"private_key":             SSHConnectionSchema.PrivateKey,
		"port":                    SSHConnectionSchema.Port,
		"use_provider_as_bastion": SSHConnectionSchema.UseProviderAsBastion,
		"bastion":                 SSHConnectionSchema.Bastion,
	},
}
View Source
var SSHExecResourceSchema = rschema.Schema{
	MarkdownDescription: "Execute commands over SSH with potential side effects",
	Attributes: map[string]rschema.Attribute{
		"command":         SSHExecAttrs.Command,
		"output":          SSHExecAttrs.Output,
		"exit_code":       SSHExecAttrs.ExitCode,
		"fail_if_nonzero": SSHExecAttrs.FailIfNonzero__Resource,
		"on_destroy":      SSHExecAttrs.OnDestroy,
		"id":              SSHExecAttrs.ID,

		"host":                    SSHConnectionSchema.Host,
		"user":                    SSHConnectionSchema.User,
		"password":                SSHConnectionSchema.Password,
		"private_key":             SSHConnectionSchema.PrivateKey,
		"port":                    SSHConnectionSchema.Port,
		"use_provider_as_bastion": SSHConnectionSchema.UseProviderAsBastion,
		"bastion":                 SSHConnectionSchema.Bastion,
	},
}
View Source
var SSHFileAttrs = struct {
	Path                rschema.StringAttribute
	Content__Resource   rschema.StringAttribute
	Content__DataSource rschema.StringAttribute
	Permissions         rschema.StringAttribute
	FailIfAbsent        rschema.BoolAttribute
	DeleteOnDestroy     rschema.BoolAttribute
	ID                  rschema.StringAttribute
}{
	Path: rschema.StringAttribute{
		MarkdownDescription: "Path to the file",
		Required:            true,
	},
	Content__Resource: rschema.StringAttribute{
		MarkdownDescription: "Content of the file",
		Required:            true,
	},
	Content__DataSource: rschema.StringAttribute{
		MarkdownDescription: "Content of the file",
		Computed:            true,
	},
	Permissions: rschema.StringAttribute{
		MarkdownDescription: "File permissions (e.g., '0644')",
		Optional:            true,
		Computed:            true,
		Default:             stringdefault.StaticString("0644"),
	},
	FailIfAbsent: rschema.BoolAttribute{
		MarkdownDescription: "Whether to fail if the file does not exist",
		Optional:            true,
	},
	DeleteOnDestroy: rschema.BoolAttribute{
		MarkdownDescription: "Whether to delete the file when the resource is destroyed. Defaults to true.",
		Optional:            true,
		Computed:            true,
		Default:             booldefault.StaticBool(true),
	},
	ID: rschema.StringAttribute{
		MarkdownDescription: "Unique identifier for this file",
		Computed:            true,
	},
}
View Source
var SSHFileDataSourceSchema = dschema.Schema{
	MarkdownDescription: "Read files over SSH",
	Attributes: map[string]dschema.Attribute{
		"path":           SSHFileAttrs.Path,
		"content":        SSHFileAttrs.Content__DataSource,
		"permissions":    SSHFileAttrs.Permissions,
		"fail_if_absent": SSHFileAttrs.FailIfAbsent,
		"id":             SSHFileAttrs.ID,

		"host":                    SSHConnectionSchema.Host,
		"user":                    SSHConnectionSchema.User,
		"password":                SSHConnectionSchema.Password,
		"private_key":             SSHConnectionSchema.PrivateKey,
		"port":                    SSHConnectionSchema.Port,
		"use_provider_as_bastion": SSHConnectionSchema.UseProviderAsBastion,
		"bastion":                 SSHConnectionSchema.Bastion,
	},
}
View Source
var SSHFileResourceSchema = rschema.Schema{
	MarkdownDescription: "Manage files over SSH with potential side effects",
	Attributes: map[string]rschema.Attribute{
		"path":              SSHFileAttrs.Path,
		"content":           SSHFileAttrs.Content__Resource,
		"permissions":       SSHFileAttrs.Permissions,
		"fail_if_absent":    SSHFileAttrs.FailIfAbsent,
		"delete_on_destroy": SSHFileAttrs.DeleteOnDestroy,
		"id":                SSHFileAttrs.ID,

		"host":                    SSHConnectionSchema.Host,
		"user":                    SSHConnectionSchema.User,
		"password":                SSHConnectionSchema.Password,
		"private_key":             SSHConnectionSchema.PrivateKey,
		"port":                    SSHConnectionSchema.Port,
		"use_provider_as_bastion": SSHConnectionSchema.UseProviderAsBastion,
		"bastion":                 SSHConnectionSchema.Bastion,
	},
}
View Source
var SSHProviderAttrs = struct {
	Host       rschema.StringAttribute
	Port       rschema.Int64Attribute
	User       rschema.StringAttribute
	Password   rschema.StringAttribute
	PrivateKey rschema.StringAttribute
	Bastion    rschema.SingleNestedAttribute
}{
	Host: rschema.StringAttribute{
		MarkdownDescription: "The hostname or IP address of the target SSH server",
		Optional:            true,
	},
	Port: rschema.Int64Attribute{
		MarkdownDescription: "The port number of the target SSH server",
		Optional:            true,
	},
	User: rschema.StringAttribute{
		MarkdownDescription: "The username for SSH authentication",
		Optional:            true,
	},
	Password: rschema.StringAttribute{
		MarkdownDescription: "The password for SSH authentication",
		Optional:            true,
		Sensitive:           true,
	},
	PrivateKey: rschema.StringAttribute{
		MarkdownDescription: "The private key for SSH authentication",
		Optional:            true,
		Sensitive:           true,
	},
	Bastion: SSHBastionAttr,
}
View Source
var SSHProviderSchema = pschema.Schema{
	Attributes: map[string]pschema.Attribute{
		"host":        SSHProviderAttrs.Host,
		"port":        SSHProviderAttrs.Port,
		"user":        SSHProviderAttrs.User,
		"password":    SSHProviderAttrs.Password,
		"private_key": SSHProviderAttrs.PrivateKey,
		"bastion":     SSHProviderAttrs.Bastion,
	},
}

Functions

func New

func New(version string) func() provider.Provider

func NewSSHExecDataSource

func NewSSHExecDataSource() datasource.DataSource

func NewSSHExecResource

func NewSSHExecResource() resource.Resource

func NewSSHFileDataSource

func NewSSHFileDataSource() datasource.DataSource

func NewSSHFileResource

func NewSSHFileResource() resource.Resource

Types

type SSHConnectionConfig

type SSHConnectionConfig struct {
	Host       *string
	User       *string
	Password   *string
	PrivateKey *string
	Port       *int64
}

type SSHConnectionModel

type SSHConnectionModel struct {
	Host       types.String `tfsdk:"host"`
	User       types.String `tfsdk:"user"`
	Password   types.String `tfsdk:"password"`
	PrivateKey types.String `tfsdk:"private_key"`
	Port       types.Int64  `tfsdk:"port"`
}

Common model for SSH connection configuration

type SSHExecDataSource

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

func (*SSHExecDataSource) Configure

func (*SSHExecDataSource) Metadata

func (*SSHExecDataSource) Read

func (*SSHExecDataSource) Schema

type SSHExecDataSourceModel

type SSHExecDataSourceModel struct {
	Command       types.String `tfsdk:"command"`
	Output        types.String `tfsdk:"output"`
	ExitCode      types.Int64  `tfsdk:"exit_code"`
	FailIfNonzero types.Bool   `tfsdk:"fail_if_nonzero"`
	Id            types.String `tfsdk:"id"`

	// Connection details
	SSHConnectionModel
	UseProviderAsBastion types.Bool          `tfsdk:"use_provider_as_bastion"`
	Bastion              *SSHConnectionModel `tfsdk:"bastion"`
}

type SSHExecResource

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

func (*SSHExecResource) Configure

func (*SSHExecResource) Create

func (*SSHExecResource) Delete

func (*SSHExecResource) Metadata

func (*SSHExecResource) Read

func (*SSHExecResource) Schema

func (*SSHExecResource) Update

type SSHExecResourceModel

type SSHExecResourceModel struct {
	Command       types.String `tfsdk:"command"`
	Output        types.String `tfsdk:"output"`
	ExitCode      types.Int64  `tfsdk:"exit_code"`
	FailIfNonzero types.Bool   `tfsdk:"fail_if_nonzero"`
	OnDestroy     types.String `tfsdk:"on_destroy"`
	Id            types.String `tfsdk:"id"`

	// Connection details
	SSHConnectionModel
	UseProviderAsBastion types.Bool          `tfsdk:"use_provider_as_bastion"`
	Bastion              *SSHConnectionModel `tfsdk:"bastion"`
}

type SSHFileDataSource

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

func (*SSHFileDataSource) Configure

func (*SSHFileDataSource) Metadata

func (*SSHFileDataSource) Read

func (*SSHFileDataSource) Schema

type SSHFileDataSourceModel

type SSHFileDataSourceModel struct {
	Path         types.String `tfsdk:"path"`
	Content      types.String `tfsdk:"content"`
	Permissions  types.String `tfsdk:"permissions"`
	FailIfAbsent types.Bool   `tfsdk:"fail_if_absent"`
	Id           types.String `tfsdk:"id"`

	// Connection details
	SSHConnectionModel
	UseProviderAsBastion types.Bool          `tfsdk:"use_provider_as_bastion"`
	Bastion              *SSHConnectionModel `tfsdk:"bastion"`
}

type SSHFileResource

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

func (*SSHFileResource) Configure

func (*SSHFileResource) Create

func (*SSHFileResource) Delete

func (*SSHFileResource) Metadata

func (*SSHFileResource) Read

func (*SSHFileResource) Schema

func (*SSHFileResource) Update

type SSHFileResourceModel

type SSHFileResourceModel struct {
	Path            types.String `tfsdk:"path"`
	Content         types.String `tfsdk:"content"`
	Permissions     types.String `tfsdk:"permissions"`
	FailIfAbsent    types.Bool   `tfsdk:"fail_if_absent"`
	DeleteOnDestroy types.Bool   `tfsdk:"delete_on_destroy"`
	Id              types.String `tfsdk:"id"`

	// Connection details
	SSHConnectionModel
	UseProviderAsBastion types.Bool          `tfsdk:"use_provider_as_bastion"`
	Bastion              *SSHConnectionModel `tfsdk:"bastion"`
}

type SSHManager

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

SSHManager handles SSH connections for the provider

func NewSSHManager

func NewSSHManager(config *SSHConnectionConfig, bastion *SSHConnectionConfig) (*SSHManager, error)

NewSSHManager creates a new SSH connection manager

func (*SSHManager) GetClient

func (m *SSHManager) GetClient(config SSHConnectionConfig, useProviderAsBastion bool, bastion *SSHConnectionConfig, fromClient *ssh.Client) (*ssh.Client, error)

GetClient returns a cached SSH client or creates a new one if not found

type SSHProvider

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

func (*SSHProvider) Configure

func (*SSHProvider) DataSources

func (p *SSHProvider) DataSources(ctx context.Context) []func() datasource.DataSource

func (*SSHProvider) Functions

func (p *SSHProvider) Functions(ctx context.Context) []func() function.Function

func (*SSHProvider) Metadata

func (*SSHProvider) Resources

func (p *SSHProvider) Resources(ctx context.Context) []func() resource.Resource

func (*SSHProvider) Schema

type SSHProviderModel

type SSHProviderModel struct {
	SSHConnectionModel
	Bastion *SSHConnectionModel `tfsdk:"bastion"`
}

Jump to

Keyboard shortcuts

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