driftctl/pkg/remote/aws/provider.go

87 lines
2.0 KiB
Go
Raw Normal View History

2021-02-09 13:53:57 +00:00
package aws
import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/cloudskiff/driftctl/pkg/output"
2021-02-09 13:53:57 +00:00
"github.com/cloudskiff/driftctl/pkg/remote/terraform"
tf "github.com/cloudskiff/driftctl/pkg/terraform"
)
type awsConfig struct {
AccessKey string
SecretKey string
CredsFilename string
Profile string
Token string
Region string `cty:"region"`
MaxRetries int
AssumeRoleARN string
AssumeRoleExternalID string
AssumeRoleSessionName string
AssumeRolePolicy string
AllowedAccountIds []string
ForbiddenAccountIds []string
Endpoints map[string]string
IgnoreTagsConfig map[string]string
Insecure bool
SkipCredsValidation bool
SkipGetEC2Platforms bool
SkipRegionValidation bool
SkipRequestingAccountId bool
SkipMetadataApiCheck bool
S3ForcePathStyle bool
}
type AWSTerraformProvider struct {
*terraform.TerraformProvider
session *session.Session
2021-06-28 09:00:59 +00:00
name string
version string
2021-02-09 13:53:57 +00:00
}
func NewAWSTerraformProvider(version string, progress output.Progress, configDir string) (*AWSTerraformProvider, error) {
2021-06-28 09:00:59 +00:00
p := &AWSTerraformProvider{
version: version,
name: "aws",
}
2021-02-09 13:53:57 +00:00
installer, err := tf.NewProviderInstaller(tf.ProviderConfig{
2021-06-28 09:00:59 +00:00
Key: p.name,
Version: version,
ConfigDir: configDir,
2021-02-09 13:53:57 +00:00
})
if err != nil {
return nil, err
}
p.session = session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
tfProvider, err := terraform.NewTerraformProvider(installer, terraform.TerraformProviderConfig{
2021-06-28 09:00:59 +00:00
Name: p.name,
2021-02-09 13:53:57 +00:00
DefaultAlias: *p.session.Config.Region,
GetProviderConfig: func(alias string) interface{} {
return awsConfig{
Region: alias,
MaxRetries: 10, // TODO make this configurable
}
},
}, progress)
2021-02-09 13:53:57 +00:00
if err != nil {
return nil, err
}
p.TerraformProvider = tfProvider
return p, err
}
2021-06-28 09:00:59 +00:00
func (a *AWSTerraformProvider) Name() string {
return a.name
}
func (p *AWSTerraformProvider) Version() string {
return p.version
}