openapi

package
v0.31.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2020 License: Apache-2.0 Imports: 36 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// TypeString defines a schema definition property of type int
	TypeString schemaDefinitionPropertyType = "string"
	// TypeInt defines a schema definition property of type int
	TypeInt schemaDefinitionPropertyType = "integer"
	// TypeFloat defines a schema definition property of type float
	TypeFloat schemaDefinitionPropertyType = "number"
	// TypeBool defines a schema definition property of type bool
	TypeBool schemaDefinitionPropertyType = "boolean"
	// TypeList defines a schema definition property of type list
	TypeList schemaDefinitionPropertyType = "list"
	// TypeObject defines a schema definition property of type object
	TypeObject schemaDefinitionPropertyType = "object"
)
View Source
const OpenAPIPluginConfigurationFileName = "terraform-provider-openapi.yaml"

OpenAPIPluginConfigurationFileName defines the file name used for the OpenAPI plugin configuration

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientOpenAPI added in v0.4.0

type ClientOpenAPI interface {
	Post(resource SpecResource, requestPayload interface{}, responsePayload interface{}, parentIDs ...string) (*http.Response, error)
	Put(resource SpecResource, id string, requestPayload interface{}, responsePayload interface{}, parentIDs ...string) (*http.Response, error)
	Get(resource SpecResource, id string, responsePayload interface{}, parentIDs ...string) (*http.Response, error)
	Delete(resource SpecResource, id string, parentIDs ...string) (*http.Response, error)
	List(resource SpecResource, responsePayload interface{}, parentIDs ...string) (*http.Response, error)
	GetTelemetryHandler() TelemetryHandler
}

ClientOpenAPI defines the behaviour expected to be implemented for the OpenAPI Client used in the Terraform OpenAPI Provider

type MetricSubmitter added in v0.26.0

type MetricSubmitter func() error

MetricSubmitter is the function holding the logic that actually submits the metric

type ParentResourceInfo added in v0.30.0

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

ParentResourceInfo contains the information related to the parent information. For instance, a subresource would have this struct populated with the parent info so the resource name and corresponding parent properties can be configured in the resource schema

func (*ParentResourceInfo) GetParentPropertiesNames added in v0.30.0

func (info *ParentResourceInfo) GetParentPropertiesNames() []string

GetParentPropertiesNames is responsible to building the parent properties names for a resource that is a subresource

func (*ParentResourceInfo) SetParentResourceNames added in v0.30.0

func (info *ParentResourceInfo) SetParentResourceNames(parentResourceNames []string)

SetParentResourceNames sets the resource parent names

type PluginConfigSchema added in v0.1.1

type PluginConfigSchema interface {
	// Validate performs a check to confirm that the schema content is correct
	Validate() error
	// GetServiceConfig returns the service configuration for a given provider name
	GetServiceConfig(providerName string) (ServiceConfiguration, error)
	// GetAllServiceConfigurations returns all the service configuration
	GetAllServiceConfigurations() (ServiceConfigurations, error)
	// GetVersion returns the plugin configuration version
	GetVersion() (string, error)
	// Marshal serializes the value provided into a YAML document
	Marshal() ([]byte, error)
}

PluginConfigSchema defines the interface/expected behaviour for PluginConfigSchema implementations.

type PluginConfigSchemaV1 added in v0.1.1

type PluginConfigSchemaV1 struct {
	Version  string                      `yaml:"version"`
	Services map[string]*ServiceConfigV1 `yaml:"services"`
}

PluginConfigSchemaV1 defines PluginConfigSchema version 1 Configuration example: version: '1' services:

monitor:
  swagger-url: http://monitor-api.com/swagger.json
  plugin_version: 0.14.0
  insecure_skip_verify: true
cdn:
  swagger-url: https://cdn-api.com/swagger.json
vm:
  swagger-url: http://vm-api.com/swagger.json

func NewPluginConfigSchemaV1 added in v0.1.1

func NewPluginConfigSchemaV1(services map[string]*ServiceConfigV1) *PluginConfigSchemaV1

NewPluginConfigSchemaV1 creates a new PluginConfigSchemaV1 that implements PluginConfigSchema interface

func (*PluginConfigSchemaV1) GetAllServiceConfigurations added in v0.1.2

func (p *PluginConfigSchemaV1) GetAllServiceConfigurations() (ServiceConfigurations, error)

GetAllServiceConfigurations returns all the service configuration

func (*PluginConfigSchemaV1) GetServiceConfig added in v0.1.1

func (p *PluginConfigSchemaV1) GetServiceConfig(providerName string) (ServiceConfiguration, error)

GetServiceConfig returns the configuration for the given provider name

func (*PluginConfigSchemaV1) GetVersion added in v0.1.2

func (p *PluginConfigSchemaV1) GetVersion() (string, error)

GetVersion returns the plugin configuration version

func (*PluginConfigSchemaV1) Marshal added in v0.1.2

func (p *PluginConfigSchemaV1) Marshal() ([]byte, error)

Marshal serializes the value provided into a YAML document

func (*PluginConfigSchemaV1) Validate added in v0.1.1

func (p *PluginConfigSchemaV1) Validate() error

Validate makes sure that schema data is correct

type PluginConfiguration added in v0.1.1

type PluginConfiguration struct {
	// ProviderName defines the <provider_name> (should match the provider name of the terraform provider binary; terraform-provider-<provider_name>)
	ProviderName string
	// Configuration defines the reader that contains the plugin's external configuration (located at ~/.terraform.d/plugins)
	// If the plugin configuration file is not present the OTF_VAR_<provider_name>_SWAGGER_URL environment variable will
	// be required when invoking the openapi provider.
	// If at runtime both the OTF_VAR_<provider_name>_SWAGGER_URL as well as the plugin configuration file are present
	// the former takes preference. This allows the user to override the url specified in the configuration file with
	// the value provided in the OTF_VAR_<provider_name>_SWAGGER_URL
	Configuration io.Reader
}

PluginConfiguration defines the OpenAPI plugin's configuration

func NewPluginConfiguration added in v0.1.1

func NewPluginConfiguration(providerName string) (*PluginConfiguration, error)

NewPluginConfiguration creates a new PluginConfiguration

type ProviderClient added in v0.4.0

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

ProviderClient defines a client that is configured based on the OpenAPI server side documentation The CRUD operations accept an OpenAPI operation which defines among other things the security scheme applicable to the API when making the HTTP requests

func (*ProviderClient) Delete added in v0.4.0

func (o *ProviderClient) Delete(resource SpecResource, id string, parentIDs ...string) (*http.Response, error)

Delete performs a DELETE request to the server API based on the resource configuration and the resource instance id passed in

func (*ProviderClient) Get added in v0.4.0

func (o *ProviderClient) Get(resource SpecResource, id string, responsePayload interface{}, parentIDs ...string) (*http.Response, error)

Get performs a GET request to the server API based on the resource configuration and the resource instance id passed in

func (*ProviderClient) GetTelemetryHandler added in v0.28.0

func (o *ProviderClient) GetTelemetryHandler() TelemetryHandler

GetTelemetryHandler returns the configured telemetry handler

func (*ProviderClient) List added in v0.18.0

func (o *ProviderClient) List(resource SpecResource, responsePayload interface{}, parentIDs ...string) (*http.Response, error)

List performs a GET request to the root level endpoint of the resource (e,g: GET /v1/groups)

func (*ProviderClient) Post added in v0.4.0

func (o *ProviderClient) Post(resource SpecResource, requestPayload interface{}, responsePayload interface{}, parentIDs ...string) (*http.Response, error)

Post performs a POST request to the server API based on the resource configuration and the payload passed in

func (*ProviderClient) Put added in v0.4.0

func (o *ProviderClient) Put(resource SpecResource, id string, requestPayload interface{}, responsePayload interface{}, parentIDs ...string) (*http.Response, error)

Put performs a PUT request to the server API based on the resource configuration and the payload passed in

type ProviderOpenAPI added in v0.4.0

type ProviderOpenAPI struct {
	ProviderName string
	// contains filtered or unexported fields
}

ProviderOpenAPI defines the struct for the OpenAPI Terraform Provider

func (*ProviderOpenAPI) CreateSchemaProvider added in v0.8.0

func (p *ProviderOpenAPI) CreateSchemaProvider() (*schema.Provider, error)

CreateSchemaProvider returns a terraform.ResourceProvider.

func (*ProviderOpenAPI) CreateSchemaProviderFromServiceConfiguration added in v0.16.0

func (p *ProviderOpenAPI) CreateSchemaProviderFromServiceConfiguration(serviceConfiguration ServiceConfiguration) (*schema.Provider, error)

CreateSchemaProviderFromServiceConfiguration helper function to enable creation of schema.Provider with the given serviceConfiguration

type ServiceConfigStub added in v0.16.0

type ServiceConfigStub struct {
	SwaggerURL          string
	PluginVersion       string
	InsecureSkipVerify  bool
	Telemetry           TelemetryProvider
	SchemaConfiguration []*ServiceSchemaPropertyConfigurationStub
	Err                 error
}

ServiceConfigStub implements the ServiceConfiguration interface and can be used to simplify the creation of the ProviderOpenAPI provider by calling the CreateSchemaProviderWithConfiguration function passing in the stub wit the swagger URL populated with the URL where the openapi doc is hosted.

func (*ServiceConfigStub) GetPluginVersion added in v0.16.0

func (s *ServiceConfigStub) GetPluginVersion() string

GetPluginVersion returns the plugin version value configured in the ServiceConfigStub.PluginVersion field

func (ServiceConfigStub) GetSchemaPropertyConfiguration added in v0.16.0

func (s ServiceConfigStub) GetSchemaPropertyConfiguration(schemaPropertyName string) ServiceSchemaPropertyConfiguration

GetSchemaPropertyConfiguration returns the service schema configuration set in the ServiceConfigStub.SchemaConfiguration field

func (*ServiceConfigStub) GetSwaggerURL added in v0.16.0

func (s *ServiceConfigStub) GetSwaggerURL() string

GetSwaggerURL returns the swagger URL value configured in the ServiceConfigStub.SwaggerURL field

func (ServiceConfigStub) GetTelemetryConfiguration added in v0.28.0

func (s ServiceConfigStub) GetTelemetryConfiguration() TelemetryProvider

GetTelemetryConfiguration returns the TelemetryProvider configured in the ServiceConfigStub

func (*ServiceConfigStub) IsInsecureSkipVerifyEnabled added in v0.16.0

func (s *ServiceConfigStub) IsInsecureSkipVerifyEnabled() bool

IsInsecureSkipVerifyEnabled returns the bool configured in the ServiceConfigStub.InsecureSkipVerify field

func (*ServiceConfigStub) Validate added in v0.16.0

func (s *ServiceConfigStub) Validate(runningPluginVersion string) error

Validate returns an error if the ServiceConfigStub.Err field is set with an error

type ServiceConfigV1 added in v0.1.1

type ServiceConfigV1 struct {
	// SwaggerURL defines where the swagger is located
	SwaggerURL string `yaml:"swagger-url"`
	// PluginVersion defines the version of the OpenAPI Terraform plugin installed when generating the plugin configuration
	PluginVersion string `yaml:"plugin_version,omitempty"`
	// InsecureSkipVerify defines whether the internal http client used to fetch the swagger file should verify the server cert
	// or not. This should only be used purposefully if the server is using a self-signed cert and only if the server is trusted
	InsecureSkipVerify bool `yaml:"insecure_skip_verify,omitempty"`
	// SchemaConfigurationV1 represents the list of schema property configurations
	SchemaConfigurationV1 []ServiceSchemaPropertyConfigurationV1 `yaml:"schema_configuration,omitempty"`

	TelemetryConfig *TelemetryConfig `yaml:"telemetry,omitempty"`
}

ServiceConfigV1 defines configuration for the service provider

func NewServiceConfigV1 added in v0.1.2

func NewServiceConfigV1(swaggerURL string, insecureSkipVerifyEnabled bool, telemetryConfig *TelemetryConfig) *ServiceConfigV1

NewServiceConfigV1 creates a new instance of NewServiceConfigV1 struct with the values provided

func (*ServiceConfigV1) GetPluginVersion added in v0.15.0

func (s *ServiceConfigV1) GetPluginVersion() string

GetPluginVersion returns the OpenAPI Plugin version

func (*ServiceConfigV1) GetSchemaPropertyConfiguration added in v0.6.0

func (s *ServiceConfigV1) GetSchemaPropertyConfiguration(schemaPropertyName string) ServiceSchemaPropertyConfiguration

GetSchemaPropertyConfiguration returns the external configuration for the given schema property name; nil is returned if no such property exists

func (*ServiceConfigV1) GetSwaggerURL added in v0.1.1

func (s *ServiceConfigV1) GetSwaggerURL() string

GetSwaggerURL returns the URL where the service swagger doc is exposed

func (*ServiceConfigV1) GetTelemetryConfiguration added in v0.28.0

func (s *ServiceConfigV1) GetTelemetryConfiguration() TelemetryProvider

GetTelemetryConfiguration returns a TelemetryProvider configured for Graphite or HTTPEndpoint

func (*ServiceConfigV1) IsInsecureSkipVerifyEnabled added in v0.1.1

func (s *ServiceConfigV1) IsInsecureSkipVerifyEnabled() bool

IsInsecureSkipVerifyEnabled returns true if the given provider's service configuration has InsecureSkipVerify enabled; false otherwise

func (*ServiceConfigV1) Validate added in v0.15.0

func (s *ServiceConfigV1) Validate(runningPluginVersion string) error

Validate makes sure the configuration is valid: - if the user has specified an OpenAPI plugin version, and if the plugin does not match the version then something is off

type ServiceConfiguration added in v0.1.1

type ServiceConfiguration interface {
	// GetSwaggerURL returns the URL where the service swagger doc is exposed
	GetSwaggerURL() string
	// GetSPluginVersion returns the OpenAPI Plugin version
	GetPluginVersion() string
	// IsInsecureSkipVerifyEnabled returns true if the given provider's service configuration has InsecureSkipVerify enabled; false
	// otherwise
	IsInsecureSkipVerifyEnabled() bool
	// GetSchemaPropertyConfiguration returns the schema configuration for the given schemaPropertyName
	GetSchemaPropertyConfiguration(schemaPropertyName string) ServiceSchemaPropertyConfiguration
	// Validate makes sure the configuration is valid
	Validate(runningPluginVersion string) error

	// GetTelemetryConfiguration returns the telemetry configuration for this service provider
	GetTelemetryConfiguration() TelemetryProvider
}

ServiceConfiguration defines the interface/expected behaviour for ServiceConfiguration implementations.

type ServiceConfigurations added in v0.1.2

type ServiceConfigurations map[string]ServiceConfiguration

ServiceConfigurations contains the map with all service configurations

type ServiceSchemaPropertyConfiguration added in v0.6.0

type ServiceSchemaPropertyConfiguration interface {
	GetDefaultValue() (string, error)
	ExecuteCommand() error
}

ServiceSchemaPropertyConfiguration defines the behaviour expected for the service schema property configuration

type ServiceSchemaPropertyConfigurationStub added in v0.16.0

type ServiceSchemaPropertyConfigurationStub struct {
	SchemaPropertyName   string
	DefaultValue         string
	Err                  error
	GetDefaultValueFunc  func() (string, error)
	ExecuteCommandCalled bool
}

ServiceSchemaPropertyConfigurationStub implements the ServiceSchemaPropertyConfiguration and can be used to simplify tests that require ServiceSchemaPropertyConfiguration implemenations

func (*ServiceSchemaPropertyConfigurationStub) ExecuteCommand added in v0.16.0

func (s *ServiceSchemaPropertyConfigurationStub) ExecuteCommand() error

ExecuteCommand keeps track if the execute command method has been called and returns the configured err ServiceSchemaPropertyConfigurationStub.ServiceSchemaPropertyConfigurationStub if set

func (*ServiceSchemaPropertyConfigurationStub) GetDefaultValue added in v0.16.0

func (s *ServiceSchemaPropertyConfigurationStub) GetDefaultValue() (string, error)

GetDefaultValue returns the default value configured in the ServiceSchemaPropertyConfigurationStub.defaultValue field

type ServiceSchemaPropertyConfigurationV1 added in v0.6.0

type ServiceSchemaPropertyConfigurationV1 struct {
	SchemaPropertyName    string                                       `yaml:"schema_property_name,omitempty"`
	DefaultValue          string                                       `yaml:"default_value,omitempty"`
	Command               []string                                     `yaml:"cmd,flow,omitempty"`
	CommandTimeout        int                                          `yaml:"cmd_timeout,omitempty"`
	ExternalConfiguration ServiceSchemaPropertyExternalConfigurationV1 `yaml:"schema_property_external_configuration,omitempty"`
}

ServiceSchemaPropertyConfigurationV1 implements the ServiceSchemaPropertyConfiguration and defines the different fields supported that enable the configuration of the provider's properties via the terraform-provider-openapi.yaml plugin config file

func (ServiceSchemaPropertyConfigurationV1) ExecuteCommand added in v0.8.0

func (s ServiceSchemaPropertyConfigurationV1) ExecuteCommand() error

ExecuteCommand run the 'Command' configured in the ServiceSchemaPropertyConfigurationV1 struct if applicable. - If the command fails to execute the appropriate error will be returned including the error returned by exec - If the command execution does not finish within the expected time (either before CommandTimeout or before the default timeout 10s) a timeout error will be returned - Otherwise, a nil error will be returned should the command executes successfully with a clean exit code

func (ServiceSchemaPropertyConfigurationV1) GetDefaultValue added in v0.6.0

func (s ServiceSchemaPropertyConfigurationV1) GetDefaultValue() (string, error)

GetDefaultValue returns the default value for the schema property configuration. The following logic defines the preference when deciding what should be the default value of the property: - if the property does not have external configuration ('schema_property_external_configuration') and it does have a 'default_value' is set, then value used will be the one specified in the 'default_value' field - if the property has both the external configuration ('schema_property_external_configuration') and the 'default_value' fields set:

  • If 'file' field is populated then:
  • If the 'content_type' is raw the contents of the 'file' will be used as default value
  • If the 'content_type' is json then the content of the 'file' must be json structure and the default value used will be the one defined in the 'key_name'
  • An error is thrown otherwise

type ServiceSchemaPropertyExternalConfigurationV1 added in v0.6.0

type ServiceSchemaPropertyExternalConfigurationV1 struct {
	// File defines the file containing the value of the schema property
	File string `yaml:"file"`
	// KeyName defines the specific key to look for within the File (only when json content type)
	KeyName string `yaml:"key_name"`
	// ContentType defines the type of content the File has
	ContentType string `yaml:"content_type"` // Currently supported types: raw, json
}

ServiceSchemaPropertyExternalConfigurationV1 defines the external configuration for a provider property.

type SpecAnalyser added in v0.4.0

type SpecAnalyser interface {
	// GetTerraformCompliantResources defines the method that is meant to discover the paths from the OpenAPI document
	// that are considered Terraform compliant, returning a list of SpecResource or an error otherwise.
	GetTerraformCompliantResources() ([]SpecResource, error)
	// GetTerraformCompliantDataSources is responsible for finding endpoints that are deemed terraform data source compatible
	// and returns a list of SpecResource configured as data sources
	GetTerraformCompliantDataSources() []SpecResource
	// GetSecurity returns a SpecSecurity based on the security defined in the OpenAPI document
	GetSecurity() SpecSecurity
	// GetAllHeaderParameters returns SpecHeaderParameters containing all the headers defined in the OpenAPI document. This
	// enabled the OpenAPI provider to expose the headers as configurable properties available in the OpenAPI Terraform
	// provider; so users can provide values for the headers that are meant to be sent along with the operations the headers
	// are defined in.
	GetAllHeaderParameters() SpecHeaderParameters
	// GetAPIBackendConfiguration encapsulates all the information related to the backend in the OpenAPI doc
	// (e,g: host, protocols, etc) which is then used in the ProviderClient to communicate with the API as specified in
	// the configuration.
	GetAPIBackendConfiguration() (SpecBackendConfiguration, error)
}

SpecAnalyser analyses the swagger doc and provides helper methods to retrieve all the end points that can be used as terraform resources. These endpoints have to meet certain criteria to be considered eligible resources as explained below: A resource is considered any end point that meets the following:

  • POST operation on the root path (e,g: api/users)
  • GET operation on the instance path (e,g: api/users/{id}). Other operations like DELETE, PUT are optional

In the example above, the resource name would be 'users'. Versioning is also supported, thus if the endpoint above had been api/v1/users the corresponding resouce name would have been 'users_v1'

func CreateSpecAnalyser added in v0.4.0

func CreateSpecAnalyser(specAnalyserVersion SpecAnalyserVersion, openAPIDocumentURL string) (SpecAnalyser, error)

CreateSpecAnalyser is a factory method that returns the appropriate implementation of SpecAnalyser depending upon the openApiSpecAnalyserVersion passed in. Currently only OpenAPI v2 version is supported but this constructor is ready to handle new implementations such as v3 when the time comes

type SpecAnalyserVersion added in v0.4.0

type SpecAnalyserVersion string

SpecAnalyserVersion defines the type for versions supported in the SpecAnalyser

type SpecBackendConfiguration added in v0.4.0

type SpecBackendConfiguration interface {
	IsMultiRegion() (bool, string, []string, error)
	GetDefaultRegion([]string) (string, error)
	// contains filtered or unexported methods
}

SpecBackendConfiguration defines the behaviour related to the OpenAPI doc backend configuration

type SpecHeaderParam added in v0.4.0

type SpecHeaderParam struct {
	Name          string
	TerraformName string
	IsRequired    bool
}

SpecHeaderParam defines the properties for a Header Parameter

func (SpecHeaderParam) GetHeaderTerraformConfigurationName added in v0.4.0

func (h SpecHeaderParam) GetHeaderTerraformConfigurationName() string

GetHeaderTerraformConfigurationName returns the terraform compliant name of the header. If the header TerraformName field is populated it takes preference over the name field.

type SpecHeaderParameters added in v0.4.0

type SpecHeaderParameters []SpecHeaderParam

SpecHeaderParameters groups a list of SpecHeaderParam

type SpecResource added in v0.4.0

type SpecResource interface {
	GetResourceName() string

	GetResourceSchema() (*SpecSchemaDefinition, error)
	ShouldIgnoreResource() bool

	// GetParentResourceInfo returns a struct populated with relevant ParentResourceInfo if the resource is considered
	// a sub-resource; nil otherwise.
	GetParentResourceInfo() *ParentResourceInfo
	// contains filtered or unexported methods
}

SpecResource defines the behaviour related to terraform compliant OpenAPI Resources.

type SpecSchemaDefinition added in v0.30.0

type SpecSchemaDefinition struct {
	Properties SpecSchemaDefinitionProperties
}

SpecSchemaDefinition defines a struct for a schema definition

func (*SpecSchemaDefinition) ConvertToDataSourceSpecSchemaDefinition added in v0.30.0

func (s *SpecSchemaDefinition) ConvertToDataSourceSpecSchemaDefinition() *SpecSchemaDefinition

ConvertToDataSourceSpecSchemaDefinition transforms the current SpecSchemaDefinition into a data source SpecSchemaDefinition. This means that all the properties that form the schema will be made optional, computed and they won't have default values.

type SpecSchemaDefinitionProperties added in v0.30.0

type SpecSchemaDefinitionProperties []*SpecSchemaDefinitionProperty

SpecSchemaDefinitionProperties defines a collection of schema definition properties

type SpecSchemaDefinitionProperty added in v0.30.0

type SpecSchemaDefinitionProperty struct {
	Name           string
	PreferredName  string
	Type           schemaDefinitionPropertyType
	ArrayItemsType schemaDefinitionPropertyType
	Description    string

	// IgnoreItemsOrder if set to true means that the array items order should be ignored
	IgnoreItemsOrder bool

	Required bool
	// ReadOnly properties are included in responses but not in request
	ReadOnly bool
	// Computed properties describe properties where the value is computed by the API
	Computed bool
	// IsParentProperty defines whether the property is a parent property in which case it will be treated differently in
	// different parts of the code. For instance, the property will not be posted to the API.
	IsParentProperty   bool
	ForceNew           bool
	Sensitive          bool
	Immutable          bool
	IsIdentifier       bool
	IsStatusIdentifier bool
	// EnableLegacyComplexObjectBlockConfiguration defines whether this SpecSchemaDefinitionProperty should be handled with special treatment following
	// the recommendation from hashi maintainers (https://github.com/hashicorp/terraform/issues/22511#issuecomment-522655851)
	// to support complex object types with the legacy SDK (objects that contain properties with different types and configurations
	// like computed properties).
	EnableLegacyComplexObjectBlockConfiguration bool
	// Default field is only for informative purposes to know what the openapi spec for the property stated the default value is
	// As per the openapi spec default attributes, the value is expected to be computed by the API
	Default interface{}
	// only for object type properties or arrays type properties with array items of type object
	SpecSchemaDefinition *SpecSchemaDefinition
}

SpecSchemaDefinitionProperty defines the attributes for a schema property

func (*SpecSchemaDefinitionProperty) GetTerraformCompliantPropertyName added in v0.30.0

func (s *SpecSchemaDefinitionProperty) GetTerraformCompliantPropertyName() string

GetTerraformCompliantPropertyName returns the property name converted to a terraform compliant name if needed following the snake_case naming convention

func (*SpecSchemaDefinitionProperty) IsOptionalComputed added in v0.30.0

func (s *SpecSchemaDefinitionProperty) IsOptionalComputed() bool

IsOptionalComputed returns true for properties that are optional and a value (not known at plan time) is computed by the API if the client does not provide a value. In order for a property to be considered optional computed it must meet: - The property must be optional, not readOnly, computed and must not have a default value populated Note: optional-computed properties (marked as readOnly=false, computed=true, default={some value}) are not considered as optional computed since the way they will be treated as far as the terraform schema will differ. The terraform schema property for this properties will contain the default value and the property will not be computed

func (*SpecSchemaDefinitionProperty) IsRequired added in v0.30.0

func (s *SpecSchemaDefinitionProperty) IsRequired() bool

IsRequired exposes whether a property is required

type SpecSecurity added in v0.4.0

type SpecSecurity interface {
	// GetAPIKeySecurityDefinitions returns all the OpenAPI security definitions from the OpenAPI document and translates those
	// into SpecSecurityDefinitions
	GetAPIKeySecurityDefinitions() (*SpecSecurityDefinitions, error)
	// GetGlobalSecuritySchemes returns all the global security schemes from the OpenAPI document and translates those
	// into SpecSecuritySchemes
	GetGlobalSecuritySchemes() (SpecSecuritySchemes, error)
}

SpecSecurity defines the behaviour related to OpenAPI security. This interface serves as a translation between the OpenAPI document and the security spec that will be used by the OpenAPI Terraform provider

type SpecSecurityDefinition added in v0.4.0

type SpecSecurityDefinition interface {

	// GetTerraformConfigurationName returns the name converted terraform compliant name (snake_case) if needed
	GetTerraformConfigurationName() string
	// contains filtered or unexported methods
}

SpecSecurityDefinition defines the behaviour expected for security definition implementations. This interface creates an abstraction between the swagger security definitions and the openapi provider removing dependencies in external libraries

type SpecSecurityDefinitions added in v0.4.0

type SpecSecurityDefinitions []SpecSecurityDefinition

SpecSecurityDefinitions groups a list of SpecSecurityDefinition

type SpecSecurityScheme added in v0.4.0

type SpecSecurityScheme struct {
	Name string
}

SpecSecurityScheme defines a security scheme. This struct serves as a translation between the OpenAPI document and the scheme that will be used by the OpenAPI Terraform provider when making API calls to the backend

func (*SpecSecurityScheme) GetTerraformConfigurationName added in v0.30.0

func (o *SpecSecurityScheme) GetTerraformConfigurationName() string

GetTerraformConfigurationName returns the scheme name converted to a terraform compliant name if needed following the snake_case naming convention

type SpecSecuritySchemes added in v0.4.0

type SpecSecuritySchemes []SpecSecurityScheme

SpecSecuritySchemes groups a list of SpecSecurityScheme

type SpecV2Resource added in v0.4.0

type SpecV2Resource struct {
	Name   string
	Region string
	// Path contains the full relative path to the resource e,g: /v1/resource
	Path string
	// SpecSchemaDefinition definition represents the representational state (aka model) of the resource
	SchemaDefinition spec.Schema
	// RootPathItem contains info about the resource root path e,g: /resource, including the POST operation used to create instances of this resource
	RootPathItem spec.PathItem
	// InstancePathItem contains info about the resource's instance /resource/{id}, including GET, PUT and REMOVE operations if applicable
	InstancePathItem spec.PathItem

	// SchemaDefinitions contains all the definitions which might be needed in case the resource schema contains properties
	// of type object which in turn refer to other definitions
	SchemaDefinitions map[string]spec.Schema

	Paths map[string]spec.PathItem
	// contains filtered or unexported fields
}

SpecV2Resource defines a struct that implements the SpecResource interface and it's based on OpenAPI v2 specification

func (*SpecV2Resource) GetParentResourceInfo added in v0.30.0

func (o *SpecV2Resource) GetParentResourceInfo() *ParentResourceInfo

GetParentResourceInfo returns the information about the parent resources

func (*SpecV2Resource) GetResourceName added in v0.30.0

func (o *SpecV2Resource) GetResourceName() string

GetResourceName returns the resource name including the region at the end of the resource name if applicable

func (*SpecV2Resource) GetResourceSchema added in v0.30.0

func (o *SpecV2Resource) GetResourceSchema() (*SpecSchemaDefinition, error)

GetResourceSchema returns the resource schema

func (*SpecV2Resource) ShouldIgnoreResource added in v0.30.0

func (o *SpecV2Resource) ShouldIgnoreResource() bool

ShouldIgnoreResource checks whether the POST operation for a given resource as the 'x-terraform-exclude-resource' extension defined with true value. If so, the resource will not be exposed to the OpenAPI Terraform provider; otherwise it will be exposed and users will be able to manage such resource via terraform.

type TelemetryConfig added in v0.26.0

type TelemetryConfig struct {
	// Graphite defines the configuration needed to ship telemetry to Graphite
	Graphite *TelemetryProviderGraphite `yaml:"graphite,omitempty"`
	// HTTPEndpoint defines the configuration needed to ship telemetry to an http endpoint
	HTTPEndpoint *TelemetryProviderHTTPEndpoint `yaml:"http_endpoint,omitempty"`
}

TelemetryConfig contains the configuration for the telemetry

type TelemetryHandler added in v0.26.0

type TelemetryHandler interface {
	// SubmitPluginExecutionMetrics submits the metrics for the total number of times the plugin and specific OpenAPI plugin version
	// have been executed
	SubmitPluginExecutionMetrics()
	// SubmitResourceExecutionMetrics submits the metrics related to resource operation execution
	SubmitResourceExecutionMetrics(resourceName string, tfOperation TelemetryResourceOperation)
}

TelemetryHandler is responsible for making sure that metrics are shipped to all the telemetry providers registered and also ensures that metrics submissions are configured with timeouts. Hence, if the telemetry provider is taking longer than the timeout set or it errors when sending the metric, the provider execution will not be affected by it and the corresponding error will be logged for the reference

type TelemetryProvider added in v0.26.0

type TelemetryProvider interface {
	// Validate performs a check to confirm that the telemetry configuration is valid
	Validate() error
	// IncOpenAPIPluginVersionTotalRunsCounter is the method responsible for submitting to the corresponding telemetry platform the counter increase for the OpenAPI plugin Version used
	IncOpenAPIPluginVersionTotalRunsCounter(openAPIPluginVersion string, telemetryProviderConfiguration TelemetryProviderConfiguration) error
	// IncServiceProviderResourceTotalRunsCounter is the method responsible for submitting to the corresponding telemetry platform the counter increase for service provider used along
	// with tags for provider name, resource name, and Terraform operation
	IncServiceProviderResourceTotalRunsCounter(providerName, resourceName string, tfOperation TelemetryResourceOperation, telemetryProviderConfiguration TelemetryProviderConfiguration) error
	// GetTelemetryProviderConfiguration is the method responsible for getting a specific telemetry provider config given the input data provided
	GetTelemetryProviderConfiguration(data *schema.ResourceData) TelemetryProviderConfiguration
}

TelemetryProvider holds the behaviour expected to be implemented for the Telemetry Providers supported. At the moment only Graphite is supported.

type TelemetryProviderConfiguration added in v0.28.0

type TelemetryProviderConfiguration interface{}

TelemetryProviderConfiguration defines the struct type that specific telemetry providers can configure based on the resource data received in GetTelemetryProviderConfiguration. The struct serves as a way to document in the metric methods signature (eg: IncOpenAPIPluginVersionTotalRunsCounter) that a specific telemetry provider configuration struct can be passed in if needed

type TelemetryProviderGraphite added in v0.26.0

type TelemetryProviderGraphite struct {
	// Host describes the graphite host (fqdn)
	Host string `yaml:"host"`
	// Port describes the port to where metrics will be pushed in Graphite
	Port int `yaml:"port"`
	// Prefix enables to append a prefix to the metrics pushed to graphite
	Prefix string `yaml:"prefix,omitempty"`
}

TelemetryProviderGraphite defines the configuration for Graphite. This struct also implements the TelemetryProvider interface and ships metrics to the following namespace by default statsd.<prefix>.terraform.* where '<prefix>' can be configured.

func (TelemetryProviderGraphite) GetTelemetryProviderConfiguration added in v0.28.0

func (g TelemetryProviderGraphite) GetTelemetryProviderConfiguration(data *schema.ResourceData) TelemetryProviderConfiguration

GetTelemetryProviderConfiguration returns nil since Graphite does not need any TelemetryProviderConfiguration at the moment

func (TelemetryProviderGraphite) IncOpenAPIPluginVersionTotalRunsCounter added in v0.26.0

func (g TelemetryProviderGraphite) IncOpenAPIPluginVersionTotalRunsCounter(openAPIPluginVersion string, telemetryProviderConfiguration TelemetryProviderConfiguration) error

IncOpenAPIPluginVersionTotalRunsCounter will increment the counter 'statsd.<prefix>.terraform.openapi_plugin_version.total_runs' metric to 1 and appends a tag containing the 'openapi_plugin_version' used.

func (TelemetryProviderGraphite) IncServiceProviderResourceTotalRunsCounter added in v0.28.0

func (g TelemetryProviderGraphite) IncServiceProviderResourceTotalRunsCounter(providerName, resourceName string, tfOperation TelemetryResourceOperation, telemetryProviderConfiguration TelemetryProviderConfiguration) error

IncServiceProviderResourceTotalRunsCounter will increment the counter for a given provider 'statsd.<prefix>.terraform.provider' metric to 1 and appends tags containing the 'provider_name', 'resource_name', and 'terraform_operation' called

func (TelemetryProviderGraphite) Validate added in v0.26.0

func (g TelemetryProviderGraphite) Validate() error

Validate checks whether the provider is configured correctly. This validation is performed upon telemetry provider registration. If this method returns an error the error will be logged but the telemetry will be disabled. Otherwise, the telemetry will be enabled and the corresponding metrics will be shipped to Graphite

type TelemetryProviderHTTPEndpoint added in v0.27.0

type TelemetryProviderHTTPEndpoint struct {
	// URL describes the HTTP endpoint to send the metric to
	URL string `yaml:"url"`
	// Prefix enables to append a prefix to the metrics pushed to the HTTP endpoint
	Prefix string `yaml:"prefix,omitempty"`
	// ProviderSchemaProperties defines what specific provider configuration properties and their values that will be injected into
	// metric API request headers. Values must match a real property name in provider schema configuration.
	ProviderSchemaProperties []string `yaml:"provider_schema_properties,omitempty"`
}

TelemetryProviderHTTPEndpoint defines the configuration for HTTPEndpoint. This struct also implements the TelemetryProvider interface and ships metrics to the following namespace by default <prefix>.terraform.* where '<prefix>' can be configured.

func (TelemetryProviderHTTPEndpoint) GetTelemetryProviderConfiguration added in v0.28.0

func (g TelemetryProviderHTTPEndpoint) GetTelemetryProviderConfiguration(data *schema.ResourceData) TelemetryProviderConfiguration

GetTelemetryProviderConfiguration returns a telemetryProviderConfigurationHTTPEndpoint loaded with headers mapping to the plugin configuration schema properties that match the ones specified in the TelemetryProviderHTTPEndpoint ProviderSchemaProperties values

func (TelemetryProviderHTTPEndpoint) IncOpenAPIPluginVersionTotalRunsCounter added in v0.27.0

func (g TelemetryProviderHTTPEndpoint) IncOpenAPIPluginVersionTotalRunsCounter(openAPIPluginVersion string, telemetryProviderConfiguration TelemetryProviderConfiguration) error

IncOpenAPIPluginVersionTotalRunsCounter will submit an increment to 1 the metric type counter '<prefix>.terraform.openapi_plugin_version.total_runs' including any other tag present in the TelemetryProviderConfiguration.

func (TelemetryProviderHTTPEndpoint) IncServiceProviderResourceTotalRunsCounter added in v0.28.0

func (g TelemetryProviderHTTPEndpoint) IncServiceProviderResourceTotalRunsCounter(providerName, resourceName string, tfOperation TelemetryResourceOperation, telemetryProviderConfiguration TelemetryProviderConfiguration) error

IncServiceProviderResourceTotalRunsCounter will submit an increment to 1 the metric type counter '<prefix>.terraform.provider'. In addition, it will send tags with the provider name, resource name, and terrraform operation called.

func (TelemetryProviderHTTPEndpoint) Validate added in v0.27.0

func (g TelemetryProviderHTTPEndpoint) Validate() error

Validate checks whether the provider is configured correctly. This validation is performed upon telemetry provider registration. If this method returns an error the error will be logged but the telemetry will be disabled. Otherwise, the telemetry will be enabled and the corresponding metrics will be shipped to Graphite

type TelemetryResourceOperation added in v0.28.0

type TelemetryResourceOperation string

TelemetryResourceOperation defines the resource operation (CRUD) to be used in the telemetry metric

const (
	// TelemetryResourceOperationCreate represents the create operation invocation
	TelemetryResourceOperationCreate TelemetryResourceOperation = "create"
	// TelemetryResourceOperationRead represents the read operation invocation
	TelemetryResourceOperationRead TelemetryResourceOperation = "read"
	// TelemetryResourceOperationUpdate represents the update operation invocation
	TelemetryResourceOperationUpdate TelemetryResourceOperation = "update"
	// TelemetryResourceOperationDelete represents the delete operation invocation
	TelemetryResourceOperationDelete TelemetryResourceOperation = "delete"
	// TelemetryResourceOperationImport represents the import operation invocation
	TelemetryResourceOperationImport TelemetryResourceOperation = "import"
)

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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