diff --git a/.gitignore b/.gitignore index cde0123..adfefb3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ - +.vscode dist/ diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 55240e5..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Attach to Process", - "type": "go", - "request": "attach", - "mode": "local", - "processId": 0 - } - ] -} \ No newline at end of file diff --git a/internal/meta/importlist.go b/internal/meta/importlist.go index fdd6c52..955a593 100644 --- a/internal/meta/importlist.go +++ b/internal/meta/importlist.go @@ -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 diff --git a/internal/meta/meta_map.go b/internal/meta/meta_map.go index 106298a..9146897 100644 --- a/internal/meta/meta_map.go +++ b/internal/meta/meta_map.go @@ -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) diff --git a/internal/meta/meta_query.go b/internal/meta/meta_query.go index d799b8c..95d4ccb 100644 --- a/internal/meta/meta_query.go +++ b/internal/meta/meta_query.go @@ -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 } diff --git a/internal/meta/meta_res.go b/internal/meta/meta_res.go index b3d9f08..fafec8c 100644 --- a/internal/meta/meta_res.go +++ b/internal/meta/meta_res.go @@ -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. @@ -83,6 +85,7 @@ func (meta *MetaResource) ListResource() (ImportList, error) { } item.TFResourceId = tfid item.TFAddr.Type = meta.ResourceType + item.TFAddrCache.Type = meta.ResourceType } } diff --git a/internal/meta/meta_rg.go b/internal/meta/meta_rg.go index b19bf17..2d4d106 100644 --- a/internal/meta/meta_rg.go +++ b/internal/meta/meta_rg.go @@ -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 } diff --git a/internal/ui/importlist/importlist.go b/internal/ui/importlist/importlist.go index c14782f..4750b63 100644 --- a/internal/ui/importlist/importlist.go +++ b/internal/ui/importlist/importlist.go @@ -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): diff --git a/internal/ui/importlist/importlist_delegate.go b/internal/ui/importlist/importlist_delegate.go index 1c5ee9c..b4f4b1a 100644 --- a/internal/ui/importlist/importlist_delegate.go +++ b/internal/ui/importlist/importlist_delegate.go @@ -104,6 +104,7 @@ func NewImportItemDelegate() list.ItemDelegate { selItem.v.ValidateError = nil selItem.v.TFAddr = *addr + selItem.v.TFAddrCache = *addr return } }