Skip to content

Commit ddb54e8

Browse files
committed
Remove rawNames from getInfoFromTerraformName
This is a pure refactor and doesn't have behavioral effects. At this point, `getInfoFromTerraformName` is only falled with `rawNames = false` so we can safely remove it.
1 parent d32841a commit ddb54e8

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

pkg/tfbridge/diff.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func visitPropertyValue(
145145
elementPath = fmt.Sprintf("%s.%s", path, k)
146146
}
147147

148-
en, etf, eps := getInfoFromPulumiName(k, tfflds, psflds, false)
148+
en, etf, eps := getInfoFromPulumiName(k, tfflds, psflds)
149149
visitPropertyValue(ctx, name+"."+en, elementPath, e, etf, eps, visitor)
150150
}
151151
return
@@ -305,11 +305,11 @@ func computeIgnoreChanges(
305305
return true
306306
}
307307
for k, v := range olds {
308-
en, etf, eps := getInfoFromPulumiName(k, tfs, ps, false)
308+
en, etf, eps := getInfoFromPulumiName(k, tfs, ps)
309309
visitPropertyValue(ctx, en, string(k), v, etf, eps, visitor)
310310
}
311311
for k, v := range news {
312-
en, etf, eps := getInfoFromPulumiName(k, tfs, ps, false)
312+
en, etf, eps := getInfoFromPulumiName(k, tfs, ps)
313313
visitPropertyValue(ctx, en, string(k), v, etf, eps, visitor)
314314
}
315315
return ignoredKeySet
@@ -361,17 +361,17 @@ func makeDetailedDiffExtra(
361361
diff := map[string]*pulumirpc.PropertyDiff{}
362362
collectionDiffs := map[string]*pulumirpc.PropertyDiff{}
363363
for k, v := range olds {
364-
en, etf, eps := getInfoFromPulumiName(k, tfs, ps, false)
364+
en, etf, eps := getInfoFromPulumiName(k, tfs, ps)
365365
makePropertyDiff(ctx, en, string(k), v, tfDiff, diff, collectionDiffs, forceDiff,
366366
etf, eps, false)
367367
}
368368
for k, v := range news {
369-
en, etf, eps := getInfoFromPulumiName(k, tfs, ps, false)
369+
en, etf, eps := getInfoFromPulumiName(k, tfs, ps)
370370
makePropertyDiff(ctx, en, string(k), v, tfDiff, diff, collectionDiffs, forceDiff,
371371
etf, eps, false)
372372
}
373373
for k, v := range olds {
374-
en, etf, eps := getInfoFromPulumiName(k, tfs, ps, false)
374+
en, etf, eps := getInfoFromPulumiName(k, tfs, ps)
375375
makePropertyDiff(ctx, en, string(k), v, tfDiff, diff, collectionDiffs, forceDiff,
376376
etf, eps, true)
377377
}

pkg/tfbridge/schema.go

+10-14
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func nameRequiresDeleteBeforeReplace(news resource.PropertyMap, olds resource.Pr
223223
if len(resourceInfo.UniqueNameFields) > 0 {
224224
for _, name := range resourceInfo.UniqueNameFields {
225225
key := resource.PropertyKey(name)
226-
_, _, psi := getInfoFromPulumiName(key, tfs, fields, false)
226+
_, _, psi := getInfoFromPulumiName(key, tfs, fields)
227227

228228
oldVal := olds[key]
229229
newVal := news[key]
@@ -241,7 +241,7 @@ func nameRequiresDeleteBeforeReplace(news resource.PropertyMap, olds resource.Pr
241241
}
242242

243243
for key := range news {
244-
_, _, psi := getInfoFromPulumiName(key, tfs, fields, false)
244+
_, _, psi := getInfoFromPulumiName(key, tfs, fields)
245245
if psi != nil && psi.HasDefault() && psi.Default.AutoNamed && !hasDefault[key] {
246246
return true
247247
}
@@ -591,7 +591,7 @@ func (ctx *conversionContext) makeObjectTerraformInputs(
591591
}
592592

593593
// First translate the Pulumi property name to a Terraform name.
594-
name, tfi, psi := getInfoFromPulumiName(key, tfs, ps, false)
594+
name, tfi, psi := getInfoFromPulumiName(key, tfs, ps)
595595
contract.Assertf(name != "", `Object properties cannot be empty`)
596596

597597
if _, duplicate := result[name]; duplicate {
@@ -1383,7 +1383,7 @@ func getInfoFromTerraformName(key string,
13831383

13841384
// getInfoFromPulumiName does a reverse map lookup to find the Terraform name and schema info for a Pulumi name, if any.
13851385
func getInfoFromPulumiName(key resource.PropertyKey,
1386-
tfs shim.SchemaMap, ps map[string]*SchemaInfo, rawName bool) (string,
1386+
tfs shim.SchemaMap, ps map[string]*SchemaInfo) (string,
13871387
shim.Schema, *SchemaInfo) {
13881388
// To do this, we will first look to see if there's a known custom schema that uses this name. If yes, we
13891389
// prefer to use that. To do this, we must use a reverse lookup. (In the future we may want to make a
@@ -1394,14 +1394,10 @@ func getInfoFromPulumiName(key resource.PropertyKey,
13941394
return tfname, getSchema(tfs, tfname), schinfo
13951395
}
13961396
}
1397-
var name string
1398-
if rawName {
1399-
// If raw names are requested, they will not have been mangled, so preserve the name as-is.
1400-
name = ks
1401-
} else {
1402-
// Otherwise, transform the Pulumi name to the Terraform name using the standard mangling scheme.
1403-
name = PulumiToTerraformName(ks, tfs, ps)
1404-
}
1397+
1398+
// transform the Pulumi name to the Terraform name using the standard mangling scheme.
1399+
name := PulumiToTerraformName(ks, tfs, ps)
1400+
14051401
return name, getSchema(tfs, name), ps[name]
14061402
}
14071403

@@ -1565,7 +1561,7 @@ func extractInputsObject(
15651561
for name, oldValue := range oldInput {
15661562
defaultElem := false
15671563
if newValue, ok := newState[name]; ok {
1568-
_, etfs, eps := getInfoFromPulumiName(name, tfs, ps, false)
1564+
_, etfs, eps := getInfoFromPulumiName(name, tfs, ps)
15691565
oldInput[name], defaultElem = extractInputs(oldValue, newValue, etfs, eps)
15701566
} else {
15711567
delete(oldInput, name)
@@ -1729,7 +1725,7 @@ func extractSchemaInputsObject(
17291725
) resource.PropertyMap {
17301726
v := make(map[resource.PropertyKey]resource.PropertyValue, len(state))
17311727
for k, e := range state {
1732-
_, etfs, eps := getInfoFromPulumiName(k, tfs, ps, false)
1728+
_, etfs, eps := getInfoFromPulumiName(k, tfs, ps)
17331729
typeKnown := tfs != nil && etfs != nil
17341730

17351731
// We drop fields that are not present in the schema.

0 commit comments

Comments
 (0)