Skip to content

Commit

Permalink
interpolator: Now interpolation compares with Lowcase values (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
xescugc committed Mar 13, 2023
1 parent 65eeb11 commit 064d092
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
- Azurerm `azurerm_network_security_group.security_rule.protocol` now has the right format
([PR #357](https://github.com/cycloidio/terracognita/pull/357))

### Changed

- Interpolation now will compare value lowcasing them beforehand
([PR #356](https://github.com/cycloidio/terracognita/pull/356))

## [0.8.2] _2023-03-07_

### Added
Expand Down
1 change: 0 additions & 1 deletion azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ func (a *azurerm) FixResource(t string, v cty.Value) (cty.Value, error) {
if err != nil {
return v, errors.Wrapf(err, "failed to convert CTY value to GO type")
}

case "azurerm_windows_virtual_machine":
v, err = cty.Transform(v, func(path cty.Path, v cty.Value) (cty.Value, error) {
if len(path) > 0 {
Expand Down
4 changes: 2 additions & 2 deletions interpolator/interpolator.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ func (i *Interpolator) Interpolate(k, v string) (string, bool) {
func (i *Interpolator) checkAttributes(sk []string, v string, ngi int, ng string, rns map[string]map[string]string) string {
for rn, attrs := range rns {
att := strings.Join(sk[(len(sk)-(ngi)):len(sk)], "_")
if av, ok := attrs[att]; ok && av == v {
if av, ok := attrs[att]; ok && strings.ToLower(av) == strings.ToLower(v) {
return fmt.Sprintf("${%s.%s.%s}", fmt.Sprintf("%s_%s", i.provider, ng), rn, att)
}
}
// Then if no exact we try to find first one with the same value on the resource
for rn, attrs := range rns {
for ak, av := range attrs {
if av == v {
if strings.ToLower(av) == strings.ToLower(v) {
return fmt.Sprintf("${%s.%s.%s}", fmt.Sprintf("%s_%s", i.provider, ng), rn, ak)
}
}
Expand Down

0 comments on commit 064d092

Please sign in to comment.