provider

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2025 License: MPL-2.0 Imports: 37 Imported by: 0

Documentation

Overview

Package provider implements the Terraform Provider for Jira.

Highlights:

  • Auth: API token for Jira Cloud (recommended) and basic auth for self-hosted Jira.
  • Timeouts & retries: configurable HTTP timeout and capped exponential backoff; honors Retry-After.
  • Concurrency: safe for parallel plans; declare explicit dependencies when API ordering matters.
  • Deterministic outputs: data sources/resources avoid spurious diffs via stable IDs and sorting.

Further reading (canonical docs):

  • Configuration & env vars: docs/index.md#configuration
  • Retries, timeouts, and rate limits: docs/index.md#provider-retries-and-timeouts
  • Troubleshooting: docs/index.md#troubleshooting
  • Examples: docs/ and examples/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackoffDuration added in v0.5.0

func BackoffDuration(attempt int, base, max time.Duration, jitter float64) time.Duration

BackoffDuration computes capped exponential backoff for the given attempt (1-based), starting from base and capped at max. A jitter fraction in [0,1] expands/shrinks the delay uniformly within [1-jitter, 1+jitter]. Values outside bounds are clamped.

func CreateResource added in v0.1.0

func CreateResource[C, R any](ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse, resourceModel ResourceTransformer[C, R], createFunc func(ctx context.Context, newResource C) (R, *models.ResponseScheme, error))

CreateResource is a generic helper that reads the plan, calls the API create function, transforms the API response into Terraform state, and sets it on the response.

func DeleteResource added in v0.1.0

func DeleteResource(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse, resourceModel IDer, deleteFunc func(ctx context.Context, id string) (*models.ResponseScheme, error))

DeleteResource is a generic helper that loads state, calls the API delete function, treats 404 as a successful no-op for idempotency, and returns diagnostics on failure.

func EnsureSuccessOrDiagFromScheme added in v0.5.0

func EnsureSuccessOrDiagFromScheme(ctx context.Context, op string, rs *models.ResponseScheme, err error, diags *diag.Diagnostics) bool

EnsureSuccessOrDiagFromScheme validates success and adds diagnostics on failure.

func EnsureSuccessOrDiagFromSchemeWithOptions added in v0.5.0

func EnsureSuccessOrDiagFromSchemeWithOptions(ctx context.Context, op string, rs *models.ResponseScheme, err error, diags *diag.Diagnostics, opts *EnsureSuccessOrDiagOptions) bool

EnsureSuccessOrDiagFromSchemeWithOptions validates success according to options.

func ErrorFromScheme added in v0.5.0

func ErrorFromScheme(ctx context.Context, op string, rs *models.ResponseScheme, err error) (string, string)

ErrorFromScheme returns redacted summary and detail without body/header snippets.

func ErrorFromSchemeWithOptions added in v0.5.0

func ErrorFromSchemeWithOptions(ctx context.Context, op string, rs *models.ResponseScheme, err error, opts *EnsureSuccessOrDiagOptions) (string, string)

ErrorFromSchemeWithOptions includes body/headers snippets when requested.

func HTTPStatusFromScheme added in v0.5.0

func HTTPStatusFromScheme(rs *models.ResponseScheme) int

HTTPStatusFromScheme returns the HTTP status from the response scheme or 0 if unavailable.

func HTTPStatusStrictFromScheme added in v0.5.0

func HTTPStatusStrictFromScheme(rs *models.ResponseScheme) (int, error)

HTTPStatusStrictFromScheme validates and returns the status or an error when missing/invalid.

func ImportResource added in v0.1.0

func ImportResource[R any](ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse, resourceModel TerraformTransformer[R], getFunc func(ctx context.Context, id string) (R, *models.ResponseScheme, error))

func IsContextError added in v0.5.0

func IsContextError(err error) bool

IsContextError reports if err indicates context cancellation or deadline exceeded.

func IsSuccess added in v0.5.0

func IsSuccess(code int) bool

IsSuccess reports whether the given HTTP status code is in 2xx range.

func New

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

New returns a constructor that builds a JiraProvider with the given version string.

func NewProjectCategoriesDataSource added in v0.7.0

func NewProjectCategoriesDataSource() datasource.DataSource

NewProjectCategoriesDataSource returns the Terraform data source implementation for jira_project_categories.

func NewProjectCategoryResource added in v0.7.0

func NewProjectCategoryResource() resource.Resource

NewProjectCategoryResource returns the Terraform resource implementation for jira_project_category.

func NewProjectDataSource added in v0.5.0

func NewProjectDataSource() datasource.DataSource

NewProjectDataSource returns the Terraform data source implementation for jira_project (lookup by key/ID).

func NewProjectResource added in v0.5.0

func NewProjectResource() resource.Resource

NewProjectResource returns the Terraform resource implementation for jira_project.

func NewProjectsDataSource added in v0.6.0

func NewProjectsDataSource() datasource.DataSource

NewProjectsDataSource returns the Terraform data source implementation for jira_projects (list/filter; pagination).

func NewWorkTypeResource added in v0.1.0

func NewWorkTypeResource() resource.Resource

NewWorkTypeResource returns the Terraform resource implementation for jira_work_type.

func NewWorkTypesDataSource added in v0.2.0

func NewWorkTypesDataSource() datasource.DataSource

NewWorkTypesDataSource returns the Terraform data source implementation for jira_work_types.

func NewWorkflowStatusResource added in v0.3.0

func NewWorkflowStatusResource() resource.Resource

NewWorkflowStatusResource returns the Terraform resource implementation for jira_workflow_status.

func ParseRetryAfter added in v0.5.0

func ParseRetryAfter(h http.Header) time.Duration

ParseRetryAfter returns a server-specified delay indicated by the Retry-After header. It supports both seconds and HTTP-date formats. Returns 0 when absent/invalid or when the computed delay would be negative.

func ReadResource added in v0.1.0

func ReadResource[R any](ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse, resourceModel TerraformTransformer[R], readFunc func(ctx context.Context, id string) (R, *models.ResponseScheme, error))

ReadResource is a generic helper that loads state, calls the API read function, handles 404 as not found by removing state, and updates state on success.

func RedactHeaders added in v0.5.0

func RedactHeaders(h http.Header) http.Header

RedactHeaders returns a safe copy of the provided headers with sensitive keys redacted. It operates on a copy; the input is not mutated.

func RedactJoin added in v0.5.0

func RedactJoin(parts []string, sep string) string

RedactJoin is a small helper to join strings with a separator after redaction.

func RedactSecrets added in v0.5.0

func RedactSecrets(s string) string

RedactSecrets scans the provided string and masks common sensitive values such as Authorization tokens, basic credentials, emails, and URLs with embedded credentials. It is idempotent and safe to call multiple times.

func ShouldRetry added in v0.5.0

func ShouldRetry(status int, err error) bool

ShouldRetry classifies whether a request should be retried for given status/err. Policy: - Never retry context cancellation/deadline errors (caller controls lifetime). - Retry on HTTP 429 and 5xx (server signaled throttling or transient server failure). - Transport-level retries are restricted to likely-transient conditions only:

  • net.Error with Timeout()==true (includes DNS/socket timeouts)
  • io.ErrUnexpectedEOF (truncated responses)
  • Connection reset/aborted/broken pipe (syscall ECONNRESET/ECONNABORTED/EPIPE)
  • Do NOT blanket-retry all status==0 errors; e.g., DNS resolution failures like "no such host" are treated as non-retryable unless they reported a timeout.

func UpdateResource added in v0.1.0

func UpdateResource[P, R any](ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse, resourceModel ResourceTransformer[P, R], updateFunc func(ctx context.Context, updatedResourceId string, updatedResource P) (R, *models.ResponseScheme, error))

UpdateResource is a generic helper that reads the plan, calls the API update function, transforms the API response into Terraform state, and writes the updated state.

Types

type APIPayloadGetter added in v0.5.0

type APIPayloadGetter[P any] interface {
	GetAPIPayload(ctx context.Context) (createPayload P, diags diag.Diagnostics)
}

APIPayloadGetter defines a model capable of producing an API payload for create/update operations.

type EnsureSuccessOrDiagOptions added in v0.5.0

type EnsureSuccessOrDiagOptions struct {
	AcceptableStatuses      []int
	TreatRead404AsNotFound  bool
	TreatDelete404AsSuccess bool
	IncludeBodySnippet      bool
	MaxBodyBytes            int
}

EnsureSuccessOrDiagOptions configures success and diagnostics behavior per operation. AcceptableStatuses extends success criteria beyond 2xx. TreatRead404AsNotFound means callers will handle state removal on 404 reads. TreatDelete404AsSuccess makes delete idempotent. IncludeBodySnippet appends a truncated response body and select headers.

type IDer added in v0.1.0

type IDer interface {
	GetID() string
}

IDer exposes a stable identifier accessor used by CRUD helpers and import.

type JiraProvider

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

JiraProvider defines the provider implementation.

func (*JiraProvider) Configure

Configure establishes the Jira API client and validates authentication. It attaches the configured client to resources and data sources for use in operations.

func (*JiraProvider) DataSources

func (j *JiraProvider) DataSources(_ context.Context) []func() datasource.DataSource

DataSources returns the set of Terraform data sources supported by the provider.

func (*JiraProvider) Metadata

Metadata sets the provider type name and version for Terraform.

func (*JiraProvider) Resources

func (j *JiraProvider) Resources(_ context.Context) []func() resource.Resource

Resources returns the set of Terraform resources supported by the provider.

func (*JiraProvider) Schema

Schema returns the provider schema describing configuration attributes.

func (*JiraProvider) ValidateConfig

type JiraProviderModel

type JiraProviderModel struct {
	// Base Configuration
	Endpoint types.String `tfsdk:"endpoint"`

	AuthMethod types.String `tfsdk:"auth_method"`

	// Logging
	Debug types.Bool `tfsdk:"debug"`

	OperationTimeouts *OperationTimeoutsModel `tfsdk:"operation_timeouts"`

	// HTTP Settings
	HTTPTimeoutSeconds    types.Int64 `tfsdk:"http_timeout_seconds"`
	RetryOn4295xx         types.Bool  `tfsdk:"retry_on_429_5xx"`
	RetryMaxAttempts      types.Int64 `tfsdk:"retry_max_attempts"`
	RetryInitialBackoffMs types.Int64 `tfsdk:"retry_initial_backoff_ms"`
	RetryMaxBackoffMs     types.Int64 `tfsdk:"retry_max_backoff_ms"`

	// API Token Authentication
	APIToken     types.String `tfsdk:"api_token"`
	APIAuthEmail types.String `tfsdk:"api_auth_email"`

	// Basic Authentication
	Username types.String `tfsdk:"username"`
	Password types.String `tfsdk:"password"`

	// Privacy & Redaction
	EmailRedactionMode types.String `tfsdk:"email_redaction_mode"`
}

JiraProviderModel describes the provider data model.

type OperationTimeoutsModel added in v0.5.0

type OperationTimeoutsModel struct {
	Create types.String `tfsdk:"create"`
	Read   types.String `tfsdk:"read"`
	Update types.String `tfsdk:"update"`
	Delete types.String `tfsdk:"delete"`
}

type ResourceTransformer added in v0.1.0

type ResourceTransformer[P, R any] interface {
	APIPayloadGetter[P]
	TerraformTransformer[R]
}

ResourceTransformer combines API payload building and state transformation for a resource model.

type TerraformTransformer added in v0.1.0

type TerraformTransformer[R any] interface {
	IDer
	TransformToState(ctx context.Context, apiModel R) diag.Diagnostics
}

TerraformTransformer defines a model that can map an API model into Terraform state.

Directories

Path Synopsis
Package testhelpers provides shared testing utilities used across unit and acceptance tests.
Package testhelpers provides shared testing utilities used across unit and acceptance tests.

Jump to

Keyboard shortcuts

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