provider

package
v0.0.0-...-2a54362 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: GPL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeOut            = 5     // Default http session timeout
	DefaultInsecureSkipVerify = false // Default value for insecure skip verify
)

Variables

View Source
var GroupResponse1 = map[string]string{
	"description": "",
	"inventory":   "1",
	"name":        "Group1",
}
View Source
var GroupResponse2 = map[string]string{
	"description": "Updated group",
	"inventory":   "1",
	"name":        "Group1",
}
View Source
var GroupResponse3 = map[string]string{
	"description": "",
	"inventory":   "3",
	"name":        "Group1",
	"variables":   "{\"ansible_network_os\": \"ios\"}",
}
View Source
var JobResponse1 = map[string]string{
	"status": "running",
	"type":   "check",
}
View Source
var JobResponse2 = map[string]string{
	"status":   "pending",
	"playbook": "ansible_aws.yaml",
}
View Source
var JobResponse3 = map[string]string{
	"status":                "complete",
	"execution_environment": "3",
}
View Source
var MockConfig = map[string]map[string]string{
	"/api/v2/job_templates/1/launch/": JobResponse1,
	"/api/v2/job_templates/2/launch/": JobResponse2,
	"/api/v2/jobs/1/":                 JobResponse1,
	"/api/v2/jobs/2/":                 JobResponse3,
	"/api/v2/groups/":                 GroupResponse1,
	"/api/v2/groups/1/":               GroupResponse2,
	"/api/v2/groups/2/":               GroupResponse3,
}

Functions

func AddConfigurationAttributeError

func AddConfigurationAttributeError(resp *provider.ConfigureResponse, name, envName string, isUnknown bool)

func DeepEqualJSONByte

func DeepEqualJSONByte(a, b []byte) (bool, error)

DeepEqualJSONByte compares the JSON in two byte slices.

func IsValueProvided

func IsValueProvided(value attr.Value) bool

func New

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

New is a helper function to simplify provider server and testing implementation.

func NewGroupResource

func NewGroupResource() resource.Resource

NewGroupResource is a helper function to simplify the provider implementation.

func NewHostResource

func NewHostResource() resource.Resource

NewHostResource is a helper function to simplify the provider implementation.

func NewInventoryDataSource

func NewInventoryDataSource() datasource.DataSource

NewInventoryDataSource is a helper function to simplify the provider implementation.

func NewInventoryResource

func NewInventoryResource() resource.Resource

NewInventoryResource is a helper function to simplify the provider implementation.

func NewJobResource

func NewJobResource() resource.Resource

NewJobResource is a helper function to simplify the provider implementation.

func ParseAAPCustomStringValue

func ParseAAPCustomStringValue(variables string) customtypes.AAPCustomStringValue

func ParseNormalizedValue

func ParseNormalizedValue(variables string) jsontypes.Normalized

func ParseStringValue

func ParseStringValue(description string) types.String

func ValidateResponse

func ValidateResponse(resp *http.Response, body []byte, err error, expected_statuses []int) diag.Diagnostics

Types

type AAPClient

type AAPClient struct {
	HostURL  string
	Username *string
	Password *string
	// contains filtered or unexported fields
}

Client -

func NewClient

func NewClient(host string, username *string, password *string, insecureSkipVerify bool, timeout int64) (*AAPClient, error)

NewClient - create new AAPClient instance

func (*AAPClient) Create

func (c *AAPClient) Create(path string, data io.Reader) ([]byte, diag.Diagnostics)

Create sends a POST request with the provided data to the provided path, checks for errors, and returns the response body with any errors as diagnostics.

func (*AAPClient) Delete

func (c *AAPClient) Delete(path string) ([]byte, diag.Diagnostics)

Delete sends a DELETE request to the provided path, checks for errors, and returns any errors as diagnostics.

func (*AAPClient) Get

func (c *AAPClient) Get(path string) ([]byte, diag.Diagnostics)

Get sends a GET request to the provided path, checks for errors, and returns the response body with any errors as diagnostics.

func (*AAPClient) Update

func (c *AAPClient) Update(path string, data io.Reader) ([]byte, diag.Diagnostics)

Update sends a PUT request with the provided data to the provided path, checks for errors, and returns the response body with any errors as diagnostics.

type GroupAPIModel

type GroupAPIModel struct {
	InventoryId int64  `json:"inventory"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	URL         string `json:"url,omitempty"`
	Variables   string `json:"variables,omitempty"`
	Id          int64  `json:"id,omitempty"`
}

Group AAP API model

type GroupResource

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

GroupResource is the resource implementation.

func (*GroupResource) Configure

Configure adds the provider configured client to the resource

func (*GroupResource) Create

Create creates the group resource and sets the Terraform state on success.

func (*GroupResource) Delete

Delete deletes the group resource.

func (*GroupResource) Metadata

Metadata returns the resource type name.

func (*GroupResource) Read

Read refreshes the Terraform state with the latest group data.

func (*GroupResource) Schema

Schema defines the schema for the group resource.

func (*GroupResource) Update

Update updates the group resource and sets the updated Terraform state on success.

type GroupResourceModel

type GroupResourceModel struct {
	InventoryId types.Int64                      `tfsdk:"inventory_id"`
	Name        types.String                     `tfsdk:"name"`
	Description types.String                     `tfsdk:"description"`
	URL         types.String                     `tfsdk:"url"`
	Variables   customtypes.AAPCustomStringValue `tfsdk:"variables"`
	Id          types.Int64                      `tfsdk:"id"`
}

GroupResourceModel maps the group resource schema to a Go struct

func (*GroupResourceModel) CreateRequestBody

func (r *GroupResourceModel) CreateRequestBody() ([]byte, diag.Diagnostics)

CreateRequestBody creates a JSON encoded request body from the group resource data

func (*GroupResourceModel) ParseHttpResponse

func (r *GroupResourceModel) ParseHttpResponse(body []byte) diag.Diagnostics

ParseHttpResponse updates the group resource data from an AAP API response

type HostAPIModel

type HostAPIModel struct {
	InventoryId int64  `json:"inventory"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	URL         string `json:"url,omitempty"`
	Variables   string `json:"variables,omitempty"`
	Enabled     bool   `json:"enabled"`
	Id          int64  `json:"id,omitempty"`
}

Host AAP API model

type HostResource

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

HostResource is the resource implementation.

func (*HostResource) AssociateGroups

func (r *HostResource) AssociateGroups(ctx context.Context, data []int64, url string, args ...bool) diag.Diagnostics

func (*HostResource) Configure

Configure adds the provider configured client to the resource

func (*HostResource) Create

Create creates the host resource and sets the Terraform state on success.

func (*HostResource) Delete

Delete deletes the host resource.

func (*HostResource) HandleGroupAssociation

func (r *HostResource) HandleGroupAssociation(ctx context.Context, data HostResourceModel) diag.Diagnostics

func (*HostResource) Metadata

Metadata returns the resource type name.

func (*HostResource) Read

Read refreshes the Terraform state with the latest host data.

func (*HostResource) ReadAssociatedGroups

func (r *HostResource) ReadAssociatedGroups(data HostResourceModel) ([]int64, diag.Diagnostics)

func (*HostResource) Schema

Schema defines the schema for the host resource.

func (*HostResource) Update

Update updates the host resource and sets the updated Terraform state on success.

type HostResourceModel

type HostResourceModel struct {
	InventoryId types.Int64                      `tfsdk:"inventory_id"`
	Name        types.String                     `tfsdk:"name"`
	URL         types.String                     `tfsdk:"url"`
	Description types.String                     `tfsdk:"description"`
	Variables   customtypes.AAPCustomStringValue `tfsdk:"variables"`
	Groups      types.Set                        `tfsdk:"groups"`
	Enabled     types.Bool                       `tfsdk:"enabled"`
	Id          types.Int64                      `tfsdk:"id"`
}

HostResourceModel maps the host resource schema to a Go struct

func (*HostResourceModel) CreateRequestBody

func (r *HostResourceModel) CreateRequestBody() ([]byte, diag.Diagnostics)

CreateRequestBody creates a JSON encoded request body from the host resource data

func (*HostResourceModel) ParseHttpResponse

func (r *HostResourceModel) ParseHttpResponse(body []byte) diag.Diagnostics

ParseHttpResponse updates the host resource data from an AAP API response

func (*HostResourceModel) UpdateStateWithGroups

func (r *HostResourceModel) UpdateStateWithGroups(ctx context.Context, groups []int64) diag.Diagnostics

type InventoryAPIModel

type InventoryAPIModel struct {
	Id           int64  `json:"id,omitempty"`
	Organization int64  `json:"organization"`
	Url          string `json:"url,omitempty"`
	Name         string `json:"name"`
	Description  string `json:"description,omitempty"`
	Variables    string `json:"variables,omitempty"`
}

Inventory AAP API model

type InventoryDataSource

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

inventoryDataSource is the data source implementation.

func (*InventoryDataSource) Configure

Configure adds the provider configured client to the data source.

func (*InventoryDataSource) Metadata

Metadata returns the data source type name.

func (*InventoryDataSource) Read

Read refreshes the Terraform state with the latest data.

func (*InventoryDataSource) Schema

Schema defines the schema for the data source.

type InventoryDataSourceModel

type InventoryDataSourceModel struct {
	Id           types.Int64                      `tfsdk:"id"`
	Organization types.Int64                      `tfsdk:"organization"`
	Url          types.String                     `tfsdk:"url"`
	Name         types.String                     `tfsdk:"name"`
	Description  types.String                     `tfsdk:"description"`
	Variables    customtypes.AAPCustomStringValue `tfsdk:"variables"`
}

inventoryDataSourceModel maps the data source schema data.

func (*InventoryDataSourceModel) ParseHttpResponse

func (d *InventoryDataSourceModel) ParseHttpResponse(body []byte) diag.Diagnostics

type InventoryResource

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

InventoryResource is the resource implementation.

func (*InventoryResource) Configure

Configure adds the provider configured client to the resource.

func (*InventoryResource) Create

Create creates the inventory resource and sets the Terraform state on success.

func (*InventoryResource) Delete

Delete deletes the inventory resource.

func (*InventoryResource) Metadata

Metadata returns the resource type name.

func (*InventoryResource) Read

Read refreshes the Terraform state with the latest inventory data.

func (*InventoryResource) Schema

Schema defines the schema for the resource.

func (*InventoryResource) Update

Update updates the inventory resource and sets the updated Terraform state on success.

type JobAPIModel

type JobAPIModel struct {
	TemplateID    int64                  `json:"job_template,omitempty"`
	Type          string                 `json:"job_type,omitempty"`
	URL           string                 `json:"url,omitempty"`
	Status        string                 `json:"status,omitempty"`
	Inventory     int64                  `json:"inventory,omitempty"`
	ExtraVars     string                 `json:"extra_vars,omitempty"`
	IgnoredFields map[string]interface{} `json:"ignored_fields,omitempty"`
}

Job AAP API model

type JobResource

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

JobResource is the resource implementation.

func (*JobResource) Configure

Configure adds the provider configured client to the data source.

func (*JobResource) Create

func (JobResource) Delete

func (*JobResource) LaunchJob

func (r *JobResource) LaunchJob(data *JobResourceModel) diag.Diagnostics

func (*JobResource) Metadata

Metadata returns the resource type name.

func (*JobResource) Read

func (*JobResource) Schema

Schema defines the schema for the jobresource.

func (*JobResource) Update

type JobResourceModel

type JobResourceModel struct {
	TemplateID    types.Int64                      `tfsdk:"job_template_id"`
	Type          types.String                     `tfsdk:"job_type"`
	URL           types.String                     `tfsdk:"url"`
	Status        types.String                     `tfsdk:"status"`
	InventoryID   types.Int64                      `tfsdk:"inventory_id"`
	ExtraVars     customtypes.AAPCustomStringValue `tfsdk:"extra_vars"`
	IgnoredFields types.List                       `tfsdk:"ignored_fields"`
	Triggers      types.Map                        `tfsdk:"triggers"`
}

JobResourceModel maps the resource schema data.

func (*JobResourceModel) CreateRequestBody

func (r *JobResourceModel) CreateRequestBody() ([]byte, diag.Diagnostics)

CreateRequestBody creates a JSON encoded request body from the job resource data

func (*JobResourceModel) GetTemplateID

func (r *JobResourceModel) GetTemplateID() string

func (*JobResourceModel) ParseHttpResponse

func (r *JobResourceModel) ParseHttpResponse(body []byte) diag.Diagnostics

ParseHttpResponse updates the job resource data from an AAP API response

func (*JobResourceModel) ParseIgnoredFields

func (r *JobResourceModel) ParseIgnoredFields(ignoredFields map[string]interface{}) (diags diag.Diagnostics)

type MockHTTPClient

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

func NewMockHTTPClient

func NewMockHTTPClient(methods []string, httpCode int) *MockHTTPClient

func (*MockHTTPClient) Create

func (c *MockHTTPClient) Create(path string, data io.Reader) ([]byte, diag.Diagnostics)

func (*MockHTTPClient) Delete

func (c *MockHTTPClient) Delete(path string) ([]byte, diag.Diagnostics)

func (*MockHTTPClient) Get

func (c *MockHTTPClient) Get(path string) ([]byte, diag.Diagnostics)

func (*MockHTTPClient) Update

func (c *MockHTTPClient) Update(path string, data io.Reader) ([]byte, diag.Diagnostics)

type ProviderHTTPClient

type ProviderHTTPClient interface {
	Create(path string, data io.Reader) ([]byte, diag.Diagnostics)
	Get(path string) ([]byte, diag.Diagnostics)
	Update(path string, data io.Reader) ([]byte, diag.Diagnostics)
	Delete(path string) ([]byte, diag.Diagnostics)
	// contains filtered or unexported methods
}

Provider Http Client interface (will be useful for unit tests)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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