driftctl/pkg/remote/aws/provider.go

74 lines
1.7 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"
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
}
func NewAWSTerraformProvider() (*AWSTerraformProvider, error) {
p := &AWSTerraformProvider{}
2021-02-15 13:21:29 +00:00
providerKey := "aws"
2021-02-09 13:53:57 +00:00
installer, err := tf.NewProviderInstaller(tf.ProviderConfig{
2021-02-15 13:21:29 +00:00
Key: providerKey,
2021-02-09 13:53:57 +00:00
Version: "3.19.0",
Postfix: "x5",
})
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-02-15 13:21:29 +00:00
Name: providerKey,
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
}
},
})
if err != nil {
return nil, err
}
p.TerraformProvider = tfProvider
return p, err
}