aws

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package aws enables cost estimation of AWS resources and ingestion of pricing data from AWS.

It should not be used directly by consumers, instead, please use the costestimation package. This package contains implementations of Ingester and TerraformProviderInitializer that are used internally by other packages.

Index

Constants

View Source
const (
	// RegistryName is the fully qualified name under which this provider is stored in the registry.
	RegistryName = "registry.terraform.io/hashicorp/aws"

	// DefaultRegion is the region used by default when none is defined on the provider
	DefaultRegion = "us-east-1"
)
View Source
const ProviderName = "aws"

ProviderName uniquely identifies this provider implementation.

Variables

View Source
var TerraformProviderInitializer = terraform.ProviderInitializer{
	MatchNames: []string{ProviderName, RegistryName},
	Provider: func(values map[string]interface{}) (terraform.Provider, error) {
		r, ok := values["region"]

		if !ok {
			r = DefaultRegion
		}
		regCode := region.Code(r.(string))
		return awstf.NewProvider(ProviderName, regCode)
	},
}

TerraformProviderInitializer is a terraform.ProviderInitializer that initializes the default AWS provider.

Functions

func DefaultFilter

func DefaultFilter(_ *price.WithProduct) bool

DefaultFilter ingests all the records without filtering.

func GetSupportedServices

func GetSupportedServices() []string

GetSupportedServices returns all the AWS service names that Terracost supports.

func IsServiceSupported

func IsServiceSupported(service string) bool

IsServiceSupported returns true if the AWS service is valid and supported by Terracost (e.g. for ingestion.)

func MinimalFilter

func MinimalFilter(pp *price.WithProduct) bool

MinimalFilter only ingests the supported records, skipping those that would never be used.

Types

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

HTTPClient is an interface of a client that is able to Do HTTP requests

type Ingester

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

Ingester is used to load the pricing data from AWS offer files into a database. It is one-use only and should be discarded after the ingestion is complete.

func NewIngester

func NewIngester(service, region string, options ...Option) (*Ingester, error)

NewIngester returns a new Ingester using the given options. Only the repositories must be provided using the WithRepositories function, other configuration options will use their default values. The service must be a valid AWS service name that is supported by Terracost, otherwise this function will return an error.

func (*Ingester) Err

func (ing *Ingester) Err() error

Err returns any error that might have happened during the ingestion.

func (*Ingester) Ingest

func (ing *Ingester) Ingest(ctx context.Context, chSize int) <-chan *price.WithProduct

Ingest starts a goroutine that reads pricing data from AWS and, for the duration of the context, sends the results to the returned channel.

type IngestionFilter

type IngestionFilter func(pp *price.WithProduct) bool

IngestionFilter allows control over what pricing data is ingested. Given a price.WithProduct the function returns true if the record should be ingested, false if it should be skipped.

type Option

type Option func(ing *Ingester)

Option is used to configure the Ingester.

func WithBufferSize

func WithBufferSize(size uint) Option

WithBufferSize sets the I/O buffer size for the downloaded file, 100 MiB by default.

func WithHTTPClient

func WithHTTPClient(client HTTPClient) Option

WithHTTPClient sets a custom HTTP client to be used for offer file downloads.

func WithIngestionFilter

func WithIngestionFilter(filter IngestionFilter) Option

WithIngestionFilter sets a custom IngestionFilter to control which pricing data records should be ingested.

func WithPricingURL

func WithPricingURL(url string) Option

WithPricingURL sets the base AWS pricing URL, "https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws" by default.

func WithProgress

func WithProgress(progressCh chan<- progress.Progress, interval time.Duration) Option

WithProgress sets a channel for receiving progress updates. By default progress is not sent.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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