Documentation ¶
Index ¶
- Constants
- type ClientOpenAPI
- type MetricSubmitter
- type ParentResourceInfo
- type PluginConfigSchema
- type PluginConfigSchemaV1
- func (p *PluginConfigSchemaV1) GetAllServiceConfigurations() (ServiceConfigurations, error)
- func (p *PluginConfigSchemaV1) GetServiceConfig(providerName string) (ServiceConfiguration, error)
- func (p *PluginConfigSchemaV1) GetVersion() (string, error)
- func (p *PluginConfigSchemaV1) Marshal() ([]byte, error)
- func (p *PluginConfigSchemaV1) Validate() error
- type PluginConfiguration
- type ProviderClient
- func (o *ProviderClient) Delete(resource SpecResource, id string, parentIDs ...string) (*http.Response, error)
- func (o *ProviderClient) Get(resource SpecResource, id string, responsePayload interface{}, ...) (*http.Response, error)
- func (o *ProviderClient) GetTelemetryHandler() TelemetryHandler
- func (o *ProviderClient) List(resource SpecResource, responsePayload interface{}, parentIDs ...string) (*http.Response, error)
- func (o *ProviderClient) Post(resource SpecResource, requestPayload interface{}, responsePayload interface{}, ...) (*http.Response, error)
- func (o *ProviderClient) Put(resource SpecResource, id string, requestPayload interface{}, ...) (*http.Response, error)
- type ProviderOpenAPI
- type ServiceConfigStub
- func (s ServiceConfigStub) GetSchemaPropertyConfiguration(schemaPropertyName string) ServiceSchemaPropertyConfiguration
- func (s *ServiceConfigStub) GetSwaggerURL() string
- func (s ServiceConfigStub) GetTelemetryConfiguration() TelemetryProvider
- func (s *ServiceConfigStub) IsInsecureSkipVerifyEnabled() bool
- func (s *ServiceConfigStub) Validate() error
- type ServiceConfigV1
- func (s *ServiceConfigV1) GetSchemaPropertyConfiguration(schemaPropertyName string) ServiceSchemaPropertyConfiguration
- func (s *ServiceConfigV1) GetSwaggerURL() string
- func (s *ServiceConfigV1) GetTelemetryConfiguration() TelemetryProvider
- func (s *ServiceConfigV1) IsInsecureSkipVerifyEnabled() bool
- func (s *ServiceConfigV1) Validate() error
- type ServiceConfiguration
- type ServiceConfigurations
- type ServiceSchemaPropertyConfiguration
- type ServiceSchemaPropertyConfigurationStub
- type ServiceSchemaPropertyConfigurationV1
- type ServiceSchemaPropertyExternalConfigurationV1
- type SpecAnalyser
- type SpecAnalyserVersion
- type SpecBackendConfiguration
- type SpecHeaderParam
- type SpecHeaderParameters
- type SpecResource
- type SpecSchemaDefinition
- type SpecSchemaDefinitionProperties
- type SpecSchemaDefinitionProperty
- type SpecSecurity
- type SpecSecurityDefinition
- type SpecSecurityDefinitions
- type SpecSecurityScheme
- type SpecSecuritySchemes
- type SpecV2Resource
- type TelemetryConfig
- type TelemetryHandler
- type TelemetryProvider
- type TelemetryProviderConfiguration
- type TelemetryProviderGraphite
- func (g TelemetryProviderGraphite) GetTelemetryProviderConfiguration(data *schema.ResourceData) TelemetryProviderConfiguration
- func (g TelemetryProviderGraphite) IncOpenAPIPluginVersionTotalRunsCounter(openAPIPluginVersion string, ...) error
- func (g TelemetryProviderGraphite) IncServiceProviderResourceTotalRunsCounter(providerName, resourceName string, tfOperation TelemetryResourceOperation, ...) error
- func (g TelemetryProviderGraphite) Validate() error
- type TelemetryProviderHTTPEndpoint
- func (g TelemetryProviderHTTPEndpoint) GetTelemetryProviderConfiguration(data *schema.ResourceData) TelemetryProviderConfiguration
- func (g TelemetryProviderHTTPEndpoint) IncOpenAPIPluginVersionTotalRunsCounter(openAPIPluginVersion string, ...) error
- func (g TelemetryProviderHTTPEndpoint) IncServiceProviderResourceTotalRunsCounter(providerName, resourceName string, tfOperation TelemetryResourceOperation, ...) error
- func (g TelemetryProviderHTTPEndpoint) Validate() error
- type TelemetryResourceOperation
Constants ¶
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" )
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 ¶
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 ¶
type MetricSubmitter func() error
MetricSubmitter is the function holding the logic that actually submits the metric
type ParentResourceInfo ¶
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 ¶
func (info *ParentResourceInfo) GetParentPropertiesNames() []string
GetParentPropertiesNames is responsible to building the parent properties names for a resource that is a subresource
func (*ParentResourceInfo) SetParentResourceNames ¶
func (info *ParentResourceInfo) SetParentResourceNames(parentResourceNames []string)
SetParentResourceNames sets the resource parent names
type PluginConfigSchema ¶
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 ¶
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 insecure_skip_verify: true cdn: swagger-url: https://cdn-api.com/swagger.json vm: swagger-url: http://vm-api.com/swagger.json
func NewPluginConfigSchemaV1 ¶
func NewPluginConfigSchemaV1(services map[string]*ServiceConfigV1) *PluginConfigSchemaV1
NewPluginConfigSchemaV1 creates a new PluginConfigSchemaV1 that implements PluginConfigSchema interface
func (*PluginConfigSchemaV1) GetAllServiceConfigurations ¶
func (p *PluginConfigSchemaV1) GetAllServiceConfigurations() (ServiceConfigurations, error)
GetAllServiceConfigurations returns all the service configuration
func (*PluginConfigSchemaV1) GetServiceConfig ¶
func (p *PluginConfigSchemaV1) GetServiceConfig(providerName string) (ServiceConfiguration, error)
GetServiceConfig returns the configuration for the given provider name
func (*PluginConfigSchemaV1) GetVersion ¶
func (p *PluginConfigSchemaV1) GetVersion() (string, error)
GetVersion returns the plugin configuration version
func (*PluginConfigSchemaV1) Marshal ¶
func (p *PluginConfigSchemaV1) Marshal() ([]byte, error)
Marshal serializes the value provided into a YAML document
func (*PluginConfigSchemaV1) Validate ¶
func (p *PluginConfigSchemaV1) Validate() error
Validate makes sure that schema data is correct
type PluginConfiguration ¶
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 ¶
func NewPluginConfiguration(providerName string) (*PluginConfiguration, error)
NewPluginConfiguration creates a new PluginConfiguration
type ProviderClient ¶
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 ¶
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 ¶
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 ¶
func (o *ProviderClient) GetTelemetryHandler() TelemetryHandler
GetTelemetryHandler returns the configured telemetry handler
func (*ProviderClient) List ¶
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 ¶
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 ¶
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 ¶
type ProviderOpenAPI struct { ProviderName string // contains filtered or unexported fields }
ProviderOpenAPI defines the struct for the OpenAPI Terraform Provider
func (*ProviderOpenAPI) CreateSchemaProvider ¶
func (p *ProviderOpenAPI) CreateSchemaProvider() (*schema.Provider, error)
CreateSchemaProvider returns a terraform.ResourceProvider.
func (*ProviderOpenAPI) CreateSchemaProviderFromServiceConfiguration ¶
func (p *ProviderOpenAPI) CreateSchemaProviderFromServiceConfiguration(serviceConfiguration ServiceConfiguration) (*schema.Provider, error)
CreateSchemaProviderFromServiceConfiguration helper function to enable creation of schema.Provider with the given serviceConfiguration
type ServiceConfigStub ¶
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) GetSchemaPropertyConfiguration ¶
func (s ServiceConfigStub) GetSchemaPropertyConfiguration(schemaPropertyName string) ServiceSchemaPropertyConfiguration
GetSchemaPropertyConfiguration returns the service schema configuration set in the ServiceConfigStub.SchemaConfiguration field
func (*ServiceConfigStub) GetSwaggerURL ¶
func (s *ServiceConfigStub) GetSwaggerURL() string
GetSwaggerURL returns the swagger URL value configured in the ServiceConfigStub.SwaggerURL field
func (ServiceConfigStub) GetTelemetryConfiguration ¶
func (s ServiceConfigStub) GetTelemetryConfiguration() TelemetryProvider
GetTelemetryConfiguration returns the TelemetryProvider configured in the ServiceConfigStub
func (*ServiceConfigStub) IsInsecureSkipVerifyEnabled ¶
func (s *ServiceConfigStub) IsInsecureSkipVerifyEnabled() bool
IsInsecureSkipVerifyEnabled returns the bool configured in the ServiceConfigStub.InsecureSkipVerify field
func (*ServiceConfigStub) Validate ¶
func (s *ServiceConfigStub) Validate() error
Validate returns an error if the ServiceConfigStub.Err field is set with an error
type ServiceConfigV1 ¶
type ServiceConfigV1 struct { // SwaggerURL defines where the swagger is located SwaggerURL string `yaml:"swagger-url"` // 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 ¶
func NewServiceConfigV1(swaggerURL string, insecureSkipVerifyEnabled bool, telemetryConfig *TelemetryConfig) *ServiceConfigV1
NewServiceConfigV1 creates a new instance of NewServiceConfigV1 struct with the values provided
func (*ServiceConfigV1) GetSchemaPropertyConfiguration ¶
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 ¶
func (s *ServiceConfigV1) GetSwaggerURL() string
GetSwaggerURL returns the URL where the service swagger doc is exposed
func (*ServiceConfigV1) GetTelemetryConfiguration ¶
func (s *ServiceConfigV1) GetTelemetryConfiguration() TelemetryProvider
GetTelemetryConfiguration returns a TelemetryProvider configured for Graphite or HTTPEndpoint
func (*ServiceConfigV1) IsInsecureSkipVerifyEnabled ¶
func (s *ServiceConfigV1) IsInsecureSkipVerifyEnabled() bool
IsInsecureSkipVerifyEnabled returns true if the given provider's service configuration has InsecureSkipVerify enabled; false otherwise
func (*ServiceConfigV1) Validate ¶
func (s *ServiceConfigV1) Validate() error
Validate makes sure the configuration is valid:
type ServiceConfiguration ¶
type ServiceConfiguration interface { // GetSwaggerURL returns the URL where the service swagger doc is exposed GetSwaggerURL() 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() error // GetTelemetryConfiguration returns the telemetry configuration for this service provider GetTelemetryConfiguration() TelemetryProvider }
ServiceConfiguration defines the interface/expected behaviour for ServiceConfiguration implementations.
type ServiceConfigurations ¶
type ServiceConfigurations map[string]ServiceConfiguration
ServiceConfigurations contains the map with all service configurations
type ServiceSchemaPropertyConfiguration ¶
type ServiceSchemaPropertyConfiguration interface { GetDefaultValue() (string, error) ExecuteCommand() error }
ServiceSchemaPropertyConfiguration defines the behaviour expected for the service schema property configuration
type ServiceSchemaPropertyConfigurationStub ¶
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 ¶
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 ¶
func (s *ServiceSchemaPropertyConfigurationStub) GetDefaultValue() (string, error)
GetDefaultValue returns the default value configured in the ServiceSchemaPropertyConfigurationStub.defaultValue field
type ServiceSchemaPropertyConfigurationV1 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
type SpecAnalyserVersion string
SpecAnalyserVersion defines the type for versions supported in the SpecAnalyser
type SpecBackendConfiguration ¶
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 ¶
SpecHeaderParam defines the properties for a Header Parameter
func (SpecHeaderParam) GetHeaderTerraformConfigurationName ¶
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 ¶
type SpecHeaderParameters []SpecHeaderParam
SpecHeaderParameters groups a list of SpecHeaderParam
type SpecResource ¶
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 ¶
type SpecSchemaDefinition struct {
Properties SpecSchemaDefinitionProperties
}
SpecSchemaDefinition defines a struct for a schema definition
func (*SpecSchemaDefinition) ConvertToDataSourceSpecSchemaDefinition ¶
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 ¶
type SpecSchemaDefinitionProperties []*SpecSchemaDefinitionProperty
SpecSchemaDefinitionProperties defines a collection of schema definition properties
type SpecSchemaDefinitionProperty ¶
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 // 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 ¶
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 ¶
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) IsOptionalComputedWithDefault ¶
func (s *SpecSchemaDefinitionProperty) IsOptionalComputedWithDefault() bool
IsOptionalComputedWithDefault returns true for properties that are optional and a value (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 have a default value populated
func (*SpecSchemaDefinitionProperty) IsRequired ¶
func (s *SpecSchemaDefinitionProperty) IsRequired() bool
IsRequired exposes whether a property is required
type SpecSecurity ¶
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 ¶
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 ¶
type SpecSecurityDefinitions []SpecSecurityDefinition
SpecSecurityDefinitions groups a list of SpecSecurityDefinition
type SpecSecurityScheme ¶
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 ¶
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 ¶
type SpecSecuritySchemes []SpecSecurityScheme
SpecSecuritySchemes groups a list of SpecSecurityScheme
type SpecV2Resource ¶
type SpecV2Resource struct { Name 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 ¶
func (o *SpecV2Resource) GetParentResourceInfo() *ParentResourceInfo
GetParentResourceInfo returns the information about the parent resources
func (*SpecV2Resource) GetResourceName ¶
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 ¶
func (o *SpecV2Resource) GetResourceSchema() (*SpecSchemaDefinition, error)
GetResourceSchema returns the resource schema
func (*SpecV2Resource) ShouldIgnoreResource ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (g TelemetryProviderGraphite) GetTelemetryProviderConfiguration(data *schema.ResourceData) TelemetryProviderConfiguration
GetTelemetryProviderConfiguration returns nil since Graphite does not need any TelemetryProviderConfiguration at the moment
func (TelemetryProviderGraphite) IncOpenAPIPluginVersionTotalRunsCounter ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
- common.go
- data_source_factory.go
- data_source_instance_factory.go
- headers.go
- openapi_client.go
- openapi_client_stub.go
- openapi_spec_analyser.go
- openapi_spec_analyser_stub.go
- openapi_spec_authenticator.go
- openapi_spec_authenticator_api.go
- openapi_spec_authenticator_apikey.go
- openapi_spec_authenticator_apikey_header.go
- openapi_spec_authenticator_apikey_query.go
- openapi_spec_authenticator_refresh_token.go
- openapi_spec_backend_configuration.go
- openapi_spec_header.go
- openapi_spec_resource.go
- openapi_spec_resource_operations.go
- openapi_spec_resource_responses.go
- openapi_spec_resource_schema_definition.go
- openapi_spec_resource_schema_definition_property.go
- openapi_spec_security.go
- openapi_spec_security_definition_apikey_header.go
- openapi_spec_security_definition_apikey_header_bearer.go
- openapi_spec_security_definition_apikey_query.go
- openapi_spec_security_definition_apikey_query_bearer.go
- openapi_spec_security_definition_apikey_refresh_token.go
- openapi_spec_security_definition_spec_apikey.go
- openapi_spec_security_definitions.go
- openapi_spec_security_schemes.go
- openapi_spec_security_stub.go
- openapi_spec_subresource_info.go
- openapi_stub_authenticator.go
- openapi_stub_backend_configuration.go
- openapi_stub_resource.go
- openapi_v2_backend_configuration.go
- openapi_v2_headers.go
- openapi_v2_resource.go
- openapi_v2_security.go
- openapi_v2_spec_analyser.go
- plugin_config.go
- plugin_config_schema.go
- plugin_config_services.go
- plugin_config_services_schema_property_configuration.go
- plugin_config_services_stub.go
- plugin_config_telemetry.go
- plugin_config_telemetry_handler.go
- plugin_config_telemetry_handler_stub.go
- plugin_config_telemetry_provider_graphite.go
- plugin_config_telemetry_provider_httpendpoint.go
- plugin_config_telemetry_provider_stub.go
- provider.go
- provider_configuration.go
- provider_configuration_endpoints.go
- provider_factory.go
- resource_factory.go
- utils.go