Skip to content

Commit 20d95bc

Browse files
committed
Adds inherent region parser in service registration
1 parent 85038b5 commit 20d95bc

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

internal/generate/servicepackage/main.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ type ResourceDatum struct {
240240
IdentityVersion int64
241241
CustomInherentRegionIdentity bool
242242
customIdentityAttribute string
243+
CustomInherentRegionParser string
243244
}
244245

245246
func (r ResourceDatum) IsARNFormatGlobal() bool {
@@ -567,11 +568,27 @@ func (v *visitor) processFuncDecl(funcDecl *ast.FuncDecl) {
567568
case "CustomInherentRegionIdentity":
568569
d.CustomInherentRegionIdentity = true
569570
d.WrappedImport = true
570-
d.CustomImport = true
571571

572572
args := common.ParseArgs(m[3])
573+
574+
if len(args.Positional) < 2 {
575+
v.errs = append(v.errs, fmt.Errorf("CustomInherentRegionIdentity missing required parameters: at %s", fmt.Sprintf("%s.%s", v.packageName, v.functionName)))
576+
continue
577+
}
578+
573579
d.customIdentityAttribute = args.Positional[0]
574580

581+
attr := args.Positional[1]
582+
if funcName, importSpec, err := parseIdentifierSpec(attr); err != nil {
583+
v.errs = append(v.errs, fmt.Errorf("%q at %s: %w", attr, fmt.Sprintf("%s.%s", v.packageName, v.functionName), err))
584+
continue
585+
} else {
586+
d.CustomInherentRegionParser = funcName
587+
if importSpec != nil {
588+
d.goImports = append(d.goImports, *importSpec)
589+
}
590+
}
591+
575592
if attr, ok := args.Keyword["identityDuplicateAttributes"]; ok {
576593
attrs := strings.Split(attr, ";")
577594
d.IdentityDuplicateAttrs = tfslices.ApplyToAll(attrs, func(s string) string {

internal/generate/servicepackage/service_package_gen.go.gtpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*inttypes.ServicePa
517517
),
518518
{{- end }}
519519
{{- else if $value.CustomInherentRegionIdentity -}}
520-
inttypes.RegionalCustomInherentRegionIdentity({{ .CustomIdentityAttribute }},
520+
inttypes.RegionalCustomInherentRegionIdentity({{ .CustomIdentityAttribute }}, {{ .CustomInherentRegionParser }},
521521
inttypes.WithIdentityDuplicateAttrs(names.AttrID),
522522
{{- template "SDKv2CommonIdentityOpts" . }}
523523
),

0 commit comments

Comments
 (0)