Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactive mode: del can be used for reverting skip #326

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

.vscode
dist/
15 changes: 0 additions & 15 deletions .vscode/launch.json

This file was deleted.

3 changes: 3 additions & 0 deletions internal/meta/importlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ type ImportItem struct {
// The terraform resource
TFAddr tfaddr.TFAddr

// The cached terraform resource addr (this is only used by the interactive mode when reverting skipping this import item)
TFAddrCache tfaddr.TFAddr

// Whether this TF resource type is from recommendation
IsRecommended bool

Expand Down
10 changes: 6 additions & 4 deletions internal/meta/meta_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ func (meta *MetaMap) ListResource() (ImportList, error) {
if err != nil {
return nil, fmt.Errorf("parsing resource id %q: %v", id, err)
}
tfAddr := tfaddr.TFAddr{
Type: res.ResourceType,
Name: res.ResourceName,
}
item := ImportItem{
AzureResourceID: azureId,
TFResourceId: res.ResourceId,
TFAddr: tfaddr.TFAddr{
Type: res.ResourceType,
Name: res.ResourceName,
},
TFAddrCache: tfAddr,
TFAddr: tfAddr,
Recommendations: []string{res.ResourceType},
}
l = append(l, item)
Expand Down
5 changes: 5 additions & 0 deletions internal/meta/meta_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ func (meta *MetaQuery) ListResource() (ImportList, error) {
Type: "",
Name: fmt.Sprintf("%s%d%s", meta.resourceNamePrefix, i, meta.resourceNameSuffix),
},
TFAddrCache: tfaddr.TFAddr{
Type: "",
Name: fmt.Sprintf("%s%d%s", meta.resourceNamePrefix, i, meta.resourceNameSuffix),
},
}
if res.TFType != "" {
item.Recommendations = []string{res.TFType}
item.TFAddr.Type = res.TFType
item.TFAddrCache.Type = res.TFType
item.IsRecommended = true
}

Expand Down
11 changes: 7 additions & 4 deletions internal/meta/meta_res.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ func (meta *MetaResource) ListResource() (ImportList, error) {
if rtCnt[res.TFType] > 1 {
name += fmt.Sprintf("-%d", rtCnt[res.TFType]-1)
}
tfAddr := tfaddr.TFAddr{
Type: res.TFType, //this might be empty if have multiple matches in aztft
Name: name,
}
item := ImportItem{
AzureResourceID: res.AzureId,
TFResourceId: res.TFId, // this might be empty if have multiple matches in aztft
TFAddr: tfaddr.TFAddr{
Type: res.TFType, //this might be empty if have multiple matches in aztft
Name: name,
},
TFAddr: tfAddr,
TFAddrCache: tfAddr,
}

// Some special Azure resource is missing the essential property that is used by aztft to detect their TF resource type.
Expand All @@ -83,6 +85,7 @@ func (meta *MetaResource) ListResource() (ImportList, error) {
}
item.TFResourceId = tfid
item.TFAddr.Type = meta.ResourceType
item.TFAddrCache.Type = meta.ResourceType
}
}

Expand Down
11 changes: 7 additions & 4 deletions internal/meta/meta_rg.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,20 @@ func (meta *MetaResourceGroup) ListResource() (ImportList, error) {

var l ImportList
for i, res := range rl {
tfAddr := tfaddr.TFAddr{
Type: "",
Name: fmt.Sprintf("%s%d%s", meta.resourceNamePrefix, i, meta.resourceNameSuffix),
}
item := ImportItem{
AzureResourceID: res.AzureId,
TFResourceId: res.TFId,
TFAddr: tfaddr.TFAddr{
Type: "",
Name: fmt.Sprintf("%s%d%s", meta.resourceNamePrefix, i, meta.resourceNameSuffix),
},
TFAddr: tfAddr,
TFAddrCache: tfAddr,
}
if res.TFType != "" {
item.Recommendations = []string{res.TFType}
item.TFAddr.Type = res.TFType
item.TFAddrCache.Type = res.TFType
item.IsRecommended = true
}

Expand Down
11 changes: 9 additions & 2 deletions internal/ui/importlist/importlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,15 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
return m, nil
}
selItem := sel.(Item)
selItem.v.TFAddr = tfaddr.TFAddr{}
selItem.textinput.Model.SetValue("")

if !selItem.v.Skip() {
selItem.v.TFAddr = tfaddr.TFAddr{}
selItem.textinput.Model.SetValue("")
} else {
selItem.v.TFAddr = selItem.v.TFAddrCache
selItem.textinput.Model.SetValue(selItem.v.TFAddr.String())
}

m.list.SetItem(selItem.idx, selItem)
return m, nil
case key.Matches(msg, m.listkeys.error):
Expand Down
1 change: 1 addition & 0 deletions internal/ui/importlist/importlist_delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func NewImportItemDelegate() list.ItemDelegate {

selItem.v.ValidateError = nil
selItem.v.TFAddr = *addr
selItem.v.TFAddrCache = *addr
return
}
}
Expand Down