Skip to content

Commit

Permalink
use custom external name to get pass tf validation
Browse files Browse the repository at this point in the history
Signed-off-by: Tung Huynh <[email protected]>
  • Loading branch information
huynhsontung committed Sep 28, 2023
1 parent 51fb249 commit 63090d1
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions config/externalname.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ var ExternalNameConfigs = map[string]config.ExternalName{
// https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule
"aws_security_group_rule": config.IdentifierFromProvider,
// Imported by using the id: sgr-02108b27edd666983
"aws_vpc_security_group_egress_rule": config.IdentifierFromProvider,
"aws_vpc_security_group_egress_rule": vpcSecurityGroupRule(),
// Imported by using the id: sgr-02108b27edd666983
"aws_vpc_security_group_ingress_rule": config.IdentifierFromProvider,
"aws_vpc_security_group_ingress_rule": vpcSecurityGroupRule(),
// Imported by using the VPC CIDR Association ID: vpc-cidr-assoc-xxxxxxxx
"aws_vpc_ipv4_cidr_block_association": config.IdentifierFromProvider,
// Imported using the vpc peering id: pcx-111aaa111
Expand Down Expand Up @@ -2732,6 +2732,19 @@ func kmsAlias() config.ExternalName {
return e
}

func vpcSecurityGroupRule() config.ExternalName {
// Terraform does not allow security group rule id to be empty.
// Using a stub value to pass validation.
e := config.IdentifierFromProvider
e.GetIDFn = func(_ context.Context, externalName string, _ map[string]any, _ map[string]any) (string, error) {
if len(externalName) == 0 {
return "sgr-stub", nil
}
return externalName, nil
}
return e
}

func route() config.ExternalName {
e := config.IdentifierFromProvider
e.GetIDFn = func(_ context.Context, _ string, parameters map[string]interface{}, _ map[string]interface{}) (string, error) {
Expand Down

0 comments on commit 63090d1

Please sign in to comment.