Skip to content

Commit

Permalink
provider: rearrange files to ease reading/addition
Browse files Browse the repository at this point in the history
The known providers are now put into a separated files, which helps with
adding new supported one to the default list.
  • Loading branch information
Hugo Rosnet committed Aug 20, 2021
1 parent de17200 commit db5159d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
9 changes: 2 additions & 7 deletions estimation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/spf13/afero"

"github.com/cycloidio/terracost/aws"
"github.com/cycloidio/terracost/cost"
"github.com/cycloidio/terracost/terraform"
)
Expand All @@ -16,9 +15,7 @@ import (
// It uses the Backend to retrieve the pricing data.
func EstimateTerraformPlan(ctx context.Context, backend Backend, plan io.Reader, providerInitializers ...terraform.ProviderInitializer) (*cost.Plan, error) {
if len(providerInitializers) == 0 {
providerInitializers = []terraform.ProviderInitializer{
aws.TerraformProviderInitializer,
}
providerInitializers = getDefaultProviders()
}

tfplan := terraform.NewPlan(providerInitializers...)
Expand Down Expand Up @@ -52,9 +49,7 @@ func EstimateTerraformPlan(ctx context.Context, backend Backend, plan io.Reader,
// It uses the Backend to retrieve the pricing data.
func EstimateHCL(ctx context.Context, backend Backend, fs afero.Fs, path string, providerInitializers ...terraform.ProviderInitializer) (*cost.Plan, error) {
if len(providerInitializers) == 0 {
providerInitializers = []terraform.ProviderInitializer{
aws.TerraformProviderInitializer,
}
providerInitializers = getDefaultProviders()
}

plannedQueries, err := terraform.ExtractQueriesFromHCL(fs, providerInitializers, path)
Expand Down
16 changes: 16 additions & 0 deletions provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package terracost

import (
"github.com/cycloidio/terracost/aws"
"github.com/cycloidio/terracost/terraform"
)

// defaultProviders are the currently known and supported terraform providers
var defaultProviders = []terraform.ProviderInitializer{
aws.TerraformProviderInitializer,
}

// getDefaultProviders will return the default supported providers of terracost
func getDefaultProviders() []terraform.ProviderInitializer {
return defaultProviders
}

0 comments on commit db5159d

Please sign in to comment.