Skip to content

Commit

Permalink
Change the rule for dashed values to include suffixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailshilkov committed Apr 17, 2024
1 parent a42f5af commit 9bcae4e
Show file tree
Hide file tree
Showing 8 changed files with 548 additions and 512 deletions.
14 changes: 12 additions & 2 deletions provider/cmd/pulumi-resource-aws/schema.json
Expand Up @@ -39201,7 +39201,7 @@
"value": "c7a.48xlarge"
},
{
"name": "C7a_Metal",
"name": "C7a_Metal_48xl",
"value": "c7a.metal-48xl"
},
{
Expand Down Expand Up @@ -40025,7 +40025,7 @@
"value": "m7a.48xlarge"
},
{
"name": "M7a_Metal",
"name": "M7a_Metal_48xl",
"value": "m7a.metal-48xl"
},
{
Expand Down Expand Up @@ -40700,6 +40700,16 @@
"name": "M5as_XLarge",
"value": "m5ad.xlarge",
"deprecationMessage": "Has a typo, use M5ad_XLarge instead"
},
{
"name": "C7a_Metal",
"value": "c7a.metal-48xl",
"deprecationMessage": "Use C7a_Metal_48xl instead"
},
{
"name": "M7a_Metal",
"value": "m7a.metal-48xl",
"deprecationMessage": "Use M7a_Metal_48xl instead"
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions provider/enum_test.go
Expand Up @@ -20,9 +20,10 @@ func TestInstanceTypeName(t *testing.T) {
{Name: "C6a_Large", Value: "c6a.large"},
{Name: "C7g_Medium", Value: "c7g.medium"},
{Name: "M1_Small", Value: "m1.small"},
{Name: "M7a_Metal", Value: "m7a.metal-48xl"},
{Name: "M7a_Metal_48xl", Value: "m7a.metal-48xl"},
{Name: "T1_Micro", Value: "t1.micro"},
{Name: "T2_Nano", Value: "t2.nano"},
{Name: "U_24tb1_112XLarge", Value: "u-24tb1.112xlarge"},
}

for _, tc := range testCases {
Expand All @@ -35,7 +36,6 @@ func TestInstanceTypeName(t *testing.T) {
func TestInstanceTypeNameErr(t *testing.T) {
testCases := []string{
"a1.metal.pc",
"m7a.metal-96xl",
}

for _, tc := range testCases {
Expand Down
14 changes: 5 additions & 9 deletions provider/enums.go
Expand Up @@ -12,24 +12,18 @@ import (
)

var replacer = strings.NewReplacer(
// It's a bit suspicious to drop this suffix but that's what we did manually.
// There is a panic below in case we find some other -xxx suffix.
"-48xl", "",
// Replace dashes with underscores.
"-", "_",
// Xlarge would be a wrong capitalization, and also we have 2xlarge etc.
// So we capitalize with a replacement.
"xlarge", "XLarge",
)

func instanceTypeName(value string) (string, error) {
replaced := replacer.Replace(value)
if strings.Contains(replaced, "-") {
// Error on any dash except for the -48xl suffix
return "", fmt.Errorf("unexpected dash in %q", value)
}

parts := strings.Split(replaced, ".")
if len(parts) != 2 {
// Error on 2+ underscores (like T4g_Nano_Odd)
// Error on 2+ dots (like t4g.nano.odd)
return "", fmt.Errorf("too many dots in %q", value)
}
for i, part := range parts {
Expand Down Expand Up @@ -62,6 +56,8 @@ func instanceTypes() []schema.EnumValueSpec {
results = append(results, schema.EnumValueSpec{Name: "U_9tb1Metal", Value: "u-9tb1.metal", DeprecationMessage: "This instancetype has been deprecated"})
results = append(results, schema.EnumValueSpec{Name: "Hs1_8XLarge", Value: "hs1.8xlarge", DeprecationMessage: "This instancetype has been deprecated"})
results = append(results, schema.EnumValueSpec{Name: "M5as_XLarge", Value: "m5ad.xlarge", DeprecationMessage: "Has a typo, use M5ad_XLarge instead"})
results = append(results, schema.EnumValueSpec{Name: "C7a_Metal", Value: "c7a.metal-48xl", DeprecationMessage: "Use C7a_Metal_48xl instead"})
results = append(results, schema.EnumValueSpec{Name: "M7a_Metal", Value: "m7a.metal-48xl", DeprecationMessage: "Use M7a_Metal_48xl instead"})

return results
}
8 changes: 6 additions & 2 deletions sdk/dotnet/Ec2/Enums.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9bcae4e

Please sign in to comment.