mirror of https://github.com/hashicorp/terraform
backend/s3: Reinstate region validation and update copy for skip_requesting_account_id deprecation message
parent
43f12bbfe0
commit
a41e545198
@ -1,3 +1,9 @@
|
||||
# v0.2.0 (February 20, 2019)
|
||||
|
||||
ENHANCEMENTS
|
||||
|
||||
* validation: Add `ValidateAccountID` and `ValidateRegion` functions [GH-1]
|
||||
|
||||
# v0.1.0 (February 18, 2019)
|
||||
|
||||
* Initial release after split from github.com/terraform-providers/terraform-provider-aws
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
package awsbase
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/endpoints"
|
||||
)
|
||||
|
||||
// ValidateAccountID checks if the given AWS account ID is specifically allowed or forbidden.
|
||||
// The allowedAccountIDs can be used as a whitelist and forbiddenAccountIDs can be used as a blacklist.
|
||||
func ValidateAccountID(accountID string, allowedAccountIDs, forbiddenAccountIDs []string) error {
|
||||
if len(forbiddenAccountIDs) > 0 {
|
||||
for _, forbiddenAccountID := range forbiddenAccountIDs {
|
||||
if accountID == forbiddenAccountID {
|
||||
return fmt.Errorf("Forbidden AWS Account ID: %s", accountID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(allowedAccountIDs) > 0 {
|
||||
for _, allowedAccountID := range allowedAccountIDs {
|
||||
if accountID == allowedAccountID {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("AWS Account ID not allowed: %s)", accountID)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateRegion checks if the given region is a valid AWS region.
|
||||
func ValidateRegion(region string) error {
|
||||
for _, partition := range endpoints.DefaultPartitions() {
|
||||
for _, partitionRegion := range partition.Regions() {
|
||||
if region == partitionRegion.ID() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("Invalid AWS Region: %s", region)
|
||||
}
|
||||
Loading…
Reference in new issue