This commit is contained in:
magodo 2023-03-06 12:42:33 +08:00
Родитель abdc6f2710
Коммит 2cf388c316
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 2A3C3526EE99038E
37 изменённых файлов: 302 добавлений и 302 удалений

2
go.mod
Просмотреть файл

@ -1,4 +1,4 @@
module github.com/Azure/aztfy
module github.com/Azure/aztfexport
go 1.19

Просмотреть файл

@ -11,7 +11,7 @@ import (
"github.com/tidwall/sjson"
)
const CfgDirName = ".aztfy"
const CfgDirName = ".aztfexport"
const CfgFileName = "config.json"
type Configuration struct {

Просмотреть файл

@ -1,6 +1,6 @@
package config
import "github.com/Azure/aztfy/pkg/config"
import "github.com/Azure/aztfexport/pkg/config"
type InteractiveModeConfig struct {
config.Config

Просмотреть файл

@ -1,6 +1,6 @@
package config
import "github.com/Azure/aztfy/pkg/config"
import "github.com/Azure/aztfexport/pkg/config"
type NonInteractiveModeConfig struct {
config.Config

Просмотреть файл

@ -9,14 +9,14 @@ import (
"path/filepath"
"strings"
"github.com/Azure/aztfy/pkg/config"
"github.com/Azure/aztfy/pkg/log"
"github.com/Azure/aztfexport/pkg/config"
"github.com/Azure/aztfexport/pkg/log"
"github.com/zclconf/go-cty/cty"
"github.com/Azure/aztfy/internal/client"
"github.com/Azure/aztfy/internal/resmap"
"github.com/Azure/aztfy/internal/utils"
"github.com/Azure/aztfy/pkg/telemetry"
"github.com/Azure/aztfexport/internal/client"
"github.com/Azure/aztfexport/internal/resmap"
"github.com/Azure/aztfexport/internal/utils"
"github.com/Azure/aztfexport/pkg/telemetry"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
@ -33,15 +33,15 @@ import (
"github.com/magodo/workerpool"
)
const ResourceMappingFileName = "aztfyResourceMapping.json"
const SkippedResourcesFileName = "aztfySkippedResources.txt"
const ResourceMappingFileName = "aztfexportResourceMapping.json"
const SkippedResourcesFileName = "aztfexportSkippedResources.txt"
type TFConfigTransformer func(configs ConfigInfos) (ConfigInfos, error)
type BaseMeta interface {
// Init initializes aztfy, including initialize terraform, provider and soem runtime temporary resources.
// Init initializes the base meta, including initialize terraform, provider and soem runtime temporary resources.
Init(ctx context.Context) error
// DeInit deinitializes aztfy, including cleaning up runtime temporary resources.
// DeInit deinitializes the base meta, including cleaning up runtime temporary resources.
DeInit(ctx context.Context) error
// Workspace returns the path of the output directory.
Workspace() string
@ -58,7 +58,7 @@ type BaseMeta interface {
ExportSkippedResources(ctx context.Context, l ImportList) error
// ExportResourceMapping writes a resource mapping file to the output directory.
ExportResourceMapping(ctx context.Context, l ImportList) error
// CleanUpWorkspace is a weired method that is only meant to be used internally by aztfy, which under the hood will remove everything in the output directory, except the generated TF config.
// CleanUpWorkspace is a weired method that is only meant to be used internally by aztfexport, which under the hood will remove everything in the output directory, except the generated TF config.
// This method does nothing if HCLOnly in the Config is not set.
CleanUpWorkspace(ctx context.Context) error
}
@ -226,7 +226,7 @@ func (meta *baseMeta) Init(ctx context.Context) error {
}
}
for i := 0; i < meta.parallelism; i++ {
dir, err := os.MkdirTemp("", "aztfy-")
dir, err := os.MkdirTemp("", "aztfexport-")
if err != nil {
return fmt.Errorf("creating import directory: %v", err)
}
@ -321,7 +321,7 @@ func (meta *baseMeta) ParallelImport(ctx context.Context, items []*ImportItem) e
// Performance improvement.
// In case there is no TF state in the target workspace (no matter local/remote backend), we can avoid using tfmerge (which takes care of terraform internals, like keeping the lineage, etc).
// As long as the user ensure there is no address conflicts in the import list (which is always the case by aztfy as the resource names are almost unique),
// As long as the user ensure there is no address conflicts in the import list (which is always the case as the resource names are almost unique),
// We are updating the local thisBaseStateJSON here, will update it to the meta.baseState at the end of this function.
if len(meta.originBaseState) == 0 {
log.Printf("[DEBUG] Merging terraform state file %s (simple)", stateFile)
@ -406,7 +406,7 @@ func (meta baseMeta) PushState(ctx context.Context) error {
if baseState != string(meta.originBaseState) {
edits := myers.ComputeEdits(span.URIFromPath("origin.tfstate"), string(meta.originBaseState), baseState)
changes := fmt.Sprint(gotextdiff.ToUnified("origin.tfstate", "current.tfstate", string(meta.originBaseState), edits))
return fmt.Errorf("there is out-of-band changes on the state file during running aztfy:\n%s", changes)
return fmt.Errorf("there is out-of-band changes on the state file:\n%s", changes)
}
// Create a temporary state file to hold the merged states, then push the state to the output directory.
@ -715,7 +715,7 @@ func (meta *baseMeta) importItem(ctx context.Context, item *ImportItem, importId
tf := meta.importTFs[importIdx]
// Construct the empty cfg file for importing
cfgFile := filepath.Join(moduleDir, "tmp.aztfy.tf")
cfgFile := filepath.Join(moduleDir, "tmp.aztfexport.tf")
tpl := fmt.Sprintf(`resource "%s" "%s" {}`, item.TFAddr.Type, item.TFAddr.Name)
// #nosec G306
if err := os.WriteFile(cfgFile, []byte(tpl), 0644); err != nil {

Просмотреть файл

@ -1,7 +1,7 @@
package meta
import (
"github.com/Azure/aztfy/internal/tfaddr"
"github.com/Azure/aztfexport/internal/tfaddr"
"github.com/magodo/armid"
)

Просмотреть файл

@ -7,11 +7,11 @@ import (
"os"
"sort"
"github.com/Azure/aztfy/pkg/config"
"github.com/Azure/aztfy/pkg/log"
"github.com/Azure/aztfexport/pkg/config"
"github.com/Azure/aztfexport/pkg/log"
"github.com/Azure/aztfy/internal/resmap"
"github.com/Azure/aztfy/internal/tfaddr"
"github.com/Azure/aztfexport/internal/resmap"
"github.com/Azure/aztfexport/internal/tfaddr"
"github.com/magodo/armid"
)

Просмотреть файл

@ -4,10 +4,10 @@ import (
"context"
"fmt"
"github.com/Azure/aztfy/internal/resourceset"
"github.com/Azure/aztfy/internal/tfaddr"
"github.com/Azure/aztfy/pkg/config"
"github.com/Azure/aztfy/pkg/log"
"github.com/Azure/aztfexport/internal/resourceset"
"github.com/Azure/aztfexport/internal/tfaddr"
"github.com/Azure/aztfexport/pkg/config"
"github.com/Azure/aztfexport/pkg/log"
"github.com/magodo/azlist/azlist"
)

Просмотреть файл

@ -4,10 +4,10 @@ import (
"context"
"fmt"
"github.com/Azure/aztfy/internal/resourceset"
"github.com/Azure/aztfy/internal/tfaddr"
"github.com/Azure/aztfy/pkg/config"
"github.com/Azure/aztfy/pkg/log"
"github.com/Azure/aztfexport/internal/resourceset"
"github.com/Azure/aztfexport/internal/tfaddr"
"github.com/Azure/aztfexport/pkg/config"
"github.com/Azure/aztfexport/pkg/log"
"github.com/magodo/armid"
"github.com/magodo/aztft/aztft"
)
@ -56,7 +56,7 @@ func (meta *MetaResource) ListResource(_ context.Context) (ImportList, error) {
// This is to record known resource types. In case there is a known resource type and there comes another same typed resource,
// then we need to modify the resource name. Otherwise, there will be a resource address conflict.
// See https://github.com/Azure/aztfy/issues/275 for an example.
// See https://github.com/Azure/aztfexport/issues/275 for an example.
rtCnt := map[string]int{}
var l ImportList

Просмотреть файл

@ -4,10 +4,10 @@ import (
"context"
"fmt"
"github.com/Azure/aztfy/internal/resourceset"
"github.com/Azure/aztfy/internal/tfaddr"
"github.com/Azure/aztfy/pkg/config"
"github.com/Azure/aztfy/pkg/log"
"github.com/Azure/aztfexport/internal/resourceset"
"github.com/Azure/aztfexport/internal/tfaddr"
"github.com/Azure/aztfexport/pkg/config"
"github.com/Azure/aztfexport/pkg/log"
"github.com/magodo/armid"
"github.com/magodo/azlist/azlist"
)

Просмотреть файл

@ -3,7 +3,7 @@ package resourceset
import (
"sort"
"github.com/Azure/aztfy/pkg/log"
"github.com/Azure/aztfexport/pkg/log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"

Просмотреть файл

@ -6,12 +6,12 @@ import (
"os"
"strings"
internalmeta "github.com/Azure/aztfy/internal/meta"
internalmeta "github.com/Azure/aztfexport/internal/meta"
"github.com/Azure/aztfy/internal/config"
"github.com/Azure/aztfy/pkg/meta"
"github.com/Azure/aztfexport/internal/config"
"github.com/Azure/aztfexport/pkg/meta"
"github.com/Azure/aztfy/internal/ui/common"
"github.com/Azure/aztfexport/internal/ui/common"
bspinner "github.com/charmbracelet/bubbles/spinner"
"github.com/magodo/spinner"
)

Просмотреть файл

@ -1,8 +1,8 @@
package cases
import (
"github.com/Azure/aztfy/internal/resmap"
"github.com/Azure/aztfy/internal/test"
"github.com/Azure/aztfexport/internal/resmap"
"github.com/Azure/aztfexport/internal/test"
)
type SingleResourceContext struct {

Просмотреть файл

@ -3,9 +3,9 @@ package cases
import (
"fmt"
"github.com/Azure/aztfy/internal/test"
"github.com/Azure/aztfexport/internal/test"
"github.com/Azure/aztfy/internal/resmap"
"github.com/Azure/aztfexport/internal/resmap"
)
var _ Case = CaseApplicationInsightWebTest{}

Просмотреть файл

@ -3,9 +3,9 @@ package cases
import (
"fmt"
"github.com/Azure/aztfy/internal/test"
"github.com/Azure/aztfexport/internal/test"
"github.com/Azure/aztfy/internal/resmap"
"github.com/Azure/aztfexport/internal/resmap"
)
var _ Case = CaseComputeVMDisk{}
@ -26,7 +26,7 @@ resource "azurerm_resource_group" "test" {
location = "WestEurope"
}
resource "azurerm_virtual_network" "test" {
name = "aztfy-test-%[2]s"
name = "aztfexport-test-%[2]s"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
@ -38,7 +38,7 @@ resource "azurerm_subnet" "test" {
address_prefixes = ["10.0.2.0/24"]
}
resource "azurerm_network_interface" "test" {
name = "aztfy-test-%[2]s"
name = "aztfexport-test-%[2]s"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
ip_configuration {
@ -48,7 +48,7 @@ resource "azurerm_network_interface" "test" {
}
}
resource "azurerm_linux_virtual_machine" "test" {
name = "aztfy-test-%[2]s"
name = "aztfexport-test-%[2]s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
size = "Standard_F2"
@ -72,7 +72,7 @@ resource "azurerm_linux_virtual_machine" "test" {
}
}
resource "azurerm_managed_disk" "test" {
name = "aztfy-test-%[2]s"
name = "aztfexport-test-%[2]s"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
storage_account_type = "Standard_LRS"
@ -100,40 +100,40 @@ func (CaseComputeVMDisk) ResourceMapping(d test.Data) (resmap.ResourceMapping, e
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s"
},
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.compute/disks/aztfy-test-%[3]s" | Quote }}: {
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.compute/disks/aztfexport-test-%[3]s" | Quote }}: {
"resource_type": "azurerm_managed_disk",
"resource_name": "test",
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Compute/disks/aztfy-test-%[3]s"
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Compute/disks/aztfexport-test-%[3]s"
},
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.compute/virtualmachines/aztfy-test-%[3]s/datadisks/aztfy-test-%[3]s" | Quote }}: {
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.compute/virtualmachines/aztfexport-test-%[3]s/datadisks/aztfexport-test-%[3]s" | Quote }}: {
"resource_type": "azurerm_virtual_machine_data_disk_attachment",
"resource_name": "test",
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Compute/virtualMachines/aztfy-test-%[3]s/dataDisks/aztfy-test-%[3]s"
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Compute/virtualMachines/aztfexport-test-%[3]s/dataDisks/aztfexport-test-%[3]s"
},
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.compute/virtualmachines/aztfy-test-%[3]s" | Quote }}: {
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.compute/virtualmachines/aztfexport-test-%[3]s" | Quote }}: {
"resource_type": "azurerm_linux_virtual_machine",
"resource_name": "test",
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Compute/virtualMachines/aztfy-test-%[3]s"
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Compute/virtualMachines/aztfexport-test-%[3]s"
},
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.network/networkinterfaces/aztfy-test-%[3]s" | Quote }}: {
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.network/networkinterfaces/aztfexport-test-%[3]s" | Quote }}: {
"resource_type": "azurerm_network_interface",
"resource_name": "test",
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Network/networkInterfaces/aztfy-test-%[3]s"
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Network/networkInterfaces/aztfexport-test-%[3]s"
},
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.network/virtualnetworks/aztfy-test-%[3]s" | Quote }}: {
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.network/virtualnetworks/aztfexport-test-%[3]s" | Quote }}: {
"resource_type": "azurerm_virtual_network",
"resource_name": "test",
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Network/virtualNetworks/aztfy-test-%[3]s"
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Network/virtualNetworks/aztfexport-test-%[3]s"
},
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.network/virtualnetworks/aztfy-test-%[3]s/subnets/internal" | Quote }}: {
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.network/virtualnetworks/aztfexport-test-%[3]s/subnets/internal" | Quote }}: {
"resource_type": "azurerm_subnet",
"resource_name": "test",
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Network/virtualNetworks/aztfy-test-%[3]s/subnets/internal"
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Network/virtualNetworks/aztfexport-test-%[3]s/subnets/internal"
}
}
@ -147,19 +147,19 @@ func (CaseComputeVMDisk) SingleResourceContext(d test.Data) ([]SingleResourceCon
ExpectResourceCount: 1,
},
{
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Compute/virtualMachines/aztfy-test-%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Compute/virtualMachines/aztfexport-test-%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
ExpectResourceCount: 2,
},
{
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Network/networkInterfaces/aztfy-test-%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Network/networkInterfaces/aztfexport-test-%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
ExpectResourceCount: 1,
},
{
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Network/virtualNetworks/aztfy-test-%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Network/virtualNetworks/aztfexport-test-%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
ExpectResourceCount: 1,
},
{
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Network/virtualNetworks/aztfy-test-%[3]s/subnets/internal", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Network/virtualNetworks/aztfexport-test-%[3]s/subnets/internal", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
ExpectResourceCount: 1,
},
}, nil

Просмотреть файл

@ -3,9 +3,9 @@ package cases
import (
"fmt"
"github.com/Azure/aztfy/internal/test"
"github.com/Azure/aztfexport/internal/test"
"github.com/Azure/aztfy/internal/resmap"
"github.com/Azure/aztfexport/internal/resmap"
)
var _ Case = CaseFunctionAppSlot{}
@ -26,14 +26,14 @@ resource "azurerm_resource_group" "test" {
location = "EastUS2"
}
resource "azurerm_storage_account" "test" {
name = "aztfytest%[2]s"
name = "aztfexporttest%[2]s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_service_plan" "test" {
name = "aztfy-test-%[2]s"
name = "aztfexport-test-%[2]s"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
os_type = "Windows"
@ -41,7 +41,7 @@ resource "azurerm_service_plan" "test" {
}
resource "azurerm_windows_function_app" "test" {
name = "aztfy-test-%[2]s"
name = "aztfexport-test-%[2]s"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
service_plan_id = azurerm_service_plan.test.id
@ -50,7 +50,7 @@ resource "azurerm_windows_function_app" "test" {
site_config {}
}
resource "azurerm_windows_function_app_slot" "test" {
name = "aztfy-test-%[2]s"
name = "aztfexport-test-%[2]s"
function_app_id = azurerm_windows_function_app.test.id
storage_account_name = azurerm_storage_account.test.name
storage_account_access_key = azurerm_storage_account.test.primary_access_key
@ -71,28 +71,28 @@ func (CaseFunctionAppSlot) ResourceMapping(d test.Data) (resmap.ResourceMapping,
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s"
},
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.storage/storageaccounts/aztfytest%[3]s" | Quote }}: {
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.storage/storageaccounts/aztfexporttest%[3]s" | Quote }}: {
"resource_type": "azurerm_storage_account",
"resource_name": "test",
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Storage/storageAccounts/aztfytest%[3]s"
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Storage/storageAccounts/aztfexporttest%[3]s"
},
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.web/serverfarms/aztfy-test-%[3]s" | Quote }}: {
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.web/serverfarms/aztfexport-test-%[3]s" | Quote }}: {
"resource_type": "azurerm_service_plan",
"resource_name": "test",
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Web/serverfarms/aztfy-test-%[3]s"
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Web/serverfarms/aztfexport-test-%[3]s"
},
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.web/sites/aztfy-test-%[3]s" | Quote }}: {
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.web/sites/aztfexport-test-%[3]s" | Quote }}: {
"resource_type": "azurerm_windows_function_app",
"resource_name": "test",
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Web/sites/aztfy-test-%[3]s"
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Web/sites/aztfexport-test-%[3]s"
},
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.web/sites/aztfy-test-%[3]s/slots/aztfy-test-%[3]s" | Quote }}: {
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.web/sites/aztfexport-test-%[3]s/slots/aztfexport-test-%[3]s" | Quote }}: {
"resource_type": "azurerm_windows_function_app_slot",
"resource_name": "test",
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Web/sites/aztfy-test-%[3]s/slots/aztfy-test-%[3]s"
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Web/sites/aztfexport-test-%[3]s/slots/aztfexport-test-%[3]s"
}
}
@ -106,19 +106,19 @@ func (CaseFunctionAppSlot) SingleResourceContext(d test.Data) ([]SingleResourceC
ExpectResourceCount: 1,
},
{
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Storage/storageAccounts/aztfytest%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Storage/storageAccounts/aztfexporttest%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
ExpectResourceCount: 1,
},
{
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Web/serverfarms/aztfy-test-%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Web/serverfarms/aztfexport-test-%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
ExpectResourceCount: 1,
},
{
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Web/sites/aztfy-test-%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Web/sites/aztfexport-test-%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
ExpectResourceCount: 1,
},
{
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Web/sites/aztfy-test-%[3]s/slots/aztfy-test-%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Web/sites/aztfexport-test-%[3]s/slots/aztfexport-test-%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
ExpectResourceCount: 1,
},
}, nil

Просмотреть файл

@ -6,10 +6,10 @@ import (
"os"
"strings"
"github.com/Azure/aztfy/internal/test"
"github.com/Azure/aztfexport/internal/test"
"github.com/Azure/aztfy/internal/client"
"github.com/Azure/aztfy/internal/resmap"
"github.com/Azure/aztfexport/internal/client"
"github.com/Azure/aztfexport/internal/resmap"
)
var _ Case = CaseKeyVaultNestedItems{}
@ -34,7 +34,7 @@ resource "azurerm_resource_group" "test" {
data "azurerm_client_config" "current" {}
resource "azurerm_key_vault" "test" {
location = azurerm_resource_group.test.location
name = "aztfy-test-%[2]s"
name = "aztfexport-test-%[2]s"
resource_group_name = azurerm_resource_group.test.name
sku_name = "standard"
soft_delete_retention_days = 7
@ -135,7 +135,7 @@ func (c CaseKeyVaultNestedItems) getItems(d test.Data) (keyId, secretId, certId
if err != nil {
return "", "", "", err
}
resp, err := client.Get(ctx, d.RandomRgName(), "aztfy-test-"+d.RandomStringOfLength(8), "key-"+d.RandomStringOfLength(8), nil)
resp, err := client.Get(ctx, d.RandomRgName(), "aztfexport-test-"+d.RandomStringOfLength(8), "key-"+d.RandomStringOfLength(8), nil)
if err != nil {
return "", "", "", fmt.Errorf("retrieving the key: %v", err)
}
@ -149,7 +149,7 @@ func (c CaseKeyVaultNestedItems) getItems(d test.Data) (keyId, secretId, certId
if err != nil {
return "", "", "", err
}
resp, err := client.Get(ctx, d.RandomRgName(), "aztfy-test-"+d.RandomStringOfLength(8), "secret-"+d.RandomStringOfLength(8), nil)
resp, err := client.Get(ctx, d.RandomRgName(), "aztfexport-test-"+d.RandomStringOfLength(8), "secret-"+d.RandomStringOfLength(8), nil)
if err != nil {
return "", "", "", fmt.Errorf("retrieving the secret: %v", err)
}
@ -163,7 +163,7 @@ func (c CaseKeyVaultNestedItems) getItems(d test.Data) (keyId, secretId, certId
if err != nil {
return "", "", "", err
}
resp, err := client.Get(ctx, d.RandomRgName(), "aztfy-test-"+d.RandomStringOfLength(8), "cert-"+d.RandomStringOfLength(8), nil)
resp, err := client.Get(ctx, d.RandomRgName(), "aztfexport-test-"+d.RandomStringOfLength(8), "cert-"+d.RandomStringOfLength(8), nil)
if err != nil {
return "", "", "", fmt.Errorf("retrieving the cert (secret): %v", err)
}
@ -190,25 +190,25 @@ func (c CaseKeyVaultNestedItems) ResourceMapping(d test.Data) (resmap.ResourceMa
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s"
},
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.keyvault/vaults/aztfy-test-%[3]s" | Quote }}: {
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.keyvault/vaults/aztfexport-test-%[3]s" | Quote }}: {
"resource_type": "azurerm_key_vault",
"resource_name": "test",
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.KeyVault/vaults/aztfy-test-%[3]s"
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.KeyVault/vaults/aztfexport-test-%[3]s"
},
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.keyvault/vaults/aztfy-test-%[3]s/keys/key-%[3]s" | Quote }} : {
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.keyvault/vaults/aztfexport-test-%[3]s/keys/key-%[3]s" | Quote }} : {
"resource_type": "azurerm_key_vault_key",
"resource_name": "test",
"resource_id": %[4]q
},
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.keyvault/vaults/aztfy-test-%[3]s/secrets/secret-%[3]s" | Quote }} : {
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.keyvault/vaults/aztfexport-test-%[3]s/secrets/secret-%[3]s" | Quote }} : {
"resource_type": "azurerm_key_vault_secret",
"resource_name": "test",
"resource_id": %[5]q
},
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.keyvault/vaults/aztfy-test-%[3]s/certificates/cert-%[3]s" | Quote }} : {
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.keyvault/vaults/aztfexport-test-%[3]s/certificates/cert-%[3]s" | Quote }} : {
"resource_type": "azurerm_key_vault_certificate",
"resource_name": "test",
"resource_id": %[6]q
@ -246,19 +246,19 @@ func (c CaseKeyVaultNestedItems) SingleResourceContext(d test.Data) ([]SingleRes
ExpectResourceCount: 1,
},
{
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.KeyVault/vaults/aztfy-test-%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.KeyVault/vaults/aztfexport-test-%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
ExpectResourceCount: 1,
},
{
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.KeyVault/vaults/aztfy-test-%[3]s/%[4]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8), keyIdSuffix),
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.KeyVault/vaults/aztfexport-test-%[3]s/%[4]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8), keyIdSuffix),
ExpectResourceCount: 1,
},
{
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.KeyVault/vaults/aztfy-test-%[3]s/%[4]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8), secretIdSuffix),
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.KeyVault/vaults/aztfexport-test-%[3]s/%[4]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8), secretIdSuffix),
ExpectResourceCount: 1,
},
{
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.KeyVault/vaults/aztfy-test-%[3]s/%[4]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8), certIdSuffix),
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.KeyVault/vaults/aztfexport-test-%[3]s/%[4]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8), certIdSuffix),
ExpectResourceCount: 1,
},
}, nil

Просмотреть файл

@ -3,9 +3,9 @@ package cases
import (
"fmt"
"github.com/Azure/aztfy/internal/test"
"github.com/Azure/aztfexport/internal/test"
"github.com/Azure/aztfy/internal/resmap"
"github.com/Azure/aztfexport/internal/resmap"
)
var _ Case = CaseSignalRService{}

Просмотреть файл

@ -3,9 +3,9 @@ package cases
import (
"fmt"
"github.com/Azure/aztfy/internal/test"
"github.com/Azure/aztfexport/internal/test"
"github.com/Azure/aztfy/internal/resmap"
"github.com/Azure/aztfexport/internal/resmap"
)
var _ Case = CaseStorageFileShare{}
@ -27,14 +27,14 @@ resource "azurerm_resource_group" "test" {
}
resource "azurerm_storage_account" "test" {
name = "aztfy%[2]s"
name = "aztfexport%[2]s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_storage_share" "test" {
name = "aztfy%[2]s"
name = "aztfexport%[2]s"
storage_account_name = azurerm_storage_account.test.name
quota = 5
}
@ -53,16 +53,16 @@ func (CaseStorageFileShare) ResourceMapping(d test.Data) (resmap.ResourceMapping
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s"
},
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.storage/storageaccounts/aztfy%[3]s" | Quote }}: {
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.storage/storageaccounts/aztfexport%[3]s" | Quote }}: {
"resource_type": "azurerm_storage_account",
"resource_name": "test",
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Storage/storageAccounts/aztfy%[3]s"
"resource_id": "/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Storage/storageAccounts/aztfexport%[3]s"
},
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.storage/storageaccounts/aztfy%[3]s/fileservices/default/shares/aztfy%[3]s" | Quote }}: {
{{ "/subscriptions/%[1]s/resourcegroups/%[2]s/providers/microsoft.storage/storageaccounts/aztfexport%[3]s/fileservices/default/shares/aztfexport%[3]s" | Quote }}: {
"resource_type": "azurerm_storage_share",
"resource_name": "test",
"resource_id": "https://aztfy%[3]s.file.core.windows.net/aztfy%[3]s"
"resource_id": "https://aztfexport%[3]s.file.core.windows.net/aztfexport%[3]s"
}
}
@ -76,11 +76,11 @@ func (CaseStorageFileShare) SingleResourceContext(d test.Data) ([]SingleResource
ExpectResourceCount: 1,
},
{
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Storage/storageAccounts/aztfy%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Storage/storageAccounts/aztfexport%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
ExpectResourceCount: 1,
},
{
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Storage/storageAccounts/aztfy%[3]s/fileServices/default/shares/aztfy%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
AzureId: fmt.Sprintf("/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.Storage/storageAccounts/aztfexport%[3]s/fileServices/default/shares/aztfexport%[3]s", d.SubscriptionId, d.RandomRgName(), d.RandomStringOfLength(8)),
ExpectResourceCount: 1,
},
}, nil

Просмотреть файл

@ -8,12 +8,12 @@ import (
"testing"
"time"
internalconfig "github.com/Azure/aztfy/internal/config"
"github.com/Azure/aztfy/pkg/config"
internalconfig "github.com/Azure/aztfexport/internal/config"
"github.com/Azure/aztfexport/pkg/config"
"github.com/Azure/aztfy/internal"
"github.com/Azure/aztfy/internal/test"
"github.com/Azure/aztfy/internal/utils"
"github.com/Azure/aztfexport/internal"
"github.com/Azure/aztfexport/internal/test"
"github.com/Azure/aztfexport/internal/utils"
"github.com/hashicorp/terraform-exec/tfexec"
)
@ -86,14 +86,14 @@ resource "azurerm_subnet" "test" {
cred, clientOpt := test.BuildCredAndClientOpt(t)
// Import in non-recursive mode
aztfyDir := t.TempDir()
aztfexportDir := t.TempDir()
cfg := internalconfig.NonInteractiveModeConfig{
Config: config.Config{
CommonConfig: config.CommonConfig{
SubscriptionId: os.Getenv("ARM_SUBSCRIPTION_ID"),
AzureSDKCredential: cred,
AzureSDKClientOption: *clientOpt,
OutputDir: aztfyDir,
OutputDir: aztfexportDir,
BackendType: "local",
DevProvider: true,
Parallelism: 1,
@ -110,7 +110,7 @@ resource "azurerm_subnet" "test" {
if err := internal.BatchImport(ctx, cfg); err != nil {
t.Fatalf("failed to run batch import non-recursively: %v", err)
}
test.Verify(t, ctx, aztfyDir, tfexecPath, 1)
test.Verify(t, ctx, aztfexportDir, tfexecPath, 1)
// Import in recursive mode
t.Log("Importing in recursive mode")
@ -121,5 +121,5 @@ resource "azurerm_subnet" "test" {
if err := internal.BatchImport(ctx, cfg); err != nil {
t.Fatalf("failed to run batch import recursively: %v", err)
}
test.Verify(t, ctx, aztfyDir, tfexecPath, 2)
test.Verify(t, ctx, aztfexportDir, tfexecPath, 2)
}

Просмотреть файл

@ -86,5 +86,5 @@ func (rd Rd) RandomStringOfLength(len int) string {
}
func (rd Rd) RandomRgName() string {
return fmt.Sprintf("aztfy-rg-%s", rd.RandomStringOfLength(8))
return fmt.Sprintf("aztfexport-rg-%s", rd.RandomStringOfLength(8))
}

Просмотреть файл

@ -8,14 +8,14 @@ import (
"testing"
"time"
"github.com/Azure/aztfy/internal/client"
internalconfig "github.com/Azure/aztfy/internal/config"
"github.com/Azure/aztfexport/internal/client"
internalconfig "github.com/Azure/aztfexport/internal/config"
"github.com/Azure/aztfy/pkg/config"
"github.com/Azure/aztfexport/pkg/config"
"github.com/Azure/aztfy/internal"
"github.com/Azure/aztfy/internal/test"
"github.com/Azure/aztfy/internal/test/cases"
"github.com/Azure/aztfexport/internal"
"github.com/Azure/aztfexport/internal/test"
"github.com/Azure/aztfexport/internal/test/cases"
"github.com/hashicorp/terraform-exec/tfexec"
"github.com/stretchr/testify/require"
)
@ -59,7 +59,7 @@ func runCase(t *testing.T, d test.Data, c cases.Case) {
t.Logf("Sleep for %v to wait for the just created resources be recorded in ARG\n", delay)
time.Sleep(delay)
aztfyDir := t.TempDir()
aztfexportDir := t.TempDir()
mapFile := filepath.Join(t.TempDir(), "mapping.json")
resMapping, err := c.ResourceMapping(d)
@ -76,7 +76,7 @@ func runCase(t *testing.T, d test.Data, c cases.Case) {
SubscriptionId: os.Getenv("ARM_SUBSCRIPTION_ID"),
AzureSDKCredential: cred,
AzureSDKClientOption: *clientOpt,
OutputDir: aztfyDir,
OutputDir: aztfexportDir,
BackendType: "local",
DevProvider: true,
Parallelism: 1,
@ -89,7 +89,7 @@ func runCase(t *testing.T, d test.Data, c cases.Case) {
if err := internal.BatchImport(ctx, cfg); err != nil {
t.Fatalf("failed to run batch import: %v", err)
}
test.Verify(t, ctx, aztfyDir, tfexecPath, len(resMapping))
test.Verify(t, ctx, aztfexportDir, tfexecPath, len(resMapping))
}
func TestComputeVMDisk(t *testing.T) {

Просмотреть файл

@ -8,15 +8,15 @@ import (
"testing"
"time"
"github.com/Azure/aztfy/internal/client"
internalconfig "github.com/Azure/aztfy/internal/config"
"github.com/Azure/aztfexport/internal/client"
internalconfig "github.com/Azure/aztfexport/internal/config"
"github.com/Azure/aztfy/pkg/config"
"github.com/Azure/aztfexport/pkg/config"
"github.com/Azure/aztfy/internal"
"github.com/Azure/aztfy/internal/test"
"github.com/Azure/aztfy/internal/test/cases"
"github.com/Azure/aztfy/internal/utils"
"github.com/Azure/aztfexport/internal"
"github.com/Azure/aztfexport/internal/test"
"github.com/Azure/aztfexport/internal/test/cases"
"github.com/Azure/aztfexport/internal/utils"
"github.com/hashicorp/terraform-exec/tfexec"
)
@ -59,7 +59,7 @@ func runCase(t *testing.T, d test.Data, c cases.Case) {
t.Logf("Sleep for %v to wait for the just created resources be recorded in ARG\n", delay)
time.Sleep(delay)
aztfyDir := t.TempDir()
aztfexportDir := t.TempDir()
l, err := c.SingleResourceContext(d)
if err != nil {
t.Fatalf("failed to get resource ids: %v", err)
@ -74,7 +74,7 @@ func runCase(t *testing.T, d test.Data, c cases.Case) {
SubscriptionId: os.Getenv("ARM_SUBSCRIPTION_ID"),
AzureSDKCredential: cred,
AzureSDKClientOption: *clientOpt,
OutputDir: aztfyDir,
OutputDir: aztfexportDir,
BackendType: "local",
DevProvider: true,
Parallelism: 1,
@ -91,7 +91,7 @@ func runCase(t *testing.T, d test.Data, c cases.Case) {
if err := internal.BatchImport(ctx, cfg); err != nil {
t.Fatalf("failed to run resource import: %v", err)
}
test.Verify(t, ctx, aztfyDir, tfexecPath, rctx.ExpectResourceCount)
test.Verify(t, ctx, aztfexportDir, tfexecPath, rctx.ExpectResourceCount)
}
}
func TestComputeVMDisk(t *testing.T) {

Просмотреть файл

@ -7,14 +7,14 @@ import (
"path/filepath"
"testing"
internalconfig "github.com/Azure/aztfy/internal/config"
internalconfig "github.com/Azure/aztfexport/internal/config"
"github.com/Azure/aztfy/pkg/config"
"github.com/Azure/aztfexport/pkg/config"
"github.com/Azure/aztfy/internal/test"
"github.com/Azure/aztfy/internal/utils"
"github.com/Azure/aztfexport/internal/test"
"github.com/Azure/aztfexport/internal/utils"
"github.com/Azure/aztfy/internal"
"github.com/Azure/aztfexport/internal"
"github.com/hashicorp/terraform-exec/tfexec"
)
@ -77,7 +77,7 @@ resource "azurerm_resource_group" "test3" {
}
// Import the first resource group
aztfyDir := t.TempDir()
aztfexportDir := t.TempDir()
cred, clientOpt := test.BuildCredAndClientOpt(t)
@ -87,7 +87,7 @@ resource "azurerm_resource_group" "test3" {
SubscriptionId: os.Getenv("ARM_SUBSCRIPTION_ID"),
AzureSDKCredential: cred,
AzureSDKClientOption: *clientOpt,
OutputDir: aztfyDir,
OutputDir: aztfexportDir,
BackendType: "local",
DevProvider: true,
Parallelism: 1,
@ -121,5 +121,5 @@ resource "azurerm_resource_group" "test3" {
}
// Verify
test.Verify(t, ctx, aztfyDir, tfexecPath, 3)
test.Verify(t, ctx, aztfexportDir, tfexecPath, 3)
}

Просмотреть файл

@ -7,14 +7,14 @@ import (
"testing"
"time"
"github.com/Azure/aztfy/internal/client"
internalconfig "github.com/Azure/aztfy/internal/config"
"github.com/Azure/aztfexport/internal/client"
internalconfig "github.com/Azure/aztfexport/internal/config"
"github.com/Azure/aztfy/pkg/config"
"github.com/Azure/aztfexport/pkg/config"
"github.com/Azure/aztfy/internal"
"github.com/Azure/aztfy/internal/test"
"github.com/Azure/aztfy/internal/test/cases"
"github.com/Azure/aztfexport/internal"
"github.com/Azure/aztfexport/internal/test"
"github.com/Azure/aztfexport/internal/test/cases"
"github.com/hashicorp/terraform-exec/tfexec"
)
@ -56,7 +56,7 @@ func runCase(t *testing.T, d test.Data, c cases.Case) {
t.Logf("Sleep for %v to wait for the just created resources be recorded in ARG\n", delay)
time.Sleep(delay)
aztfyDir := t.TempDir()
aztfexportDir := t.TempDir()
cred, clientOpt := test.BuildCredAndClientOpt(t)
@ -66,7 +66,7 @@ func runCase(t *testing.T, d test.Data, c cases.Case) {
SubscriptionId: os.Getenv("ARM_SUBSCRIPTION_ID"),
AzureSDKCredential: cred,
AzureSDKClientOption: *clientOpt,
OutputDir: aztfyDir,
OutputDir: aztfexportDir,
BackendType: "local",
DevProvider: true,
Parallelism: 10,
@ -80,7 +80,7 @@ func runCase(t *testing.T, d test.Data, c cases.Case) {
if err := internal.BatchImport(ctx, cfg); err != nil {
t.Fatalf("failed to run batch import: %v", err)
}
test.Verify(t, ctx, aztfyDir, tfexecPath, c.Total())
test.Verify(t, ctx, aztfexportDir, tfexecPath, c.Total())
}
func TestComputeVMDisk(t *testing.T) {

Просмотреть файл

@ -7,14 +7,14 @@ import (
"path/filepath"
"testing"
internalconfig "github.com/Azure/aztfy/internal/config"
internalconfig "github.com/Azure/aztfexport/internal/config"
"github.com/Azure/aztfy/pkg/config"
"github.com/Azure/aztfexport/pkg/config"
"github.com/Azure/aztfy/internal/test"
"github.com/Azure/aztfexport/internal/test"
"github.com/stretchr/testify/require"
"github.com/Azure/aztfy/internal"
"github.com/Azure/aztfexport/internal"
"github.com/hashicorp/terraform-exec/tfexec"
)
@ -77,24 +77,24 @@ resource "azurerm_resource_group" "test3" {
}
// Import the first resource group
aztfyDir := t.TempDir()
aztfexportDir := t.TempDir()
tf, err = tfexec.NewTerraform(aztfyDir, tfexecPath)
tf, err = tfexec.NewTerraform(aztfexportDir, tfexecPath)
if err != nil {
t.Fatalf("failed to new terraform: %v", err)
}
if err := os.MkdirAll(filepath.Join(aztfyDir, "modules", "submodules"), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(aztfexportDir, "modules", "submodules"), 0755); err != nil {
t.Fatalf("failed to create the directory `modules/submodules`: %v", err)
}
if err := os.WriteFile(filepath.Join(aztfyDir, "main.tf"), []byte(`
if err := os.WriteFile(filepath.Join(aztfexportDir, "main.tf"), []byte(`
module "my-module" {
source = "./modules"
}
`), 0644); err != nil {
t.Fatalf("failed to create the TF config file: %v", err)
}
if err := os.WriteFile(filepath.Join(aztfyDir, "modules", "main.tf"), []byte(`
if err := os.WriteFile(filepath.Join(aztfexportDir, "modules", "main.tf"), []byte(`
module "sub-module" {
source = "./submodules"
}
@ -114,7 +114,7 @@ module "sub-module" {
SubscriptionId: os.Getenv("ARM_SUBSCRIPTION_ID"),
AzureSDKCredential: cred,
AzureSDKClientOption: *clientOpt,
OutputDir: aztfyDir,
OutputDir: aztfexportDir,
BackendType: "local",
Parallelism: 1,
ModulePath: "", // Import to the root module
@ -156,7 +156,7 @@ module "sub-module" {
t.Fatalf("terraform plan has diff")
}
t.Log("Running: terraform show")
state, err := tf.ShowStateFile(ctx, filepath.Join(aztfyDir, "terraform.tfstate"))
state, err := tf.ShowStateFile(ctx, filepath.Join(aztfexportDir, "terraform.tfstate"))
if err != nil {
t.Fatalf("terraform state show in the generated workspace failed: %v", err)
}

Просмотреть файл

@ -11,7 +11,7 @@ import (
"testing"
"text/template"
"github.com/Azure/aztfy/internal/resmap"
"github.com/Azure/aztfexport/internal/resmap"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
@ -25,10 +25,10 @@ import (
"github.com/hashicorp/terraform-exec/tfexec"
)
const TestToggleEnvVar = "AZTFY_E2E"
const TestToggleEnvVar = "AZTFEXPORT_E2E"
func Keep() bool {
return os.Getenv("AZTFY_KEEP") != ""
return os.Getenv("AZTFEXPORT_KEEP") != ""
}
func Precheck(t *testing.T) {
@ -78,7 +78,7 @@ func BuildCredAndClientOpt(t *testing.T) (azcore.TokenCredential, *arm.ClientOpt
ClientOptions: policy.ClientOptions{
Cloud: cloudCfg,
Telemetry: policy.TelemetryOptions{
ApplicationID: "aztfy",
ApplicationID: "aztfexport",
Disabled: false,
},
Logging: policy.LogOptions{
@ -116,8 +116,8 @@ func EnsureTF(t *testing.T) string {
return execPath
}
func Verify(t *testing.T, ctx context.Context, aztfyDir, tfexecPath string, expectResCnt int) {
tf, err := tfexec.NewTerraform(aztfyDir, tfexecPath)
func Verify(t *testing.T, ctx context.Context, aztfexportDir, tfexecPath string, expectResCnt int) {
tf, err := tfexec.NewTerraform(aztfexportDir, tfexecPath)
if err != nil {
t.Fatalf("failed to new terraform: %v", err)
}
@ -153,7 +153,7 @@ func Verify(t *testing.T, ctx context.Context, aztfyDir, tfexecPath string, expe
t.Fatalf("terraform plan has diff")
}
t.Log("Running: terraform show")
state, err := tf.ShowStateFile(ctx, filepath.Join(aztfyDir, "terraform.tfstate"))
state, err := tf.ShowStateFile(ctx, filepath.Join(aztfexportDir, "terraform.tfstate"))
if err != nil {
t.Fatalf("terraform state show in the generated workspace failed: %v", err)
}

Просмотреть файл

@ -17,7 +17,7 @@ type stdoutMessager struct {
func NewStdoutMessager() Messager {
return &stdoutMessager{
Logger: log.New(os.Stdout, "[aztfy] ", log.LstdFlags),
Logger: log.New(os.Stdout, "[aztfexport] ", log.LstdFlags),
}
}

Просмотреть файл

@ -1,9 +1,9 @@
package aztfyclient
package aztfexportclient
import (
"context"
"github.com/Azure/aztfy/pkg/meta"
"github.com/Azure/aztfexport/pkg/meta"
tea "github.com/charmbracelet/bubbletea"
)

Просмотреть файл

@ -3,15 +3,15 @@ package importlist
import (
"context"
"fmt"
"github.com/Azure/aztfy/pkg/meta"
"github.com/Azure/aztfexport/pkg/meta"
"regexp"
"sort"
"strings"
"time"
"github.com/Azure/aztfy/internal/tfaddr"
"github.com/Azure/aztfy/internal/ui/aztfyclient"
"github.com/Azure/aztfy/internal/ui/common"
"github.com/Azure/aztfexport/internal/tfaddr"
"github.com/Azure/aztfexport/internal/ui/aztfexportclient"
"github.com/Azure/aztfexport/internal/ui/common"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list"
@ -126,7 +126,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
return m, m.list.NewStatusMessage(common.ErrorMsgStyle.Render("One or more user input is invalid"))
}
return m, aztfyclient.StartImport(m.importList(true))
return m, aztfexportclient.StartImport(m.importList(true))
case key.Matches(msg, m.listkeys.skip):
sel := m.list.SelectedItem()
if sel == nil {
@ -153,7 +153,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
if selItem.v.ImportError == nil {
return m, nil
}
return m, aztfyclient.ShowImportError(selItem.v, selItem.idx, m.importList(false))
return m, aztfexportclient.ShowImportError(selItem.v, selItem.idx, m.importList(false))
case key.Matches(msg, m.listkeys.recommendation):
sel := m.list.SelectedItem()
if sel == nil {
@ -174,7 +174,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
m.list.NewStatusMessage(common.ErrorMsgStyle.Render(err.Error()))
}
case key.Matches(msg, m.list.KeyMap.Quit):
return m, aztfyclient.Quit(m.ctx, m.c)
return m, aztfexportclient.Quit(m.ctx, m.c)
}
case tea.WindowSizeMsg:
// The height here minus the height occupied by the title

Просмотреть файл

@ -4,10 +4,10 @@ import (
"fmt"
"strings"
"github.com/Azure/aztfy/internal/tfaddr"
"github.com/Azure/aztfexport/internal/tfaddr"
"github.com/Azure/aztfy/internal/ui/aztfyclient"
"github.com/Azure/aztfy/internal/ui/common"
"github.com/Azure/aztfexport/internal/ui/aztfexportclient"
"github.com/Azure/aztfexport/internal/ui/common"
"github.com/magodo/tfadd/providers/azurerm"
"github.com/charmbracelet/bubbles/list"
@ -44,7 +44,7 @@ func NewImportItemDelegate() list.ItemDelegate {
// This allows the user to change its mind for importing this resource as another resource type.
// (e.g. vm resource -> either azurerm_virtual_machine or azurerm_linux_virtual_machine)
if selItem.v.Imported {
cmd := aztfyclient.CleanTFState(selItem.v.TFAddr.String())
cmd := aztfexportclient.CleanTFState(selItem.v.TFAddr.String())
cmds = append(cmds, cmd)
selItem.v.Imported = false
}

Просмотреть файл

@ -1,8 +1,8 @@
package importlist
import (
"github.com/Azure/aztfy/internal/ui/common"
"github.com/Azure/aztfy/pkg/meta"
"github.com/Azure/aztfexport/internal/ui/common"
"github.com/Azure/aztfexport/pkg/meta"
"github.com/magodo/textinput"
)

Просмотреть файл

@ -3,10 +3,10 @@ package progress
import (
"context"
"fmt"
"github.com/Azure/aztfy/pkg/meta"
"github.com/Azure/aztfexport/pkg/meta"
"github.com/Azure/aztfy/internal/ui/aztfyclient"
"github.com/Azure/aztfy/internal/ui/common"
"github.com/Azure/aztfexport/internal/ui/aztfexportclient"
"github.com/Azure/aztfexport/internal/ui/common"
prog "github.com/charmbracelet/bubbles/progress"
tea "github.com/charmbracelet/bubbletea"
)
@ -42,7 +42,7 @@ func NewModel(ctx context.Context, c meta.Meta, parallelism int, l meta.ImportLi
func (m Model) Init() tea.Cmd {
if m.iterationDone() {
return aztfyclient.FinishImport(m.l)
return aztfexportclient.FinishImport(m.l)
}
n := m.parallelism
@ -50,7 +50,7 @@ func (m Model) Init() tea.Cmd {
n = len(m.l) - m.idx
}
return tea.Batch(
aztfyclient.ImportItems(m.ctx, m.c, m.l[m.idx:m.idx+n]),
aztfexportclient.ImportItems(m.ctx, m.c, m.l[m.idx:m.idx+n]),
)
}
@ -65,7 +65,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
m.progress = progressModel.(prog.Model)
return m, cmd
case aztfyclient.ImportItemsDoneMsg:
case aztfexportclient.ImportItemsDoneMsg:
var cmds []tea.Cmd
// Update results
@ -88,7 +88,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
if m.iterationDone() {
cmds = append(cmds, m.progress.SetPercent(1))
cmds = append(cmds, aztfyclient.FinishImport(m.l))
cmds = append(cmds, aztfexportclient.FinishImport(m.l))
return m, tea.Batch(cmds...)
}
@ -98,7 +98,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
if m.idx+m.parallelism > len(m.l) {
n = len(m.l) - m.idx
}
cmds = append(cmds, aztfyclient.ImportItems(m.ctx, m.c, m.l[m.idx:m.idx+n]))
cmds = append(cmds, aztfexportclient.ImportItems(m.ctx, m.c, m.l[m.idx:m.idx+n]))
return m, tea.Batch(cmds...)
default:

Просмотреть файл

@ -4,19 +4,19 @@ import (
"context"
"fmt"
"github.com/Azure/aztfy/internal/config"
internalmeta "github.com/Azure/aztfy/internal/meta"
"github.com/Azure/aztfy/pkg/log"
"github.com/Azure/aztfy/pkg/meta"
"github.com/Azure/aztfexport/internal/config"
internalmeta "github.com/Azure/aztfexport/internal/meta"
"github.com/Azure/aztfexport/pkg/log"
"github.com/Azure/aztfexport/pkg/meta"
"github.com/Azure/aztfy/internal/ui/aztfyclient"
"github.com/Azure/aztfy/internal/ui/common"
"github.com/Azure/aztfexport/internal/ui/aztfexportclient"
"github.com/Azure/aztfexport/internal/ui/common"
"github.com/mitchellh/go-wordwrap"
"github.com/muesli/reflow/indent"
"github.com/Azure/aztfy/internal/ui/importlist"
"github.com/Azure/aztfy/internal/ui/progress"
"github.com/Azure/aztfexport/internal/ui/importlist"
"github.com/Azure/aztfexport/internal/ui/progress"
"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
@ -82,7 +82,7 @@ type model struct {
spinner spinner.Model
importlist importlist.Model
progress progress.Model
importerrormsg aztfyclient.ShowImportErrorMsg
importerrormsg aztfexportclient.ShowImportErrorMsg
}
func newModel(ctx context.Context, cfg config.InteractiveModeConfig) (*model, error) {
@ -111,7 +111,7 @@ func newModel(ctx context.Context, cfg config.InteractiveModeConfig) (*model, er
func (m model) Init() tea.Cmd {
return tea.Batch(
aztfyclient.NewClient(m.meta),
aztfexportclient.NewClient(m.meta),
spinner.Tick,
)
}
@ -128,20 +128,20 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg.Type {
case tea.KeyCtrlC:
m.status = statusQuitting
return m, aztfyclient.Quit(m.ctx, m.meta)
return m, aztfexportclient.Quit(m.ctx, m.meta)
}
case spinner.TickMsg:
var cmd tea.Cmd
m.spinner, cmd = m.spinner.Update(msg)
return m, cmd
case aztfyclient.NewClientMsg:
case aztfexportclient.NewClientMsg:
m.meta = msg
m.status = statusInit
return m, aztfyclient.Init(m.ctx, m.meta)
case aztfyclient.InitProviderDoneMsg:
return m, aztfexportclient.Init(m.ctx, m.meta)
case aztfexportclient.InitProviderDoneMsg:
m.status = statusListingResource
return m, aztfyclient.ListResource(m.ctx, m.meta)
case aztfyclient.ListResourceDoneMsg:
return m, aztfexportclient.ListResource(m.ctx, m.meta)
case aztfexportclient.ListResourceDoneMsg:
m.status = statusBuildingImportList
m.importlist = importlist.NewModel(m.ctx, m.meta, msg.List, 0)
// Trigger a windows resize cmd to resize the importlist model.
@ -149,11 +149,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// But this way we only need to maintain the resizing logic at one place (which takes consideration of the title height).
cmd := func() tea.Msg { return m.winsize }
return m, cmd
case aztfyclient.ShowImportErrorMsg:
case aztfexportclient.ShowImportErrorMsg:
m.status = statusImportErrorMsg
m.importerrormsg = msg
return m, nil
case aztfyclient.StartImportMsg:
case aztfexportclient.StartImportMsg:
m.status = statusImporting
m.progress = progress.NewModel(m.ctx, m.meta, m.parallelism, msg.List)
return m, tea.Batch(
@ -161,7 +161,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Resize the progress bar
func() tea.Msg { return m.winsize },
)
case aztfyclient.ImportDoneMsg:
case aztfexportclient.ImportDoneMsg:
for idx, item := range msg.List {
if item.ImportError != nil {
m.status = statusBuildingImportList
@ -171,28 +171,28 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}
m.status = statusPushState
return m, aztfyclient.PushState(m.ctx, m.meta, msg.List)
case aztfyclient.PushStateDoneMsg:
return m, aztfexportclient.PushState(m.ctx, m.meta, msg.List)
case aztfexportclient.PushStateDoneMsg:
m.status = statusExportResourceMapping
return m, aztfyclient.ExportResourceMapping(m.ctx, m.meta, msg.List)
case aztfyclient.ExportResourceMappingDoneMsg:
return m, aztfexportclient.ExportResourceMapping(m.ctx, m.meta, msg.List)
case aztfexportclient.ExportResourceMappingDoneMsg:
m.status = statusExportSkippedResources
return m, aztfyclient.ExportSkippedResources(m.ctx, m.meta, msg.List)
case aztfyclient.ExportSkippedResourcesDoneMsg:
return m, aztfexportclient.ExportSkippedResources(m.ctx, m.meta, msg.List)
case aztfexportclient.ExportSkippedResourcesDoneMsg:
m.status = statusGeneratingCfg
return m, aztfyclient.GenerateCfg(m.ctx, m.meta, msg.List)
case aztfyclient.GenerateCfgDoneMsg:
return m, aztfexportclient.GenerateCfg(m.ctx, m.meta, msg.List)
case aztfexportclient.GenerateCfgDoneMsg:
m.status = statusCleaningUpWorkspaceCfg
return m, aztfyclient.CleanUpWorkspace(m.ctx, m.meta)
case aztfyclient.WorkspaceCleanupDoneMsg:
return m, aztfexportclient.CleanUpWorkspace(m.ctx, m.meta)
case aztfexportclient.WorkspaceCleanupDoneMsg:
m.status = statusSummary
return m, nil
case aztfyclient.QuitMsg:
case aztfexportclient.QuitMsg:
return m, tea.Quit
case aztfyclient.CleanTFStateMsg:
case aztfexportclient.CleanTFStateMsg:
m.meta.CleanTFState(m.ctx, msg.Addr)
return m, nil
case aztfyclient.ErrMsg:
case aztfexportclient.ErrMsg:
m.status = statusError
m.err = msg
return m, nil
@ -221,7 +221,7 @@ func updateChildren(msg tea.Msg, m model) (model, tea.Cmd) {
switch msg.(type) {
case tea.KeyMsg:
m.status = statusQuitting
return m, aztfyclient.Quit(m.ctx, m.meta)
return m, aztfexportclient.Quit(m.ctx, m.meta)
}
}
return m, nil

120
main.go
Просмотреть файл

@ -14,24 +14,24 @@ import (
"strconv"
"strings"
"github.com/Azure/aztfy/internal/cfgfile"
internalconfig "github.com/Azure/aztfy/internal/config"
"github.com/Azure/aztfy/internal/meta"
"github.com/Azure/aztfy/pkg/telemetry"
"github.com/Azure/aztfexport/internal/cfgfile"
internalconfig "github.com/Azure/aztfexport/internal/config"
"github.com/Azure/aztfexport/internal/meta"
"github.com/Azure/aztfexport/pkg/telemetry"
"github.com/gofrs/uuid"
"github.com/pkg/profile"
"github.com/Azure/aztfy/pkg/config"
"github.com/Azure/aztfy/pkg/log"
"github.com/Azure/aztfexport/pkg/config"
"github.com/Azure/aztfexport/pkg/log"
"github.com/hashicorp/go-hclog"
"github.com/magodo/armid"
"github.com/magodo/azlist/azlist"
"github.com/magodo/tfadd/providers/azurerm"
"github.com/Azure/aztfy/internal"
"github.com/Azure/aztfy/internal/ui"
"github.com/Azure/aztfy/internal/utils"
"github.com/Azure/aztfexport/internal"
"github.com/Azure/aztfexport/internal/ui"
"github.com/Azure/aztfexport/internal/utils"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
@ -88,7 +88,7 @@ func main() {
)
prepareConfigFile := func(ctx *cli.Context) error {
// Prepare the config directory at $HOME/.aztfy
// Prepare the config directory at $HOME/.aztfexport
homeDir, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("retrieving the user's HOME directory: %v", err)
@ -244,7 +244,7 @@ The output directory is not empty. Please choose one of actions below:
// Identify the subscription id, which comes from one of following (starts from the highest priority):
// - Command line option
// - Env variable: AZTFY_SUBSCRIPTION_ID
// - Env variable: AZTFEXPORT_SUBSCRIPTION_ID
// - Env variable: ARM_SUBSCRIPTION_ID
// - Output of azure cli, the current active subscription
if flagSubscriptionId == "" {
@ -262,14 +262,14 @@ The output directory is not empty. Please choose one of actions below:
&cli.StringFlag{
Name: "subscription-id",
// Honor the "ARM_SUBSCRIPTION_ID" as is used by the AzureRM provider, for easier use.
EnvVars: []string{"AZTFY_SUBSCRIPTION_ID", "ARM_SUBSCRIPTION_ID"},
EnvVars: []string{"AZTFEXPORT_SUBSCRIPTION_ID", "ARM_SUBSCRIPTION_ID"},
Aliases: []string{"s"},
Usage: "The subscription id",
Destination: &flagSubscriptionId,
},
&cli.StringFlag{
Name: "output-dir",
EnvVars: []string{"AZTFY_OUTPUT_DIR"},
EnvVars: []string{"AZTFEXPORT_OUTPUT_DIR"},
Aliases: []string{"o"},
Usage: "The output directory (will create the dir if it does not exist)",
Value: func() string {
@ -280,60 +280,60 @@ The output directory is not empty. Please choose one of actions below:
},
&cli.BoolFlag{
Name: "overwrite",
EnvVars: []string{"AZTFY_OVERWRITE"},
EnvVars: []string{"AZTFEXPORT_OVERWRITE"},
Aliases: []string{"f"},
Usage: "Overwrites the output directory if it is not empty (use with caution)",
Destination: &flagOverwrite,
},
&cli.BoolFlag{
Name: "append",
EnvVars: []string{"AZTFY_APPEND"},
EnvVars: []string{"AZTFEXPORT_APPEND"},
Usage: "Imports to the existing state file if any and does not clean up the output directory (local backend only)",
Destination: &flagAppend,
},
&cli.BoolFlag{
Name: "dev-provider",
EnvVars: []string{"AZTFY_DEV_PROVIDER"},
EnvVars: []string{"AZTFEXPORT_DEV_PROVIDER"},
Usage: fmt.Sprintf("Use the local development AzureRM provider, instead of the pinned provider in v%s", azurerm.ProviderSchemaInfo.Version),
Destination: &flagDevProvider,
},
&cli.StringFlag{
Name: "backend-type",
EnvVars: []string{"AZTFY_BACKEND_TYPE"},
EnvVars: []string{"AZTFEXPORT_BACKEND_TYPE"},
Usage: "The Terraform backend used to store the state",
Value: "local",
Destination: &flagBackendType,
},
&cli.StringSliceFlag{
Name: "backend-config",
EnvVars: []string{"AZTFY_BACKEND_CONFIG"},
EnvVars: []string{"AZTFEXPORT_BACKEND_CONFIG"},
Usage: "The Terraform backend config",
Destination: &flagBackendConfig,
},
&cli.BoolFlag{
Name: "full-properties",
EnvVars: []string{"AZTFY_FULL_PROPERTIES"},
EnvVars: []string{"AZTFEXPORT_FULL_PROPERTIES"},
Usage: "Includes all non-computed properties in the Terraform configuration. This may require manual modifications to produce a valid config",
Value: false,
Destination: &flagFullConfig,
},
&cli.IntFlag{
Name: "parallelism",
EnvVars: []string{"AZTFY_PARALLELISM"},
EnvVars: []string{"AZTFEXPORT_PARALLELISM"},
Usage: "Limit the number of parallel operations, i.e., resource discovery, import",
Value: 10,
Destination: &flagParallelism,
},
&cli.BoolFlag{
Name: "non-interactive",
EnvVars: []string{"AZTFY_NON_INTERACTIVE"},
EnvVars: []string{"AZTFEXPORT_NON_INTERACTIVE"},
Aliases: []string{"n"},
Usage: "Non-interactive mode",
Destination: &flagNonInteractive,
},
&cli.BoolFlag{
Name: "continue",
EnvVars: []string{"AZTFY_CONTINUE"},
EnvVars: []string{"AZTFEXPORT_CONTINUE"},
Aliases: []string{"k"},
Usage: "For non-interactive mode, continue on any import error",
Destination: &flagContinue,
@ -341,31 +341,31 @@ The output directory is not empty. Please choose one of actions below:
&cli.BoolFlag{
Name: "generate-mapping-file",
Aliases: []string{"g"},
EnvVars: []string{"AZTFY_GENERATE_MAPPING_FILE"},
EnvVars: []string{"AZTFEXPORT_GENERATE_MAPPING_FILE"},
Usage: "Only generate the resource mapping file, but does NOT import any resource",
Destination: &flagGenerateMappingFile,
},
&cli.BoolFlag{
Name: "hcl-only",
EnvVars: []string{"AZTFY_HCL_ONLY"},
EnvVars: []string{"AZTFEXPORT_HCL_ONLY"},
Usage: "Only generates HCL code (and mapping file), but not the files for resource management (e.g. the state file)",
Destination: &flagHCLOnly,
},
&cli.StringFlag{
Name: "module-path",
EnvVars: []string{"AZTFY_MODULE_PATH"},
EnvVars: []string{"AZTFEXPORT_MODULE_PATH"},
Usage: `The path of the module (e.g. "module1.module2") where the resources will be imported and config generated. Note that only modules whose "source" is local path is supported. Defaults to the root module.`,
Destination: &flagModulePath,
},
&cli.StringFlag{
Name: "log-path",
EnvVars: []string{"AZTFY_LOG_PATH"},
EnvVars: []string{"AZTFEXPORT_LOG_PATH"},
Usage: "The file path to store the log",
Destination: &flagLogPath,
},
&cli.StringFlag{
Name: "log-level",
EnvVars: []string{"AZTFY_LOG_LEVEL"},
EnvVars: []string{"AZTFEXPORT_LOG_LEVEL"},
Usage: `Log level, can be one of "ERROR", "WARN", "INFO", "DEBUG" and "TRACE"`,
Destination: &flagLogLevel,
Value: "INFO",
@ -374,21 +374,21 @@ The output directory is not empty. Please choose one of actions below:
// Hidden flags
&cli.BoolFlag{
Name: "mock-client",
EnvVars: []string{"AZTFY_MOCK_CLIENT"},
EnvVars: []string{"AZTFEXPORT_MOCK_CLIENT"},
Usage: "Whether to mock the client. This is for testing UI",
Hidden: true,
Destination: &hflagMockClient,
},
&cli.BoolFlag{
Name: "plain-ui",
EnvVars: []string{"AZTFY_PLAIN_UI"},
EnvVars: []string{"AZTFEXPORT_PLAIN_UI"},
Usage: "In non-interactive mode, print the progress information line by line, rather than the spinner UI",
Hidden: true,
Destination: &hflagPlainUI,
},
&cli.StringFlag{
Name: "profile",
EnvVars: []string{"AZTFY_PROFILE"},
EnvVars: []string{"AZTFEXPORT_PROFILE"},
Usage: "Profile the program, possible values are `cpu` and `memory`",
Hidden: true,
Destination: &hflagProfile,
@ -398,14 +398,14 @@ The output directory is not empty. Please choose one of actions below:
resourceFlags := append([]cli.Flag{
&cli.StringFlag{
Name: "name",
EnvVars: []string{"AZTFY_NAME"},
EnvVars: []string{"AZTFEXPORT_NAME"},
Usage: `The Terraform resource name.`,
Value: "res-0",
Destination: &flagResName,
},
&cli.StringFlag{
Name: "type",
EnvVars: []string{"AZTFY_TYPE"},
EnvVars: []string{"AZTFEXPORT_TYPE"},
Usage: `The Terraform resource type.`,
Destination: &flagResType,
},
@ -414,7 +414,7 @@ The output directory is not empty. Please choose one of actions below:
resourceGroupFlags := append([]cli.Flag{
&cli.StringFlag{
Name: "name-pattern",
EnvVars: []string{"AZTFY_NAME_PATTERN"},
EnvVars: []string{"AZTFEXPORT_NAME_PATTERN"},
Aliases: []string{"p"},
Usage: `The pattern of the resource name. The semantic of a pattern is the same as Go's os.CreateTemp()`,
Value: "res-",
@ -425,7 +425,7 @@ The output directory is not empty. Please choose one of actions below:
queryFlags := append([]cli.Flag{
&cli.BoolFlag{
Name: "recursive",
EnvVars: []string{"AZTFY_RECURSIVE"},
EnvVars: []string{"AZTFEXPORT_RECURSIVE"},
Aliases: []string{"r"},
Usage: "Recursively lists child resources of the resulting query resources",
Destination: &flagRecursive,
@ -435,27 +435,27 @@ The output directory is not empty. Please choose one of actions below:
mappingFileFlags := append([]cli.Flag{}, commonFlags...)
safeOutputFileNames := config.OutputFileNames{
TerraformFileName: "terraform.aztfy.tf",
ProviderFileName: "provider.aztfy.tf",
MainFileName: "main.aztfy.tf",
TerraformFileName: "terraform.aztfexport.tf",
ProviderFileName: "provider.aztfexport.tf",
MainFileName: "main.aztfexport.tf",
}
app := &cli.App{
Name: "aztfy",
Name: "aztfexport",
Version: getVersion(),
Usage: "A tool to bring existing Azure resources under Terraform's management",
UsageText: "aztfy <command> [option] <scope>",
UsageText: "aztfexport <command> [option] <scope>",
Before: prepareConfigFile,
Commands: []*cli.Command{
{
Name: "config",
Usage: `aztfy configuration command`,
UsageText: "aztfy config [subcommand]",
Usage: `Configuring the tool`,
UsageText: "aztfexport config [subcommand]",
Subcommands: []*cli.Command{
{
Name: "set",
Usage: `Set a configuration item for aztfy`,
UsageText: "aztfy config set key value",
Usage: `Set a configuration item for aztfexport`,
UsageText: "aztfexport config set key value",
Action: func(c *cli.Context) error {
if c.NArg() != 2 {
return fmt.Errorf("Please specify a configuration key and value")
@ -469,8 +469,8 @@ The output directory is not empty. Please choose one of actions below:
},
{
Name: "get",
Usage: `Get a configuration item for aztfy`,
UsageText: "aztfy config get key",
Usage: `Get a configuration item for aztfexport`,
UsageText: "aztfexport config get key",
Action: func(c *cli.Context) error {
if c.NArg() != 1 {
return fmt.Errorf("Please specify a configuration key")
@ -487,8 +487,8 @@ The output directory is not empty. Please choose one of actions below:
},
{
Name: "show",
Usage: `Show the full configuration for aztfy`,
UsageText: "aztfy config show",
Usage: `Show the full configuration for aztfexport`,
UsageText: "aztfexport config show",
Action: func(c *cli.Context) error {
cfg, err := cfgfile.GetConfig()
if err != nil {
@ -508,7 +508,7 @@ The output directory is not empty. Please choose one of actions below:
Name: "resource",
Aliases: []string{"res"},
Usage: "Exporting a single resource",
UsageText: "aztfy resource [option] <resource id>",
UsageText: "aztfexport resource [option] <resource id>",
Flags: resourceFlags,
Before: commandBeforeFunc,
Action: func(c *cli.Context) error {
@ -563,7 +563,7 @@ The output directory is not empty. Please choose one of actions below:
Name: "resource-group",
Aliases: []string{"rg"},
Usage: "Exporting a resource group and the nested resources resides within it",
UsageText: "aztfy resource-group [option] <resource group name>",
UsageText: "aztfexport resource-group [option] <resource group name>",
Flags: resourceGroupFlags,
Before: commandBeforeFunc,
Action: func(c *cli.Context) error {
@ -613,7 +613,7 @@ The output directory is not empty. Please choose one of actions below:
{
Name: "query",
Usage: "Exporting a customized scope of resources determined by an Azure Resource Graph where predicate",
UsageText: "aztfy query [option] <ARG where predicate>",
UsageText: "aztfexport query [option] <ARG where predicate>",
Flags: queryFlags,
Before: commandBeforeFunc,
Action: func(c *cli.Context) error {
@ -664,7 +664,7 @@ The output directory is not empty. Please choose one of actions below:
Name: "mapping-file",
Aliases: []string{"map"},
Usage: "Exporting a customized scope of resources determined by the resource mapping file",
UsageText: "aztfy mapping-file [option] <resource mapping file>",
UsageText: "aztfexport mapping-file [option] <resource mapping file>",
Flags: mappingFileFlags,
Before: commandBeforeFunc,
Action: func(c *cli.Context) error {
@ -753,14 +753,14 @@ func initLog(path string, flagLevel string) error {
}
logger := hclog.New(&hclog.LoggerOptions{
Name: "aztfy",
Name: "aztfexport",
Level: level,
Output: f,
}).StandardLogger(&hclog.StandardLoggerOptions{
InferLevels: true,
})
// Enable log for aztfy
// Enable log for aztfexport
log.SetLogger(logger)
// Enable log for azlist
@ -841,7 +841,7 @@ func buildAzureSDKCredAndClientOpt() (azcore.TokenCredential, *arm.ClientOptions
ClientOptions: policy.ClientOptions{
Cloud: cloudCfg,
Telemetry: policy.TelemetryOptions{
ApplicationID: "aztfy",
ApplicationID: "aztfexport",
Disabled: false,
},
Logging: policy.LogOptions{
@ -898,17 +898,17 @@ func realMain(ctx context.Context, cfg config.Config, batch, mockMeta, plainUI,
defer func() {
if result == nil {
log.Printf("[INFO] aztfy ends")
tc.Trace(telemetry.Info, "aztfy ends")
log.Printf("[INFO] aztfexport ends")
tc.Trace(telemetry.Info, "aztfexport ends")
} else {
log.Printf("[ERROR] aztfy ends with error: %v", result)
tc.Trace(telemetry.Error, fmt.Sprintf("aztfy ends with error: %v", result))
log.Printf("[ERROR] aztfexport ends with error: %v", result)
tc.Trace(telemetry.Error, fmt.Sprintf("aztfexport ends with error: %v", result))
}
tc.Close()
}()
log.Printf("[INFO] aztfy starts with config: %#v", cfg)
tc.Trace(telemetry.Info, "aztfy starts")
log.Printf("[INFO] aztfexport starts with config: %#v", cfg)
tc.Trace(telemetry.Info, "aztfexport starts")
// Run in non-interactive mode
if batch {

Просмотреть файл

@ -1,7 +1,7 @@
package config
import (
"github.com/Azure/aztfy/pkg/telemetry"
"github.com/Azure/aztfexport/pkg/telemetry"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/zclconf/go-cty/cty"
@ -23,7 +23,7 @@ type CommonConfig struct {
AzureSDKCredential azcore.TokenCredential
// AzureSDKClientOption specifies the Azure SDK client option
AzureSDKClientOption arm.ClientOptions
// OutputDir specifies the Terraform working directory for aztfy to import resources and generate TF configs.
// OutputDir specifies the Terraform working directory import resources and generate TF configs.
OutputDir string
// OutputFileNames specifies the output terraform filenames
OutputFileNames OutputFileNames
@ -38,7 +38,7 @@ type CommonConfig struct {
BackendConfig []string
// ProviderConfig specifies key value pairs that will be expanded to the terraform-provider-azurerm settings (i.e. `azurerm {}` block)
// Currently, only the attributes (rather than blocks) are supported.
// This is not used directly by aztfy binary as the provider configs can be set by environment variable already.
// This is not used directly by aztfexport as the provider configs can be set by environment variable already.
// While it is useful for module users that want support multi-users scenarios in one process (in which case changing env vars affect the whole process).
ProviderConfig map[string]cty.Value
// FullConfig specifies whether to export all (non computed-only) Terarform properties when generating TF configs.
@ -48,7 +48,7 @@ type CommonConfig struct {
// ModulePath specifies the path of the module (e.g. "module1.module2") where the resources will be imported and config generated.
// Note that only modules whose "source" is local path is supported. By default, it is the root module.
ModulePath string
// HCLOnly is a strange field, which is only used internally by aztfy to indicate whether to remove other files other than TF config at the end.
// HCLOnly is a strange field, which is only used internally by aztfexport to indicate whether to remove other files other than TF config at the end.
// External Go modules shoudl just ignore it.
HCLOnly bool
// TelemetryClient is a client to send telemetry
@ -77,6 +77,6 @@ type Config struct {
// TFResourceName specifies the TF resource name, this only applies to resource mode.
TFResourceName string
// TFResourceName specifies the TF resource type (if empty, aztfy will deduce the type), this only applies to resource mode.
// TFResourceName specifies the TF resource type (if empty, will try to deduce the type), this only applies to resource mode.
TFResourceType string
}

Просмотреть файл

@ -3,8 +3,8 @@ package meta
import (
"context"
"fmt"
"github.com/Azure/aztfy/internal/meta"
"github.com/Azure/aztfy/pkg/config"
"github.com/Azure/aztfexport/internal/meta"
"github.com/Azure/aztfexport/pkg/config"
)
type ImportItem = meta.ImportItem