Skip to content

Commit

Permalink
Remove rawNames from getInfoFromTerraformName
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iwahbe committed Apr 10, 2024
1 parent d3ae525 commit 4d68b50
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
12 changes: 6 additions & 6 deletions pkg/tfbridge/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func visitPropertyValue(
elementPath = fmt.Sprintf("%s.%s", path, k)
}

en, etf, eps := getInfoFromPulumiName(k, tfflds, psflds, false)
en, etf, eps := getInfoFromPulumiName(k, tfflds, psflds)
visitPropertyValue(ctx, name+"."+en, elementPath, e, etf, eps, visitor)
}
return
Expand Down Expand Up @@ -305,11 +305,11 @@ func computeIgnoreChanges(
return true
}
for k, v := range olds {
en, etf, eps := getInfoFromPulumiName(k, tfs, ps, false)
en, etf, eps := getInfoFromPulumiName(k, tfs, ps)
visitPropertyValue(ctx, en, string(k), v, etf, eps, visitor)
}
for k, v := range news {
en, etf, eps := getInfoFromPulumiName(k, tfs, ps, false)
en, etf, eps := getInfoFromPulumiName(k, tfs, ps)
visitPropertyValue(ctx, en, string(k), v, etf, eps, visitor)
}
return ignoredKeySet
Expand Down Expand Up @@ -361,17 +361,17 @@ func makeDetailedDiffExtra(
diff := map[string]*pulumirpc.PropertyDiff{}
collectionDiffs := map[string]*pulumirpc.PropertyDiff{}
for k, v := range olds {
en, etf, eps := getInfoFromPulumiName(k, tfs, ps, false)
en, etf, eps := getInfoFromPulumiName(k, tfs, ps)
makePropertyDiff(ctx, en, string(k), v, tfDiff, diff, collectionDiffs, forceDiff,
etf, eps, false)
}
for k, v := range news {
en, etf, eps := getInfoFromPulumiName(k, tfs, ps, false)
en, etf, eps := getInfoFromPulumiName(k, tfs, ps)
makePropertyDiff(ctx, en, string(k), v, tfDiff, diff, collectionDiffs, forceDiff,
etf, eps, false)
}
for k, v := range olds {
en, etf, eps := getInfoFromPulumiName(k, tfs, ps, false)
en, etf, eps := getInfoFromPulumiName(k, tfs, ps)
makePropertyDiff(ctx, en, string(k), v, tfDiff, diff, collectionDiffs, forceDiff,
etf, eps, true)
}
Expand Down
24 changes: 10 additions & 14 deletions pkg/tfbridge/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func nameRequiresDeleteBeforeReplace(news resource.PropertyMap, olds resource.Pr
if len(resourceInfo.UniqueNameFields) > 0 {
for _, name := range resourceInfo.UniqueNameFields {
key := resource.PropertyKey(name)
_, _, psi := getInfoFromPulumiName(key, tfs, fields, false)
_, _, psi := getInfoFromPulumiName(key, tfs, fields)

oldVal := olds[key]
newVal := news[key]
Expand All @@ -241,7 +241,7 @@ func nameRequiresDeleteBeforeReplace(news resource.PropertyMap, olds resource.Pr
}

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

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

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

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

// transform the Pulumi name to the Terraform name using the standard mangling scheme.
name := PulumiToTerraformName(ks, tfs, ps)

return name, getSchema(tfs, name), ps[name]
}

Expand Down Expand Up @@ -1565,7 +1561,7 @@ func extractInputsObject(
for name, oldValue := range oldInput {
defaultElem := false
if newValue, ok := newState[name]; ok {
_, etfs, eps := getInfoFromPulumiName(name, tfs, ps, false)
_, etfs, eps := getInfoFromPulumiName(name, tfs, ps)
oldInput[name], defaultElem = extractInputs(oldValue, newValue, etfs, eps)
} else {
delete(oldInput, name)
Expand Down Expand Up @@ -1729,7 +1725,7 @@ func extractSchemaInputsObject(
) resource.PropertyMap {
v := make(map[resource.PropertyKey]resource.PropertyValue, len(state))
for k, e := range state {
_, etfs, eps := getInfoFromPulumiName(k, tfs, ps, false)
_, etfs, eps := getInfoFromPulumiName(k, tfs, ps)
typeKnown := tfs != nil && etfs != nil

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

0 comments on commit 4d68b50

Please sign in to comment.