From ed8a5ae16431003f627a59261585874859d6d1a4 Mon Sep 17 00:00:00 2001 From: magodo Date: Mon, 6 Mar 2023 12:10:45 +0800 Subject: [PATCH 1/6] rename the CI pipeline --- azure-pipelines.yml | 52 ++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b7c0c2e..3719874 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -15,7 +15,7 @@ stages: - stage: build pool: name: pool-ubuntu-2004 - displayName: "Build aztfy" + displayName: "Build" jobs: - job: build displayName: "Build Binaries" @@ -54,9 +54,9 @@ stages: set -e REVISION=`git rev-parse --short HEAD` mkdir build - name=aztfy + name=aztfexport if [[ $OS = windows ]]; then - name=aztfy.exe + name=aztfexport.exe fi GOOS="${OS}" GOARCH="${ARCH}" CGO_ENABLED=0 go build -trimpath -ldflags="-s -w -X 'main.version=${VERSION}' -X 'main.revision=${REVISION}'" -o build/$name displayName: "Go Build" @@ -123,7 +123,7 @@ stages: ARCH: amd64 steps: - task: DownloadPipelineArtifact@2 - displayName: "Download aztfy binary" + displayName: "Download binary" inputs: artifact: windows-$(ARCH) path: $(system.defaultWorkingDirectory)/dist/bin @@ -147,10 +147,10 @@ stages: cd $workdir/scripts/package/windows/build declare -A map=( [386]=x86 [amd64]=x64 ) export VERSION=${VERSION:1} - cp $workdir/dist/bin/aztfy.exe . + cp $workdir/dist/bin/aztfexport.exe . candle.exe -arch ${map[$ARCH]} -o setup.wxobj ./setup.wxs mkdir $workdir/dist/output - light.exe -out $workdir/dist/output/aztfy.msi ./setup.wxobj + light.exe -out $workdir/dist/output/aztfexport.msi ./setup.wxobj env: workdir: $(system.defaultWorkingDirectory) VERSION: ${{ parameters.version }} @@ -230,7 +230,7 @@ stages: - script: | set -e - chmod +x $WORKDIR/dist/source/aztfy + chmod +x $WORKDIR/dist/source/aztfexport declare -A deb_arch_map=( [386]=i386 [amd64]=amd64 [arm]=armhf [arm64]=arm64 ) declare -A rpm_arch_map=( [386]=i686 [amd64]=x86_64 [arm]=armv7hl [arm64]=aarch64 ) @@ -238,44 +238,44 @@ stages: # Build the image cd $WORKDIR/scripts/package/linux/build - docker build -t aztfybuild . + docker build -t aztfexportbuild . # Build deb package docker run -t --rm \ -v $WORKDIR/dist/source:/build/source \ -v $WORKDIR/dist/output:/build/output \ - aztfybuild \ + aztfexportbuild \ fpm \ - --name aztfy \ + --name aztfexport \ --license MPL-2.0 \ --version $version \ --description "A tool to bring existing Azure resources under Terraform's management" \ - --url "https://github.com/Azure/aztfy" \ + --url "https://github.com/Azure/aztfexport" \ --maintainer "magodo " \ --input-type dir \ --output-type deb \ --architecture ${deb_arch_map[$ARCH]} \ - --package /build/output/aztfy-$version-1-${deb_arch_map[$ARCH]}.deb \ - /build/source/aztfy=/usr/bin/aztfy + --package /build/output/aztfexport-$version-1-${deb_arch_map[$ARCH]}.deb \ + /build/source/aztfexport=/usr/bin/aztfexport # Build rpm package echo $version docker run -t --rm \ -v $WORKDIR/dist/source:/build/source \ -v $WORKDIR/dist/output:/build/output \ - aztfybuild \ + aztfexportbuild \ fpm \ - --name aztfy \ + --name aztfexport \ --license MPL-2.0 \ --version ${version} \ --description "A tool to bring existing Azure resources under Terraform's management" \ - --url "https://github.com/Azure/aztfy" \ + --url "https://github.com/Azure/aztfexport" \ --maintainer "magodo " \ --input-type dir \ --output-type rpm \ --architecture ${rpm_arch_map[$ARCH]} \ - --package /build/output/aztfy-$version-1-${rpm_arch_map[$ARCH]}.rpm \ - /build/source/aztfy=/usr/bin/aztfy + --package /build/output/aztfexport-$version-1-${rpm_arch_map[$ARCH]}.rpm \ + /build/source/aztfexport=/usr/bin/aztfexport displayName: "Build Packages" env: VERSION: ${{ parameters.version }} @@ -334,7 +334,7 @@ stages: runId: ${{ parameters.artifactBuildId }} - script: | set -e - NAME="aztfy" + NAME="aztfexport" OS_ARCH=( "windows:amd64" "windows:386" @@ -349,17 +349,17 @@ stages: for os_arch in "${OS_ARCH[@]}" ; do OS=${os_arch%%:*} ARCH=${os_arch#*:} - name=aztfy + name=aztfexport if [[ $OS = windows ]]; then - name=aztfy.exe + name=aztfexport.exe fi chmod +x dist/${OS}-${ARCH}/${name} zip -j release/${NAME}_${VERSION}_${OS}_${ARCH}.zip dist/${OS}-${ARCH}/${name} done # Copy MSI - cp dist/windows-386-msi/aztfy.msi release/${NAME}_${VERSION}_x86.msi - cp dist/windows-amd64-msi/aztfy.msi release/${NAME}_${VERSION}_x64.msi + cp dist/windows-386-msi/aztfexport.msi release/${NAME}_${VERSION}_x86.msi + cp dist/windows-amd64-msi/aztfexport.msi release/${NAME}_${VERSION}_x64.msi cd release shasum -a 256 *.zip *.msi > ${NAME}_SHA256SUMS @@ -397,7 +397,7 @@ stages: git config user.name "azure-terraform-bot" git config user.email "azure-terraform@microsoft.com" git tag -a "${VERSION}" -m "${VERSION}" - git push https://${PAT}@github.com/Azure/aztfy.git --tags + git push https://${PAT}@github.com/Azure/aztfexport.git --tags displayName: "Create and Push a Git Release" env: VERSION: ${{ parameters.version }} @@ -665,7 +665,7 @@ stages: iwr https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe git clone https://github.com/microsoft/winget-pkgs.git cd winget-pkgs - ..\wingetcreate.exe update --urls https://github.com/Azure/aztfy/releases/download/$env:VERSION/aztfy_$($env:VERSION)_x64.msi https://github.com/Azure/aztfy/releases/download/$env:VERSION/aztfy_$($env:VERSION)_x86.msi --version $env:VERSION.Substring(1) --submit --token $env:PAT Microsoft.Azure.Aztfy + ..\wingetcreate.exe update --urls https://github.com/Azure/aztfexport/releases/download/$env:VERSION/aztfexport_$($env:VERSION)_x64.msi https://github.com/Azure/aztfexport/releases/download/$env:VERSION/aztfexport_$($env:VERSION)_x86.msi --version $env:VERSION.Substring(1) --submit --token $env:PAT Microsoft.Azure.Aztfy displayName: "Create PR" env: VERSION: ${{ parameters.version }} @@ -692,7 +692,7 @@ stages: cd "$(brew --repository homebrew/core)" git config user.name "azure-terraform-bot" git config user.email "azure-terraform@microsoft.com" - HOMEBREW_GITHUB_API_TOKEN=${PAT} brew bump-formula-pr --version=${VERSION:1} --no-browse --force aztfy + HOMEBREW_GITHUB_API_TOKEN=${PAT} brew bump-formula-pr --version=${VERSION:1} --no-browse --force aztfexport displayName: "Create PR" env: VERSION: ${{ parameters.version }} From abdc6f27102eaebfdb774db522320664560f78e8 Mon Sep 17 00:00:00 2001 From: magodo Date: Mon, 6 Mar 2023 12:12:14 +0800 Subject: [PATCH 2/6] rename in scripts folder --- scripts/package/linux/verify/centos-8.sh | 2 +- scripts/package/linux/verify/debian-bullseye.sh | 2 +- scripts/package/linux/verify/debian-buster.sh | 2 +- scripts/package/linux/verify/fedora-34.sh | 2 +- scripts/package/linux/verify/fedora-35.sh | 2 +- scripts/package/linux/verify/fedora-36.sh | 2 +- scripts/package/linux/verify/ubuntu-bionic.sh | 2 +- scripts/package/linux/verify/ubuntu-focal.sh | 2 +- scripts/package/linux/verify/ubuntu-jammy.sh | 2 +- scripts/package/windows/build/setup.wxs | 10 +++++----- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/scripts/package/linux/verify/centos-8.sh b/scripts/package/linux/verify/centos-8.sh index 471aa1b..f1f85c6 100755 --- a/scripts/package/linux/verify/centos-8.sh +++ b/scripts/package/linux/verify/centos-8.sh @@ -14,7 +14,7 @@ while ((count <= total)); do echo "Try ($count/$total)" # See: https://access.redhat.com/solutions/2779441 dnf check-update --refresh || [[ $? == 100 ]] - dnf install -y aztfy && grep $version <(aztfy -v) && break + dnf install -y aztfexport && grep $version <(aztfexport -v) && break sleep 1m ((count++)) done diff --git a/scripts/package/linux/verify/debian-bullseye.sh b/scripts/package/linux/verify/debian-bullseye.sh index 04982fd..91e869a 100755 --- a/scripts/package/linux/verify/debian-bullseye.sh +++ b/scripts/package/linux/verify/debian-bullseye.sh @@ -13,7 +13,7 @@ count=1 while ((count <= total)); do echo "Try ($count/$total)" apt-get update - apt-get install -y aztfy && grep $version <(aztfy -v) && break + apt-get install -y aztfexport && grep $version <(aztfexport -v) && break sleep 1m ((count++)) done diff --git a/scripts/package/linux/verify/debian-buster.sh b/scripts/package/linux/verify/debian-buster.sh index 801431a..a468ad7 100755 --- a/scripts/package/linux/verify/debian-buster.sh +++ b/scripts/package/linux/verify/debian-buster.sh @@ -13,7 +13,7 @@ count=1 while ((count <= total)); do echo "Try ($count/$total)" apt-get update - apt-get install -y aztfy && grep $version <(aztfy -v) && break + apt-get install -y aztfexport && grep $version <(aztfexport -v) && break sleep 1m ((count++)) done diff --git a/scripts/package/linux/verify/fedora-34.sh b/scripts/package/linux/verify/fedora-34.sh index 6431c43..69cb871 100755 --- a/scripts/package/linux/verify/fedora-34.sh +++ b/scripts/package/linux/verify/fedora-34.sh @@ -16,7 +16,7 @@ while ((count <= total)); do echo "Try ($count/$total)" # See: https://access.redhat.com/solutions/2779441 dnf check-update --refresh || [[ $? == 100 ]] - dnf install -y aztfy && grep $version <(aztfy -v) && break + dnf install -y aztfexport && grep $version <(aztfexport -v) && break sleep 1m ((count++)) done diff --git a/scripts/package/linux/verify/fedora-35.sh b/scripts/package/linux/verify/fedora-35.sh index 8dcd0d5..770840e 100755 --- a/scripts/package/linux/verify/fedora-35.sh +++ b/scripts/package/linux/verify/fedora-35.sh @@ -16,7 +16,7 @@ while ((count <= total)); do echo "Try ($count/$total)" # See: https://access.redhat.com/solutions/2779441 dnf check-update --refresh || [[ $? == 100 ]] - dnf install -y aztfy && grep $version <(aztfy -v) && break + dnf install -y aztfexport && grep $version <(aztfexport -v) && break sleep 1m ((count++)) done diff --git a/scripts/package/linux/verify/fedora-36.sh b/scripts/package/linux/verify/fedora-36.sh index e2c9634..b1f8271 100755 --- a/scripts/package/linux/verify/fedora-36.sh +++ b/scripts/package/linux/verify/fedora-36.sh @@ -16,7 +16,7 @@ while ((count <= total)); do echo "Try ($count/$total)" # See: https://access.redhat.com/solutions/2779441 dnf check-update --refresh || [[ $? == 100 ]] - dnf install -y aztfy && grep $version <(aztfy -v) && break + dnf install -y aztfexport && grep $version <(aztfexport -v) && break sleep 1m ((count++)) done diff --git a/scripts/package/linux/verify/ubuntu-bionic.sh b/scripts/package/linux/verify/ubuntu-bionic.sh index bd5cb35..0f89706 100755 --- a/scripts/package/linux/verify/ubuntu-bionic.sh +++ b/scripts/package/linux/verify/ubuntu-bionic.sh @@ -13,7 +13,7 @@ count=1 while ((count <= total)); do echo "Try ($count/$total)" apt-get update - apt-get install -y aztfy && grep $version <(aztfy -v) && break + apt-get install -y aztfexport && grep $version <(aztfexport -v) && break sleep 1m ((count++)) done diff --git a/scripts/package/linux/verify/ubuntu-focal.sh b/scripts/package/linux/verify/ubuntu-focal.sh index 7ae8666..bbe91b6 100755 --- a/scripts/package/linux/verify/ubuntu-focal.sh +++ b/scripts/package/linux/verify/ubuntu-focal.sh @@ -13,7 +13,7 @@ count=1 while ((count <= total)); do echo "Try ($count/$total)" apt-get update - apt-get install -y aztfy && grep $version <(aztfy -v) && break + apt-get install -y aztfexport && grep $version <(aztfexport -v) && break sleep 1m ((count++)) done diff --git a/scripts/package/linux/verify/ubuntu-jammy.sh b/scripts/package/linux/verify/ubuntu-jammy.sh index 42a0e99..029de30 100755 --- a/scripts/package/linux/verify/ubuntu-jammy.sh +++ b/scripts/package/linux/verify/ubuntu-jammy.sh @@ -13,7 +13,7 @@ count=1 while ((count <= total)); do echo "Try ($count/$total)" apt-get update - apt-get install -y aztfy && grep $version <(aztfy -v) && break + apt-get install -y aztfexport && grep $version <(aztfexport -v) && break sleep 1m ((count++)) done diff --git a/scripts/package/windows/build/setup.wxs b/scripts/package/windows/build/setup.wxs index 8f2cc1c..328794b 100644 --- a/scripts/package/windows/build/setup.wxs +++ b/scripts/package/windows/build/setup.wxs @@ -6,13 +6,13 @@ - + - + - + @@ -20,7 +20,7 @@ - + @@ -28,7 +28,7 @@ - + Date: Mon, 6 Mar 2023 12:42:33 +0800 Subject: [PATCH 3/6] rename the code --- go.mod | 2 +- internal/cfgfile/cfg.go | 2 +- internal/config/config_interactive.go | 2 +- internal/config/config_noninteractive.go | 2 +- internal/meta/base_meta.go | 30 ++--- internal/meta/importlist.go | 2 +- internal/meta/meta_map.go | 8 +- internal/meta/meta_query.go | 8 +- internal/meta/meta_res.go | 10 +- internal/meta/meta_rg.go | 8 +- internal/resourceset/azure_resource_set.go | 2 +- internal/run.go | 8 +- internal/test/cases/case.go | 4 +- .../cases/case_applicationinsight_webtest.go | 4 +- internal/test/cases/case_compute_vm_disk.go | 44 +++---- internal/test/cases/case_function_app_slot.go | 36 +++--- .../test/cases/case_key_vault_nested_items.go | 32 ++--- internal/test/cases/case_signalr_service.go | 4 +- .../test/cases/case_storage_file_share.go | 20 +-- internal/test/query/query_test.go | 18 +-- internal/test/random.go | 2 +- internal/test/resmap/e2e_cases_test.go | 18 +-- internal/test/resource/e2e_cases_test.go | 20 +-- internal/test/resourcegroup/append_test.go | 16 +-- internal/test/resourcegroup/e2e_cases_test.go | 18 +-- internal/test/resourcegroup/module_test.go | 22 ++-- internal/test/utils.go | 14 +- internal/ui.go | 2 +- .../client.go | 4 +- internal/ui/importlist/importlist.go | 14 +- internal/ui/importlist/importlist_delegate.go | 8 +- internal/ui/importlist/item.go | 4 +- internal/ui/progress/progress.go | 16 +-- internal/ui/ui.go | 66 +++++----- main.go | 120 +++++++++--------- pkg/config/config.go | 10 +- pkg/meta/meta.go | 4 +- 37 files changed, 302 insertions(+), 302 deletions(-) rename internal/ui/{aztfyclient => aztfexportclient}/client.go (98%) diff --git a/go.mod b/go.mod index 3383588..68c7a8f 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/Azure/aztfy +module github.com/Azure/aztfexport go 1.19 diff --git a/internal/cfgfile/cfg.go b/internal/cfgfile/cfg.go index e7c2455..a53e7ee 100644 --- a/internal/cfgfile/cfg.go +++ b/internal/cfgfile/cfg.go @@ -11,7 +11,7 @@ import ( "github.com/tidwall/sjson" ) -const CfgDirName = ".aztfy" +const CfgDirName = ".aztfexport" const CfgFileName = "config.json" type Configuration struct { diff --git a/internal/config/config_interactive.go b/internal/config/config_interactive.go index 36532c5..e31d348 100644 --- a/internal/config/config_interactive.go +++ b/internal/config/config_interactive.go @@ -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 diff --git a/internal/config/config_noninteractive.go b/internal/config/config_noninteractive.go index 54886ea..e99128b 100644 --- a/internal/config/config_noninteractive.go +++ b/internal/config/config_noninteractive.go @@ -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 diff --git a/internal/meta/base_meta.go b/internal/meta/base_meta.go index 03e384d..a76cde3 100644 --- a/internal/meta/base_meta.go +++ b/internal/meta/base_meta.go @@ -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 { diff --git a/internal/meta/importlist.go b/internal/meta/importlist.go index bd1e03b..795e58e 100644 --- a/internal/meta/importlist.go +++ b/internal/meta/importlist.go @@ -1,7 +1,7 @@ package meta import ( - "github.com/Azure/aztfy/internal/tfaddr" + "github.com/Azure/aztfexport/internal/tfaddr" "github.com/magodo/armid" ) diff --git a/internal/meta/meta_map.go b/internal/meta/meta_map.go index 6efbd8b..84a3618 100644 --- a/internal/meta/meta_map.go +++ b/internal/meta/meta_map.go @@ -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" ) diff --git a/internal/meta/meta_query.go b/internal/meta/meta_query.go index bbc7a29..eba9388 100644 --- a/internal/meta/meta_query.go +++ b/internal/meta/meta_query.go @@ -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" ) diff --git a/internal/meta/meta_res.go b/internal/meta/meta_res.go index b5078c4..d41233a 100644 --- a/internal/meta/meta_res.go +++ b/internal/meta/meta_res.go @@ -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 diff --git a/internal/meta/meta_rg.go b/internal/meta/meta_rg.go index fb4a3fa..20a7dbd 100644 --- a/internal/meta/meta_rg.go +++ b/internal/meta/meta_rg.go @@ -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" ) diff --git a/internal/resourceset/azure_resource_set.go b/internal/resourceset/azure_resource_set.go index fc61c7c..98ae1dc 100644 --- a/internal/resourceset/azure_resource_set.go +++ b/internal/resourceset/azure_resource_set.go @@ -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" diff --git a/internal/run.go b/internal/run.go index dad49d0..e151274 100644 --- a/internal/run.go +++ b/internal/run.go @@ -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" ) diff --git a/internal/test/cases/case.go b/internal/test/cases/case.go index 8d360de..f9f7cef 100644 --- a/internal/test/cases/case.go +++ b/internal/test/cases/case.go @@ -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 { diff --git a/internal/test/cases/case_applicationinsight_webtest.go b/internal/test/cases/case_applicationinsight_webtest.go index 00619bd..cf9efa4 100644 --- a/internal/test/cases/case_applicationinsight_webtest.go +++ b/internal/test/cases/case_applicationinsight_webtest.go @@ -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{} diff --git a/internal/test/cases/case_compute_vm_disk.go b/internal/test/cases/case_compute_vm_disk.go index 261bed6..6bba4ab 100644 --- a/internal/test/cases/case_compute_vm_disk.go +++ b/internal/test/cases/case_compute_vm_disk.go @@ -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 diff --git a/internal/test/cases/case_function_app_slot.go b/internal/test/cases/case_function_app_slot.go index 1a13664..13ff11c 100644 --- a/internal/test/cases/case_function_app_slot.go +++ b/internal/test/cases/case_function_app_slot.go @@ -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 diff --git a/internal/test/cases/case_key_vault_nested_items.go b/internal/test/cases/case_key_vault_nested_items.go index e4a3f61..d4b8684 100644 --- a/internal/test/cases/case_key_vault_nested_items.go +++ b/internal/test/cases/case_key_vault_nested_items.go @@ -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 diff --git a/internal/test/cases/case_signalr_service.go b/internal/test/cases/case_signalr_service.go index 13e886d..ff66eef 100644 --- a/internal/test/cases/case_signalr_service.go +++ b/internal/test/cases/case_signalr_service.go @@ -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{} diff --git a/internal/test/cases/case_storage_file_share.go b/internal/test/cases/case_storage_file_share.go index fa60e13..433120f 100644 --- a/internal/test/cases/case_storage_file_share.go +++ b/internal/test/cases/case_storage_file_share.go @@ -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 diff --git a/internal/test/query/query_test.go b/internal/test/query/query_test.go index 58b99dc..d4daeeb 100644 --- a/internal/test/query/query_test.go +++ b/internal/test/query/query_test.go @@ -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) } diff --git a/internal/test/random.go b/internal/test/random.go index ed1bf87..0afa180 100644 --- a/internal/test/random.go +++ b/internal/test/random.go @@ -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)) } diff --git a/internal/test/resmap/e2e_cases_test.go b/internal/test/resmap/e2e_cases_test.go index 26053a6..1861407 100644 --- a/internal/test/resmap/e2e_cases_test.go +++ b/internal/test/resmap/e2e_cases_test.go @@ -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) { diff --git a/internal/test/resource/e2e_cases_test.go b/internal/test/resource/e2e_cases_test.go index 837f535..a0d7d18 100644 --- a/internal/test/resource/e2e_cases_test.go +++ b/internal/test/resource/e2e_cases_test.go @@ -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) { diff --git a/internal/test/resourcegroup/append_test.go b/internal/test/resourcegroup/append_test.go index 21f951e..2d8a94f 100644 --- a/internal/test/resourcegroup/append_test.go +++ b/internal/test/resourcegroup/append_test.go @@ -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) } diff --git a/internal/test/resourcegroup/e2e_cases_test.go b/internal/test/resourcegroup/e2e_cases_test.go index e11bac7..d354513 100644 --- a/internal/test/resourcegroup/e2e_cases_test.go +++ b/internal/test/resourcegroup/e2e_cases_test.go @@ -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) { diff --git a/internal/test/resourcegroup/module_test.go b/internal/test/resourcegroup/module_test.go index 26db929..ba701b4 100644 --- a/internal/test/resourcegroup/module_test.go +++ b/internal/test/resourcegroup/module_test.go @@ -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) } diff --git a/internal/test/utils.go b/internal/test/utils.go index d2a1cd0..88f3c6f 100644 --- a/internal/test/utils.go +++ b/internal/test/utils.go @@ -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) } diff --git a/internal/ui.go b/internal/ui.go index 18cd001..5bae0e7 100644 --- a/internal/ui.go +++ b/internal/ui.go @@ -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), } } diff --git a/internal/ui/aztfyclient/client.go b/internal/ui/aztfexportclient/client.go similarity index 98% rename from internal/ui/aztfyclient/client.go rename to internal/ui/aztfexportclient/client.go index 3cd945c..a0a10c5 100644 --- a/internal/ui/aztfyclient/client.go +++ b/internal/ui/aztfexportclient/client.go @@ -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" ) diff --git a/internal/ui/importlist/importlist.go b/internal/ui/importlist/importlist.go index 9a3bf9b..e10f8f0 100644 --- a/internal/ui/importlist/importlist.go +++ b/internal/ui/importlist/importlist.go @@ -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 diff --git a/internal/ui/importlist/importlist_delegate.go b/internal/ui/importlist/importlist_delegate.go index b4f4b1a..6273807 100644 --- a/internal/ui/importlist/importlist_delegate.go +++ b/internal/ui/importlist/importlist_delegate.go @@ -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 } diff --git a/internal/ui/importlist/item.go b/internal/ui/importlist/item.go index 4c413f1..fa59418 100644 --- a/internal/ui/importlist/item.go +++ b/internal/ui/importlist/item.go @@ -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" ) diff --git a/internal/ui/progress/progress.go b/internal/ui/progress/progress.go index 1f3cf3c..89445f8 100644 --- a/internal/ui/progress/progress.go +++ b/internal/ui/progress/progress.go @@ -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: diff --git a/internal/ui/ui.go b/internal/ui/ui.go index d52ae67..d207de8 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -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 diff --git a/main.go b/main.go index 964f8a5..65f4f93 100644 --- a/main.go +++ b/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 [option] ", + UsageText: "aztfexport [option] ", 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] ", + UsageText: "aztfexport resource [option] ", 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] ", + UsageText: "aztfexport resource-group [option] ", 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] ", + UsageText: "aztfexport query [option] ", 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] ", + UsageText: "aztfexport mapping-file [option] ", 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 { diff --git a/pkg/config/config.go b/pkg/config/config.go index 40daf6d..c2f62c0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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 } diff --git a/pkg/meta/meta.go b/pkg/meta/meta.go index e56fea4..b885f6a 100644 --- a/pkg/meta/meta.go +++ b/pkg/meta/meta.go @@ -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 From 9777f37379ea4cb7b81dd1e6fbf949c23a95b786 Mon Sep 17 00:00:00 2001 From: magodo Date: Mon, 6 Mar 2023 13:44:19 +0800 Subject: [PATCH 4/6] update ci --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3719874..74fb660 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -665,7 +665,7 @@ stages: iwr https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe git clone https://github.com/microsoft/winget-pkgs.git cd winget-pkgs - ..\wingetcreate.exe update --urls https://github.com/Azure/aztfexport/releases/download/$env:VERSION/aztfexport_$($env:VERSION)_x64.msi https://github.com/Azure/aztfexport/releases/download/$env:VERSION/aztfexport_$($env:VERSION)_x86.msi --version $env:VERSION.Substring(1) --submit --token $env:PAT Microsoft.Azure.Aztfy + ..\wingetcreate.exe update --urls https://github.com/Azure/aztfexport/releases/download/$env:VERSION/aztfexport_$($env:VERSION)_x64.msi https://github.com/Azure/aztfexport/releases/download/$env:VERSION/aztfexport_$($env:VERSION)_x86.msi --version $env:VERSION.Substring(1) --submit --token $env:PAT Microsoft.Azure.AztfExport displayName: "Create PR" env: VERSION: ${{ parameters.version }} From 3a925ebd99bd1265819c05459b405ff24275f01a Mon Sep 17 00:00:00 2001 From: magodo Date: Mon, 6 Mar 2023 14:05:13 +0800 Subject: [PATCH 5/6] rename in the ui title --- internal/ui/ui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/ui/ui.go b/internal/ui/ui.go index d207de8..4cef6de 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -261,7 +261,7 @@ func (m model) View() string { } func (m model) logoView() string { - return "\n" + common.TitleStyle.Render(" Azure Terrafy ") + "\n\n" + return "\n" + common.TitleStyle.Render(" Microsoft Azure Export for Terraform ") + "\n\n" } func importErrorView(m model) string { From 9deea3e0909b56df21680e7e8b1d757a3e8ecf80 Mon Sep 17 00:00:00 2001 From: magodo Date: Mon, 6 Mar 2023 14:09:24 +0800 Subject: [PATCH 6/6] readme --- README.md | 97 ++++++++++++++++++++++++++----------------------------- 1 file changed, 45 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 71f91c0..f5ab292 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,25 @@ -## Azure Terrafy +## Microsoft Azure Export for Terraform A tool to bring your existing Azure resources under the management of Terraform. ## Goal -Azure Terrafy imports the resources that are supported by the [Terraform AzureRM provider](https://github.com/hashicorp/terraform-provider-azurerm) into the Terraform state, and generates the corresponding Terraform configuration. Both the Terraform state and configuration are expected to be consistent with the resources' remote state, i.e., `terraform plan` shows no diff. The user then is able to use Terraform to manage these resources. +`aztfexport` imports the resources that are supported by the [Terraform AzureRM provider](https://github.com/hashicorp/terraform-provider-azurerm) into the Terraform state, and generates the corresponding Terraform configuration. Both the Terraform state and configuration are expected to be consistent with the resources' remote state, i.e., `terraform plan` shows no diff. The user then is able to use Terraform to manage these resources. ## Non Goal -The Terraform configurations generated by `aztfy` are not meant to be comprehensive and do not ensure that the infrastructure can be fully reproduced from the generated configurations. For details, please refer to the [limitation](#limitation). +The Terraform configurations generated by `aztfexport` are not meant to be comprehensive and do not ensure that the infrastructure can be fully reproduced from the generated configurations. For details, please refer to the [limitation](#limitation). ## Install ### From Release -Precompiled binaries and Window MSI are available at [Releases](https://github.com/Azure/aztfy/releases). +Precompiled binaries and Window MSI are available at [Releases](https://github.com/Azure/aztfexport/releases). ### From Go toolchain ```bash -go install github.com/Azure/aztfy@latest +go install github.com/Azure/aztfexport@latest ``` ### From Package Manager @@ -27,13 +27,13 @@ go install github.com/Azure/aztfy@latest #### Windows ```bash -winget install aztfy +winget install aztfexport ``` #### Homebrew (Linux/macOS) ```bash -brew install aztfy +brew install aztfexport ``` #### dnf (Linux) @@ -59,7 +59,7 @@ Supported versions: 3. Install: ``` - dnf install aztfy + dnf install aztfexport ``` #### apt (Linux) @@ -85,56 +85,50 @@ Supported versions: 3. Install: ``` - apt-get install aztfy + apt-get install aztfexport ``` -#### AUR (Linux) - -```bash -yay -S aztfy -``` - ## Precondition -`aztfy` requires a `terraform` executable installed in the `$PATH`, whose version `>= v0.12`. +`aztfexport` requires a `terraform` executable installed in the `$PATH`, whose version `>= v0.12`. ## Usage Follow the [authentication guide](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs#authenticating-to-azure) from the Terraform AzureRM provider to authenticate to Azure. -Then you can go ahead and run `aztfy resource `, `aztfy resource-group ` or `aztfy query ` to import a single resource, a resource group including child resources, or a customized set of resources by an Azure Resource Graph query. +Then you can go ahead and run `aztfexport resource `, `aztfexport resource-group ` or `aztfexport query ` to import a single resource, a resource group including child resources, or a customized set of resources by an Azure Resource Graph query. -### Terrafy a Single Resource +### Export a Single Resource -`aztfy resource [option] ` terrafies a single resource by its Azure control plane ID. +`aztfexport resource [option] ` exports a single resource by its Azure control plane ID. E.g. ```shell -aztfy resource /subscriptions/0000/resourceGroups/rg1/providers/Microsoft.Compute/virtualMachines/vm1 +aztfexport resource /subscriptions/0000/resourceGroups/rg1/providers/Microsoft.Compute/virtualMachines/vm1 ``` The command will automatically identify the Terraform resource type (e.g. correctly identifies above resource as `azurerm_linux_virtual_machine`), and import it into state file and generate the Terraform configuration. > ❗ For data plane only or property-like resources, the Azure resource ID is using a pesudo format, as is defined [here](https://github.com/magodo/aztft#pesudo-resource-id). -### Terrafy a Resource Group +### Export a Resource Group -`aztfy resource-group [option] ` terrafies a resource group and its including resources by its name. +`aztfexport resource-group [option] ` exports a resource group and its including resources by its name. -### Terrafy a Customized Set of Resources +### Export a Customized Set of Resources -`aztfy query [option] ` terrafies a set of resources (and its including resources with `--recursive`) by an Azure Resource Graph [`where` predicate](https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/whereoperator). Note that you can combine multiple conditions in one `where` predicate, e.g. `resourceGroup =~ "my-rg" and type =~ "microsoft.network/virtualnetworks"`. +`aztfexport query [option] ` exports a set of resources (and its including resources with `--recursive`) by an Azure Resource Graph [`where` predicate](https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/whereoperator). Note that you can combine multiple conditions in one `where` predicate, e.g. `resourceGroup =~ "my-rg" and type =~ "microsoft.network/virtualnetworks"`. -> 💡 Resource group mode is the same as running `aztfy query --recursive "resourceGroup =~ 'my-rg'"`, except it also add on the resource group itself. +> 💡 Resource group mode is the same as running `aztfexport query --recursive "resourceGroup =~ 'my-rg'"`, except it also add on the resource group itself. -`aztfy` depends on `azlist`, which uses ARG behind the scenes. `azlist` will first make an ARG call with the given where predicate, then if `--recursive` is specified, it will recursively call the "LIST" on the known child resource types. Since ARG only returns ARM tracked resources at this moment, but not for the RP proxy resources (e.g. subnet, network security rules, storage containers, etc). If you uses predicate like `type =~ "microsoft.network/virtualnetworks/subnets"`, it returns you nothing since subnet is not an ARM tracked resource. +`aztfexport` depends on `azlist`, which uses ARG behind the scenes. `azlist` will first make an ARG call with the given where predicate, then if `--recursive` is specified, it will recursively call the "LIST" on the known child resource types. Since ARG only returns ARM tracked resources at this moment, but not for the RP proxy resources (e.g. subnet, network security rules, storage containers, etc). If you uses predicate like `type =~ "microsoft.network/virtualnetworks/subnets"`, it returns you nothing since subnet is not an ARM tracked resource. To workaround above, you can query with a bigger scope (e.g. `type =~ "microsoft.network/virtualnetworks"`) in interactive mode, then manually remove the resources other than subnets. -### Terrafy a Predefined Set of Resources +### Export a Predefined Set of Resources -`aztfy mapping-file [option] ` terrafies a set of resources that is defined in the resource mapping file. +`aztfexport mapping-file [option] ` exports a set of resources that is defined in the resource mapping file. The format of the mapping file is defined below: @@ -158,18 +152,18 @@ Example: ```json { - "/subscriptions/0000/resourceGroups/aztfy-vmdisk": { - "resource_id": "/subscriptions/0000/resourceGroups/aztfy-vmdisk", + "/subscriptions/0000/resourceGroups/aztfexport-vmdisk": { + "resource_id": "/subscriptions/0000/resourceGroups/aztfexport-vmdisk", "resource_type": "azurerm_resource_group", "resource_name": "res-1" }, - "/subscriptions/0000/resourceGroups/aztfy-vmdisk/providers/Microsoft.Compute/disks/aztfy-test-test": { - "resource_id": "/subscriptions/0000/resourceGroups/aztfy-vmdisk/providers/Microsoft.Compute/disks/aztfy-test-test", + "/subscriptions/0000/resourceGroups/aztfexport-vmdisk/providers/Microsoft.Compute/disks/aztfexport-test-test": { + "resource_id": "/subscriptions/0000/resourceGroups/aztfexport-vmdisk/providers/Microsoft.Compute/disks/aztfexport-test-test", "resource_type": "azurerm_managed_disk", "resource_name": "res-2" }, - "/subscriptions/0000/resourceGroups/aztfy-vmdisk/providers/Microsoft.Compute/virtualMachines/aztfy-test-test": { - "resource_id": "/subscriptions/0000/resourceGroups/aztfy-vmdisk/providers/Microsoft.Compute/virtualMachines/aztfy-test-test", + "/subscriptions/0000/resourceGroups/aztfexport-vmdisk/providers/Microsoft.Compute/virtualMachines/aztfexport-test-test": { + "resource_id": "/subscriptions/0000/resourceGroups/aztfexport-vmdisk/providers/Microsoft.Compute/virtualMachines/aztfexport-test-test", "resource_type": "azurerm_linux_virtual_machine", "resource_name": "res-3" }, @@ -177,47 +171,47 @@ Example: } ``` -You can generate the mapping file in all other modes (i.e. `resource`, `resource-group`, `query`) by specifying the `--generate-mapping-file` option when running non-interactively, or press s when running interactively in the resource list stage. Also, each run of `aztfy` will generate the resource mapping file for you, to record what resources have been imported. +You can generate the mapping file in all other modes (i.e. `resource`, `resource-group`, `query`) by specifying the `--generate-mapping-file` option when running non-interactively, or press s when running interactively in the resource list stage. Also, each run of `aztfexport` will generate the resource mapping file for you, to record what resources have been imported. Of course, you are welcome to manually construct or edit the mapping file. Note that only the object value in the mapping file matters, while the key just plays as an identifier in this mode. ### Interactive vs Non-Interactive -By default `aztfy` runs in interactive mode, whilst you can also run in non-interactive mode by adding the `--non-interactive`/`-n` option. +By default `aztfexport` runs in interactive mode, whilst you can also run in non-interactive mode by adding the `--non-interactive`/`-n` option. #### Interactive mode -In interactive mode, `aztfy` list all the resources resides in the specified resource group or customized set. For each resource, `aztfy` will try to recognize the corresponding Terraform resource type. If it finds one, the line will be prefixed by a 💡 as an indicator. Otherwise, user is expected to input the Terraform resource address in form of `.` (e.g. `azurerm_linux_virtual_machine.test`). Users can press `r` to see the possible resource type(s) for the selected resource. +In interactive mode, `aztfexport` list all the resources resides in the specified resource group or customized set. For each resource, `aztfexport` will try to recognize the corresponding Terraform resource type. If it finds one, the line will be prefixed by a 💡 as an indicator. Otherwise, user is expected to input the Terraform resource address in form of `.` (e.g. `azurerm_linux_virtual_machine.test`). Users can press `r` to see the possible resource type(s) for the selected resource. In some cases, there are Azure resources that have no corresponding Terraform resources (e.g. due to lacks of Terraform support), or some resources might be created as a side effect of provisioning another resource (e.g. the OS Disk resource is created automatically when provisioning a VM). In these cases, you can skip these resources without typing anything. -After going through all the resources to be imported, users press `w` to instruct `aztfy` to proceed importing resources into Terraform state and generating the Terraform configuration. +After going through all the resources to be imported, users press `w` to instruct `aztfexport` to proceed importing resources into Terraform state and generating the Terraform configuration. #### Non-Interactive mode -In non-interactive mode, `aztfy` only imports the recognized resources, and skip the others. Users can further specify the `--continue`/`-k` option to make the tool continue even on hitting any import error. +In non-interactive mode, `aztfexport` only imports the recognized resources, and skip the others. Users can further specify the `--continue`/`-k` option to make the tool continue even on hitting any import error. ### Remote Backend -By default `aztfy` uses local backend to store the state file. While it is also possible to use [remote backend](https://www.terraform.io/language/settings/backends), via the `--backend-type` and `--backend-config` options. +By default `aztfexport` uses local backend to store the state file. While it is also possible to use [remote backend](https://www.terraform.io/language/settings/backends), via the `--backend-type` and `--backend-config` options. -E.g. to use the [`azurerm` backend](https://www.terraform.io/language/settings/backends/azurerm#azurerm), users can invoke `aztfy` like following: +E.g. to use the [`azurerm` backend](https://www.terraform.io/language/settings/backends/azurerm#azurerm), users can invoke `aztfexport` like following: ```shell -aztfy [subcommand] --backend-type=azurerm --backend-config=resource_group_name= --backend-config=storage_account_name= --backend-config=container_name= --backend-config=key=terraform.tfstate +aztfexport [subcommand] --backend-type=azurerm --backend-config=resource_group_name= --backend-config=storage_account_name= --backend-config=container_name= --backend-config=key=terraform.tfstate ``` ### Import Into Existing Local State -For local backend, `aztfy` will by default ensure the output directory is empty at the very begining. This is to avoid any conflicts happen for existing user files, including the terraform configuration, provider configuration, the state file, etc. As a result, `aztfy` generates a pretty new workspace for users. +For local backend, `aztfexport` will by default ensure the output directory is empty at the very begining. This is to avoid any conflicts happen for existing user files, including the terraform configuration, provider configuration, the state file, etc. As a result, `aztfexport` generates a pretty new workspace for users. -One limitation of doing so is users can't import resources to existing state file via `aztfy`. To support this scenario, you can use the `--append` option. This option will make `aztfy` skip the empty guarantee for the output directory. If the output directory is empty, then it has no effect. Otherwise, it will ensure the provider setting (create a file for it if not exists). Then it proceeds the following steps. +One limitation of doing so is users can't import resources to existing state file via `aztfexport`. To support this scenario, you can use the `--append` option. This option will make `aztfexport` skip the empty guarantee for the output directory. If the output directory is empty, then it has no effect. Otherwise, it will ensure the provider setting (create a file for it if not exists). Then it proceeds the following steps. -This means if the output directory has an active Terraform workspace, i.e. there exists a state file, any resource imported by the `aztfy` will be imported into that state file. Especially, the file generated by `aztfy` in this case will be named differently than normal, where each file will has `.aztfy` suffix before the extension (e.g. `main.aztfy.tf`), to avoid potential file name conflicts. If you run `aztfy --append` multiple times, the generated config in `main.aztfy.tf` will be appended in each run. +This means if the output directory has an active Terraform workspace, i.e. there exists a state file, any resource imported by the `aztfexport` will be imported into that state file. Especially, the file generated by `aztfexport` in this case will be named differently than normal, where each file will has `.aztfexport` suffix before the extension (e.g. `main.aztfexport.tf`), to avoid potential file name conflicts. If you run `aztfexport --append` multiple times, the generated config in `main.aztfexport.tf` will be appended in each run. ### Config -`aztfy` will create a configuration file at `$HOME/.aztfy/config.json`. This file is aim to be managed by command `aztfy config [subcommand]`, which includes following subcommands: +`aztfexport` will create a configuration file at `$HOME/.aztfexport/config.json`. This file is aim to be managed by command `aztfexport config [subcommand]`, which includes following subcommands: - `get`: Get a config item - `set`: Set a config item @@ -230,15 +224,15 @@ Currently, following config items are supported: ## How it Works -`aztfy` leverage [`aztft`](https://github.com/magodo/aztft) to identify the Terraform resource type on its Azure resource ID. Then it runs `terraform import` under the hood to import each resource. Afterwards, it runs [`tfadd`](https://github.com/magodo/tfadd) to generate the Terraform template for each imported resource. +`aztfexport` leverage [`aztft`](https://github.com/magodo/aztft) to identify the Terraform resource type on its Azure resource ID. Then it runs `terraform import` under the hood to import each resource. Afterwards, it runs [`tfadd`](https://github.com/magodo/tfadd) to generate the Terraform template for each imported resource. ## Demo -[![asciicast](https://asciinema.org/a/xUnzCWXY0WYpC9nbBbMMhwb5L.svg)](https://asciinema.org/a/xUnzCWXY0WYpC9nbBbMMhwb5L) +[![asciicast](https://asciinema.org/a/sKYqzSiE5bpBJCB4BM2HjvF4j.svg)](https://asciinema.org/a/sKYqzSiE5bpBJCB4BM2HjvF4j) ## Limitation -There are several limitations causing `aztfy` can hardly generate reproducible Terraform configurations. +There are several limitations causing `aztfexport` can hardly generate reproducible Terraform configurations. ### AzureRM Provider Validation @@ -246,11 +240,10 @@ When generating the Terraform configuration, not all properties of the resource One reason is because there are flexible cross-property constraints defined in the AzureRM Terraform provider. E.g. `property_a` conflits with `property_b`. This might due to the nature of the API, or might be due to some deprecation process of the provider (e.g. `property_a` is deprecated in favor of `property_b`, but kept for backwards compatibility). These constraints require some properties must be absent in the Terraform configuration, otherwise, the configuration is not a valid and will fail during `terraform validate`. -Another reason is that an Azure resource can be a property of its parent resource (e.g. `azurerm_subnet` can be its own resource, or be a property of `azurerm_virtual_network`). Per Terraform's best practice, users should only use one of the forms, not both. `aztfy` chooses to always generate all the resources, but omit the property in the parent resource that represents the child resource. +Another reason is that an Azure resource can be a property of its parent resource (e.g. `azurerm_subnet` can be its own resource, or be a property of `azurerm_virtual_network`). Per Terraform's best practice, users should only use one of the forms, not both. `aztfexport` chooses to always generate all the resources, but omit the property in the parent resource that represents the child resource. ## Additional Resources -- [The aztfy Github Page](https://azure.github.io/aztfy): Everything about aztfy, including comparisons with other existing import solutions. -- [Kyle Ruddy's Blog about aztfy](https://www.kmruddy.com/2022/terrafy-existing-azure-resources/): A live use of `aztfy`, explaining the pros and cons. +- [The aztfexport Github Page](https://azure.github.io/aztfexport): Everything about aztfexport, including comparisons with other existing import solutions. - [aztft](https://github.com/magodo/aztft): A Go program and library for identifying the correct Terraform AzureRM provider resource type on the Azure resource id. - [tfadd](https://github.com/magodo/tfadd): A Go program and library for generating Terraform configuration from Terraform state.