Skip to content

Commit

Permalink
rename the code
Browse files Browse the repository at this point in the history
  • Loading branch information
magodo committed Mar 6, 2023
1 parent abdc6f2 commit 2cf388c
Show file tree
Hide file tree
Showing 37 changed files with 302 additions and 302 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/Azure/aztfy
module github.com/Azure/aztfexport

go 1.19

Expand Down
2 changes: 1 addition & 1 deletion internal/cfgfile/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/tidwall/sjson"
)

const CfgDirName = ".aztfy"
const CfgDirName = ".aztfexport"
const CfgFileName = "config.json"

type Configuration struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config_interactive.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config_noninteractive.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 15 additions & 15 deletions internal/meta/base_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/meta/importlist.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package meta

import (
"github.com/Azure/aztfy/internal/tfaddr"
"github.com/Azure/aztfexport/internal/tfaddr"
"github.com/magodo/armid"
)

Expand Down
8 changes: 4 additions & 4 deletions internal/meta/meta_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
8 changes: 4 additions & 4 deletions internal/meta/meta_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
10 changes: 5 additions & 5 deletions internal/meta/meta_res.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions internal/meta/meta_rg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/resourceset/azure_resource_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 4 additions & 4 deletions internal/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
4 changes: 2 additions & 2 deletions internal/test/cases/case.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/test/cases/case_applicationinsight_webtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
44 changes: 22 additions & 22 deletions internal/test/cases/case_compute_vm_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
}
}
Expand All @@ -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
Expand Down
Loading

0 comments on commit 2cf388c

Please sign in to comment.