Merge pull request #534 from magodo/slog

Changing the logger type to `slog.Logger`
This commit is contained in:
magodo 2024-06-14 16:20:13 +08:00 коммит произвёл GitHub
Родитель 523f5b841b 9e046f0745
Коммит dd9c5fa3c7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
14 изменённых файлов: 189 добавлений и 112 удалений

2
.github/workflows/codeql.yml поставляемый
Просмотреть файл

@ -34,7 +34,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.19
go-version: 1.22
- name: Build
run: |

10
.github/workflows/pr.yaml поставляемый
Просмотреть файл

@ -8,8 +8,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.19
go-version: 1.22
- name: Check out code into the Go module directory
uses: actions/checkout@v2
@ -22,10 +21,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Run Gosec Security Scanner
uses: securego/gosec@v2.16.0
uses: securego/gosec@2ae137abcf405533ad6e549e9363e58e4f6e8b7d
with:
args: './...'
@ -36,7 +34,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.19
go-version: 1.22
- name: Check out code into the Go module directory
uses: actions/checkout@v2

16
flag.go
Просмотреть файл

@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"os/exec"
"strings"
"github.com/Azure/aztfexport/internal/cfgfile"
@ -15,8 +14,6 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/gofrs/uuid"
"github.com/hashicorp/go-hclog"
"github.com/magodo/terraform-client-go/tfclient"
"github.com/urfave/cli/v2"
)
@ -335,6 +332,7 @@ func buildAzureSDKCredAndClientOpt(fset FlagSet) (azcore.TokenCredential, *arm.C
}
}
// BuildCommonConfig builds the CommonConfig from the FlagSet, except the TFClient, which is built afterwards as it requires a logger.
func (f FlagSet) BuildCommonConfig() (config.CommonConfig, error) {
cred, clientOpt, err := buildAzureSDKCredAndClientOpt(f)
if err != nil {
@ -369,17 +367,5 @@ func (f FlagSet) BuildCommonConfig() (config.CommonConfig, error) {
}
}
if f.hflagTFClientPluginPath != "" {
// #nosec G204
tfc, err := tfclient.New(tfclient.Option{
Cmd: exec.Command(flagset.hflagTFClientPluginPath),
Logger: hclog.NewNullLogger(),
})
if err != nil {
return cfg, err
}
cfg.TFClient = tfc
}
return cfg, nil
}

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

@ -1,6 +1,6 @@
module github.com/Azure/aztfexport
go 1.19
go 1.21
require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0
@ -11,7 +11,7 @@ require (
github.com/charmbracelet/bubbletea v0.22.1
github.com/charmbracelet/lipgloss v0.5.0
github.com/gofrs/uuid v3.3.0+incompatible
github.com/hashicorp/go-hclog v1.3.1
github.com/hashicorp/go-hclog v1.6.3
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/hc-install v0.6.2
github.com/hashicorp/hcl/v2 v2.17.0
@ -20,8 +20,9 @@ require (
github.com/hashicorp/terraform-json v0.19.0
github.com/hexops/gotextdiff v1.0.3
github.com/magodo/armid v0.0.0-20230511151020-27880e5961c3
github.com/magodo/azlist v0.0.0-20231101012443-e30f2da262c1
github.com/magodo/azlist v0.0.0-20240613024003-b4529218cc6a
github.com/magodo/aztft v0.3.1-0.20240429022627-002cdc06267a
github.com/magodo/slog2hclog v0.0.0-20240614031327-090ebd72a033
github.com/magodo/spinner v0.0.0-20220720073946-50f31b2dc5a6
github.com/magodo/terraform-client-go v0.0.0-20230323074119-02ceb732dd25
github.com/magodo/textinput v0.0.0-20210913072708-7d24f2b4b0c0

40
go.sum
Просмотреть файл

@ -1,6 +1,7 @@
code.cloudfoundry.org/clock v0.0.0-20180518195852-02e53af36e6c h1:5eeuG0BHx1+DHeT3AP+ISKZ2ht1UjGhm581ljqYpVeQ=
code.cloudfoundry.org/clock v0.0.0-20180518195852-02e53af36e6c/go.mod h1:QD9Lzhd/ux6eNQVUDVRJX/RKTigpewimNYBi7ivZKY8=
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 h1:fb8kj/Dh4CSwgsOzHeZY4Xh68cFVbzXx+ONXGMY//4w=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0/go.mod h1:uReU2sSxZExRPBAg3qKzmAucSi51+SP1OhohieR821Q=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 h1:BMAjVKJM0U/CYF27gA0ZMmXGkOcvfFtD0oHVZ1TIPRI=
@ -46,6 +47,7 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/frontdoor/armfrontdoor v1.
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/hdinsight/armhdinsight v1.0.0 h1:YiFulhmwcgOnjlNDqu1c8dVHkhNd/wlZIVcV32Pq0kA=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/hdinsight/armhdinsight v1.0.0/go.mod h1:g0o51pdbR/Zn9w3X61C+UrYfS98UpCcp8+1KTceXD0A=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2/go.mod h1:FbdwsQ2EzwvXxOPcMFYO8ogEc9uMMIj3YkmCdXdAFmk=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/iothub/armiothub v1.1.1 h1:Dh8SxVXcSyQN76LI4IseKyrnqyTUsx336Axg8zDYSMs=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/iothub/armiothub v1.1.1/go.mod h1:fqmmortNEICbosf7BfNVO3wWs6Cz/pkxYfExJC97Vy8=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/keyvault/armkeyvault v1.0.0 h1:Jc2KcpCDMu7wJfkrzn7fs/53QMDXH78GuqnH4HOd7zs=
@ -57,9 +59,11 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/logic/armlogic v1.1.1/go.m
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/machinelearning/armmachinelearning/v3 v3.0.0 h1:C8jlM/kxDVoUbmPJPp0C6Tz8VfiuAe+Lwcdw2DeyRPE=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/machinelearning/armmachinelearning/v3 v3.0.0/go.mod h1:6IMUN/Qwv/Y6aL21XxWGcQXfRYrivO4qFPWsbf0wVJI=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0 h1:pPvTJ1dY0sA35JOeFq6TsY2xj6Z85Yo23Pj4wCCvu4o=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0/go.mod h1:mLfWfj8v3jfWKsL9G4eoBoXVcsqcIUTapmdKy7uGOp0=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor v0.7.0 h1:U6aSmNaC/WWDlHnL0e+SxQlvYmcjdoBLFjNir8AZBe0=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor v0.7.0/go.mod h1:qDMzzI3qK0Oi9wpbRIaBoYyRYg+1UJZ0I2/Y4VxoVU4=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v0.6.0 h1:zSHpZY39hfFpVNixDoFOUeLwBBX0SIRe32HaWg03R8k=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v0.6.0/go.mod h1:Yu9z4VU4VeNRoZQMjAKwzXJpNAZ8SlyVg+yHyDVqvi8=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/netapp/armnetapp v1.0.0 h1:06Xuh5qDiIaR+5IQNWz8K9ZV4banx4SOx1DsQiJOqqA=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/netapp/armnetapp v1.0.0/go.mod h1:bAQDVyOKushEZ1+h7Q157Xn3hpaB/TewYIhiWqAh71U=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork v1.1.0 h1:QM6sE5k2ZT/vI5BEe0r7mqjsUSnhVBFbOsVkEuaEfiA=
@ -99,10 +103,13 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/workloads/armworkloads v1.
github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 h1:WpB/QDNLpMw72xHJc34BNNykqSOeEJDAWkhf0u12/Jk=
github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg=
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0 h1:MzVXffFUye+ZcSR6opIgz9Co7WcDx6ZcY+RjfFHoA0I=
github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM=
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
@ -122,30 +129,39 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWR
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/felixge/fgprof v0.9.3 h1:VvyZxILNuCiUCSXtPtYmmtGvb65nqXh2QFWc0Wpf2/g=
github.com/felixge/fgprof v0.9.3/go.mod h1:RdbpDgzqYVh/T9fPELJyV7EYJuHB55UTEULNun8eiPw=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic=
github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU=
github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow=
github.com/go-git/go-git/v5 v5.10.1 h1:tu8/D8i+TWxgKpzQ3Vc43e+kkhXqtsZCKI/egajKnxk=
github.com/go-git/go-git/v5 v5.10.1/go.mod h1:uEuHjxkHap8kAl//V5F/nNWwqIYtP/402ddd05mp0wg=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/gofrs/uuid v3.3.0+incompatible h1:8K4tyRfvU1CYPgJsveYFQMhpFd/wXNM7iK6rR7UHz84=
github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE=
github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
@ -162,14 +178,17 @@ github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-hclog v1.3.1 h1:vDwF1DFNZhntP4DAjuTpOw3uEgMUpXh1pB5fW9DqHpo=
github.com/hashicorp/go-hclog v1.3.1/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-plugin v1.4.8 h1:CHGwpxYDOttQOY7HOWgETU9dyVjOXzniXDqJcYJE1zM=
github.com/hashicorp/go-plugin v1.4.8/go.mod h1:viDMjcLJuDui6pXb8U4HVfb8AamCWhHGUjr2IrTF67s=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/hc-install v0.6.2 h1:V1k+Vraqz4olgZ9UzKiAcbman9i9scg9GgSt/U3mw/M=
@ -193,8 +212,11 @@ github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSo
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE=
github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
@ -206,10 +228,12 @@ github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/magodo/armid v0.0.0-20230511151020-27880e5961c3 h1:ob6vk6PlChZvutcxcLnmPH/VNmJEuwz+TmCYCVtJqeA=
github.com/magodo/armid v0.0.0-20230511151020-27880e5961c3/go.mod h1:rR8E7zfGMbmfnSQvrkFiWYdhrfTqsVSltelnZB09BwA=
github.com/magodo/azlist v0.0.0-20231101012443-e30f2da262c1 h1:9SXoK38cfRZac8LwA3BmEhVjuU/JGPb6I3MKvpHA4To=
github.com/magodo/azlist v0.0.0-20231101012443-e30f2da262c1/go.mod h1:xefFDOxzRssOEjGoxvrO8jeTWlzHXbY6sCJYOt+Jh5k=
github.com/magodo/azlist v0.0.0-20240613024003-b4529218cc6a h1:CFX3fvA3ajq81F7fkSBF+RgrZEgyuNP8x2QWt4Zhw5k=
github.com/magodo/azlist v0.0.0-20240613024003-b4529218cc6a/go.mod h1:xefFDOxzRssOEjGoxvrO8jeTWlzHXbY6sCJYOt+Jh5k=
github.com/magodo/aztft v0.3.1-0.20240429022627-002cdc06267a h1:HYp5h1HOwwrFI6CVSeJTVfnXyO7Es6Kx8cyw3UlomDo=
github.com/magodo/aztft v0.3.1-0.20240429022627-002cdc06267a/go.mod h1:hqk4M4qig7+LTNKeHCNgi+hZfJBndnx4oSNAvP5KT0Y=
github.com/magodo/slog2hclog v0.0.0-20240614031327-090ebd72a033 h1:K2seYsMAzoICCLdDe7uU2WyaACLW+tvdTWG3QB+pyec=
github.com/magodo/slog2hclog v0.0.0-20240614031327-090ebd72a033/go.mod h1:8PvdX1kpjMEmR7LTNZ0QulFpD9j3E/eJijru+4nHY7M=
github.com/magodo/spinner v0.0.0-20220720073946-50f31b2dc5a6 h1:CElHO4hPXC+Eivy8sUC/WrnH3jmQzdF2x0lEXBEYul8=
github.com/magodo/spinner v0.0.0-20220720073946-50f31b2dc5a6/go.mod h1:Cn4fFwFH/Ddw9sjWPeSS72bNaxbM+FRXf7pkGEDReq8=
github.com/magodo/terraform-client-go v0.0.0-20230323074119-02ceb732dd25 h1:V4R1wcjD/fYQh3Qx/xUyB8xTZgJ7P+WGtHqYpjs+mTU=
@ -262,6 +286,7 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pkg/profile v1.7.0 h1:hnbDkaNWPCLMO9wGLdBFTIZvzDrDfBM2072E1S9gJkA=
@ -276,7 +301,9 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI=
github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ=
github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@ -305,11 +332,13 @@ github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgq
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/zclconf/go-cty v1.14.1 h1:t9fyA35fwjjUMcmL5hLER+e/rEPqrbCK1/OSE4SI9KA=
github.com/zclconf/go-cty v1.14.1/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
@ -347,6 +376,7 @@ golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
@ -365,8 +395,10 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

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

@ -298,7 +298,7 @@ func (meta *baseMeta) ParallelImport(ctx context.Context, items []*ImportItem) e
// Ensure the state file is removed after this round import, preparing for the next round.
defer os.Remove(stateFile)
log.Printf("[DEBUG] Merging terraform state file %s (tfmerge)", stateFile)
log.Debug("Merging terraform state file (tfmerge)", "file", stateFile)
newState, err := tfmerge.Merge(ctx, meta.tf, meta.baseState, stateFile)
if err != nil {
return fmt.Errorf("failed to merge state file: %v", err)
@ -667,12 +667,12 @@ func (meta *baseMeta) initImportDirs() error {
}
func (meta *baseMeta) initTF(ctx context.Context) error {
log.Printf("[INFO] Init Terraform")
log.Info("Init Terraform")
execPath, err := FindTerraform(ctx)
if err != nil {
return fmt.Errorf("error finding a terraform exectuable: %w", err)
}
log.Printf("[INFO] Find terraform binary at %s", execPath)
log.Info("Found terraform binary", "path", execPath)
newTF := func(dir string) (*tfexec.Terraform, error) {
tf, err := tfexec.NewTerraform(dir, execPath)
@ -708,7 +708,7 @@ func (meta *baseMeta) initTF(ctx context.Context) error {
}
func (meta *baseMeta) initProvider(ctx context.Context) error {
log.Printf("[INFO] Init provider")
log.Info("Init provider")
module, diags := tfconfig.LoadModule(meta.outdir)
if diags.HasErrors() {
@ -721,7 +721,7 @@ func (meta *baseMeta) initProvider(ctx context.Context) error {
}
if module.ProviderConfigs[meta.providerName] == nil {
log.Printf("[INFO] Output directory doesn't contain provider setting, create one then")
log.Info("Output directory doesn't contain provider setting, create one then")
cfgFile := filepath.Join(meta.outdir, meta.outputFileNames.ProviderFileName)
// #nosec G306
if err := os.WriteFile(cfgFile, []byte(meta.buildProviderConfig()), 0644); err != nil {
@ -730,7 +730,7 @@ func (meta *baseMeta) initProvider(ctx context.Context) error {
}
if tfblock == nil {
log.Printf("[INFO] Output directory doesn't contain terraform block, create one then")
log.Info("Output directory doesn't contain terraform block, create one then")
cfgFile := filepath.Join(meta.outdir, meta.outputFileNames.TerraformFileName)
// #nosec G306
if err := os.WriteFile(cfgFile, []byte(meta.buildTerraformConfig(meta.backendType)), 0644); err != nil {
@ -744,7 +744,7 @@ func (meta *baseMeta) initProvider(ctx context.Context) error {
opts = append(opts, tfexec.BackendConfig(opt))
}
log.Printf(`[DEBUG] Run "terraform init" for the output directory %s`, meta.outdir)
log.Debug(`Run "terraform init" for the output directory`, "dir", meta.outdir)
if err := meta.tf.Init(ctx, opts...); err != nil {
return fmt.Errorf("error running terraform init for the output directory: %s", err)
}
@ -766,9 +766,9 @@ func (meta *baseMeta) initProvider(ctx context.Context) error {
return nil, fmt.Errorf("error creating terraform config: %w", err)
}
if meta.devProvider {
log.Printf(`[DEBUG] Skip running "terraform init" for the import directory (dev provider): %s`, meta.importBaseDirs[i])
log.Debug(`Skip running "terraform init" for the import directory (dev provider)`, "dir", meta.importBaseDirs[i])
} else {
log.Printf(`[DEBUG] Run "terraform init" for the import directory %s`, meta.importBaseDirs[i])
log.Debug(`Run "terraform init" for the import directory`, "dir", meta.importBaseDirs[i])
if err := meta.importTFs[i].Init(ctx); err != nil {
return nil, fmt.Errorf("error running terraform init: %s", err)
}
@ -785,7 +785,7 @@ func (meta *baseMeta) initProvider(ctx context.Context) error {
func (meta *baseMeta) importItem(ctx context.Context, item *ImportItem, importIdx int) {
if item.Skip() {
log.Printf("[INFO] Skipping %s", item.TFResourceId)
log.Info("Skipping resource", "tf_id", item.TFResourceId)
return
}
@ -807,7 +807,7 @@ func (meta *baseMeta) importItem_tf(ctx context.Context, item *ImportItem, impor
// #nosec G306
if err := os.WriteFile(cfgFile, []byte(tpl), 0644); err != nil {
err := fmt.Errorf("generating resource template file for %s: %w", item.TFAddr, err)
log.Printf("[ERROR] %v", err)
log.Error("Failed to generate resource template file", "error", err, "tf_addr", item.TFAddr)
item.ImportError = err
return
}
@ -819,13 +819,13 @@ func (meta *baseMeta) importItem_tf(ctx context.Context, item *ImportItem, impor
addr = meta.moduleAddr + "." + addr
}
log.Printf("[INFO] Importing %s as %s", item.TFResourceId, addr)
log.Info("Importing a resource", "tf_id", item.TFResourceId, "tf_addr", addr)
// The actual resource type names in telemetry is redacted
meta.tc.Trace(telemetry.Info, fmt.Sprintf("Importing %s as %s", item.AzureResourceID.TypeString(), addr))
err := tf.Import(ctx, addr, item.TFResourceId)
if err != nil {
log.Printf("[ERROR] Importing %s: %v", item.TFAddr, err)
log.Error("Terraform import failed", "tf_addr", item.TFAddr, "error", err)
meta.tc.Trace(telemetry.Error, fmt.Sprintf("Importing %s failed", item.AzureResourceID.TypeString()))
meta.tc.Trace(telemetry.Error, fmt.Sprintf("Error detail: %v", err))
} else {
@ -838,7 +838,7 @@ func (meta *baseMeta) importItem_tf(ctx context.Context, item *ImportItem, impor
func (meta *baseMeta) importItem_notf(ctx context.Context, item *ImportItem, importIdx int) {
// Import resources
addr := item.TFAddr.String()
log.Printf("[INFO] Importing %s as %s", item.TFResourceId, addr)
log.Info("Importing a resource", "tf_id", item.TFResourceId, "tf_addr", addr)
// The actual resource type names in telemetry is redacted
meta.tc.Trace(telemetry.Info, fmt.Sprintf("Importing %s as %s", item.AzureResourceID.TypeString(), addr))
@ -847,7 +847,7 @@ func (meta *baseMeta) importItem_notf(ctx context.Context, item *ImportItem, imp
ID: item.TFResourceId,
})
if diags.HasErrors() {
log.Printf("[ERROR] Importing %s: %v", item.TFAddr, diags)
log.Error("Terraform import failed", "tf_addr", item.TFAddr, "error", diags.Err())
meta.tc.Trace(telemetry.Error, fmt.Sprintf("Importing %s failed", item.AzureResourceID.TypeString()))
meta.tc.Trace(telemetry.Error, fmt.Sprintf("Error detail: %v", diags.Err()))
item.ImportError = diags.Err()
@ -856,7 +856,7 @@ func (meta *baseMeta) importItem_notf(ctx context.Context, item *ImportItem, imp
}
if len(importResp.ImportedResources) != 1 {
err := fmt.Errorf("expect 1 resource being imported, got=%d", len(importResp.ImportedResources))
log.Printf("[ERROR] %s", err)
log.Error(err.Error())
meta.tc.Trace(telemetry.Error, err.Error())
item.ImportError = err
item.Imported = false
@ -869,7 +869,7 @@ func (meta *baseMeta) importItem_notf(ctx context.Context, item *ImportItem, imp
Private: res.Private,
})
if diags.HasErrors() {
log.Printf("[ERROR] Reading %s: %v", item.TFAddr, diags)
log.Error("Terraform read a resource failed", "tf_addr", item.TFAddr, "error", diags.Err())
meta.tc.Trace(telemetry.Error, fmt.Sprintf("Reading %s failed", item.AzureResourceID.TypeString()))
meta.tc.Trace(telemetry.Error, fmt.Sprintf("Error detail: %v", diags.Err()))
item.ImportError = diags.Err()

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

@ -21,7 +21,7 @@ type MetaMap struct {
}
func NewMetaMap(cfg config.Config) (*MetaMap, error) {
log.Printf("[INFO] New map meta")
log.Info("New map meta")
baseMeta, err := NewBaseMeta(cfg.CommonConfig)
if err != nil {
return nil, err
@ -42,7 +42,7 @@ func (meta MetaMap) ScopeName() string {
func (meta *MetaMap) ListResource(_ context.Context) (ImportList, error) {
var m resmap.ResourceMapping
log.Printf("[DEBUG] Read resource set from mapping file")
log.Debug("Read resource set from mapping file")
b, err := os.ReadFile(meta.mappingFile)
if err != nil {
return nil, fmt.Errorf("reading mapping file %s: %v", meta.mappingFile, err)

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

@ -22,7 +22,7 @@ type MetaQuery struct {
}
func NewMetaQuery(cfg config.Config) (*MetaQuery, error) {
log.Printf("[INFO] New query meta")
log.Info("New query meta")
baseMeta, err := NewBaseMeta(cfg.CommonConfig)
if err != nil {
return nil, err
@ -49,26 +49,26 @@ func (meta MetaQuery) ScopeName() string {
}
func (meta *MetaQuery) ListResource(ctx context.Context) (ImportList, error) {
log.Printf("[DEBUG] Query resource set")
log.Debug("Query resource set")
rset, err := meta.queryResourceSet(ctx, meta.argPredicate, meta.recursiveQuery)
if err != nil {
return nil, err
}
var rl []resourceset.TFResource
if meta.useAzAPI() {
log.Printf("[DEBUG] Azure Resource set map to TF resource set")
log.Debug("Azure Resource set map to TF resource set")
rl = rset.ToTFAzAPIResources()
} else {
log.Printf("[DEBUG] Populate resource set")
log.Debug("Populate resource set")
if err := rset.PopulateResource(); err != nil {
return nil, fmt.Errorf("tweaking single resources in the azure resource set: %v", err)
}
log.Printf("[DEBUG] Reduce resource set")
log.Debug("Reduce resource set")
if err := rset.ReduceResource(); err != nil {
return nil, fmt.Errorf("tweaking across resources in the azure resource set: %v", err)
}
log.Printf("[DEBUG] Azure Resource set map to TF resource set")
log.Debug("Azure Resource set map to TF resource set")
rl = rset.ToTFAzureRMResources(meta.parallelism, meta.azureSDKCred, meta.azureSDKClientOpt)
}

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

@ -20,7 +20,7 @@ type MetaResource struct {
}
func NewMetaResource(cfg config.Config) (*MetaResource, error) {
log.Printf("[INFO] New resource meta")
log.Info("New resource meta")
baseMeta, err := NewBaseMeta(cfg.CommonConfig)
if err != nil {
return nil, err
@ -51,7 +51,7 @@ func (meta *MetaResource) ListResource(_ context.Context) (ImportList, error) {
},
},
}
log.Printf("[DEBUG] Azure Resource set map to TF resource set")
log.Debug("Azure Resource set map to TF resource set")
var rl []resourceset.TFResource
if meta.useAzAPI() {

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

@ -21,7 +21,7 @@ type MetaResourceGroup struct {
}
func NewMetaResourceGroup(cfg config.Config) (*MetaResourceGroup, error) {
log.Printf("[INFO] New resource group meta")
log.Info("New resource group meta")
baseMeta, err := NewBaseMeta(cfg.CommonConfig)
if err != nil {
return nil, err
@ -42,7 +42,7 @@ func (meta MetaResourceGroup) ScopeName() string {
}
func (meta *MetaResourceGroup) ListResource(ctx context.Context) (ImportList, error) {
log.Printf("[DEBUG] Query resource set")
log.Debug("Query resource set")
rset, err := meta.queryResourceSet(ctx, meta.resourceGroup)
if err != nil {
return nil, err
@ -52,17 +52,16 @@ func (meta *MetaResourceGroup) ListResource(ctx context.Context) (ImportList, er
if meta.useAzAPI() {
rl = rset.ToTFAzAPIResources()
} else {
log.Printf("[DEBUG] Populate resource set")
log.Debug("Populate resource set")
if err := rset.PopulateResource(); err != nil {
return nil, fmt.Errorf("tweaking single resources in the azure resource set: %v", err)
}
log.Printf("[DEBUG] Reduce resource set")
log.Debug("Reduce resource set")
if err := rset.ReduceResource(); err != nil {
return nil, fmt.Errorf("tweaking across resources in the azure resource set: %v", err)
}
log.Printf("[DEBUG] Azure Resource set map to TF resource set")
log.Debug("Azure Resource set map to TF resource set")
rl = rset.ToTFAzureRMResources(meta.parallelism, meta.azureSDKCred, meta.azureSDKClientOpt)
}

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

@ -42,7 +42,7 @@ func (rset AzureResourceSet) ToTFAzureRMResources(parallelism int, cred azcore.T
wp.Run(func(v interface{}) error {
res := v.(result)
if res.err != nil {
log.Printf("[WARN] Failed to query resource type for %s: %v\n", res.resid, res.err)
log.Warn("Failed to query resource type", "id", res.resid, "error", res.err)
// Still put this unresolved resource in the resource set, so that users can later specify the expected TF resource type.
tfresources = append(tfresources, TFResource{
AzureId: res.resid,
@ -52,7 +52,7 @@ func (rset AzureResourceSet) ToTFAzureRMResources(parallelism int, cred azcore.T
} else {
if !res.exact {
// It is not possible to return multiple result when API is used.
log.Printf("[WARN] No query result for resource type and TF id for %s\n", res.resid)
log.Warn("No query result for resource type and TF id", "id", res.resid)
// Still put this unresolved resource in the resource set, so that users can later specify the expected TF resource type.
tfresources = append(tfresources, TFResource{
AzureId: res.resid,

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

@ -118,7 +118,7 @@ func (m model) Init() tea.Cmd {
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if _, ok := msg.(spinner.TickMsg); !ok {
log.Printf("[DEBUG] UI update. STATUS: %s | MSG: %#v\n", m.status, msg)
log.Trace("UI update", "status", m.status, "msg", fmt.Sprintf("%#v", msg))
}
switch msg := msg.(type) {

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

@ -5,8 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
golog "log"
"log/slog"
"os"
"os/exec"
"path/filepath"
@ -23,9 +22,10 @@ import (
"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/slog2hclog"
"github.com/magodo/terraform-client-go/tfclient"
"github.com/magodo/tfadd/providers/azapi"
"github.com/magodo/tfadd/providers/azurerm"
@ -70,12 +70,12 @@ func prepareConfigFile(ctx *cli.Context) error {
if id, err := cfgfile.GetInstallationIdFromCLI(); err == nil {
return id, nil
}
log.Printf("[DEBUG] Installation ID not found from Azure CLI: %v", err)
log.Debug("Installation ID not found from Azure CLI", "error", err)
if id, err := cfgfile.GetInstallationIdFromPWSH(); err == nil {
return id, nil
}
log.Printf("[DEBUG] Installation ID not found from Azure PWSH: %v", err)
log.Debug("Installation ID not found from Azure PWSH", "error", err)
uuid, err := uuid.NewV4()
if err != nil {
@ -472,7 +472,7 @@ func main() {
TFResourceType: flagset.flagResType,
}
return realMain(c.Context, cfg, flagset.flagNonInteractive, flagset.hflagMockClient, flagset.flagPlainUI, flagset.flagGenerateMappingFile, flagset.hflagProfile, flagset.DescribeCLI(ModeResource))
return realMain(c.Context, cfg, flagset.flagNonInteractive, flagset.hflagMockClient, flagset.flagPlainUI, flagset.flagGenerateMappingFile, flagset.hflagProfile, flagset.DescribeCLI(ModeResource), flagset.hflagTFClientPluginPath)
},
},
{
@ -506,7 +506,7 @@ func main() {
IncludeRoleAssignment: flagset.flagIncludeRoleAssignment,
}
return realMain(c.Context, cfg, flagset.flagNonInteractive, flagset.hflagMockClient, flagset.flagPlainUI, flagset.flagGenerateMappingFile, flagset.hflagProfile, flagset.DescribeCLI(ModeResourceGroup))
return realMain(c.Context, cfg, flagset.flagNonInteractive, flagset.hflagMockClient, flagset.flagPlainUI, flagset.flagGenerateMappingFile, flagset.hflagProfile, flagset.DescribeCLI(ModeResourceGroup), flagset.hflagTFClientPluginPath)
},
},
{
@ -540,7 +540,7 @@ func main() {
IncludeResourceGroup: flagset.flagIncludeResourceGroup,
}
return realMain(c.Context, cfg, flagset.flagNonInteractive, flagset.hflagMockClient, flagset.flagPlainUI, flagset.flagGenerateMappingFile, flagset.hflagProfile, flagset.DescribeCLI(ModeQuery))
return realMain(c.Context, cfg, flagset.flagNonInteractive, flagset.hflagMockClient, flagset.flagPlainUI, flagset.flagGenerateMappingFile, flagset.hflagProfile, flagset.DescribeCLI(ModeQuery), flagset.hflagTFClientPluginPath)
},
},
{
@ -571,7 +571,7 @@ func main() {
MappingFile: mapFile,
}
return realMain(c.Context, cfg, flagset.flagNonInteractive, flagset.hflagMockClient, flagset.flagPlainUI, flagset.flagGenerateMappingFile, flagset.hflagProfile, flagset.DescribeCLI(ModeMappingFile))
return realMain(c.Context, cfg, flagset.flagNonInteractive, flagset.hflagMockClient, flagset.flagPlainUI, flagset.flagGenerateMappingFile, flagset.hflagProfile, flagset.DescribeCLI(ModeMappingFile), flagset.hflagTFClientPluginPath)
},
},
},
@ -585,45 +585,42 @@ func main() {
}
}
func logLevel(level string) (hclog.Level, error) {
switch level {
func logLevel(level string) (slog.Level, error) {
switch strings.ToUpper(level) {
case "ERROR":
return hclog.Error, nil
return slog.LevelError, nil
case "WARN":
return hclog.Warn, nil
return slog.LevelWarn, nil
case "INFO":
return hclog.Info, nil
return slog.LevelInfo, nil
case "DEBUG":
return hclog.Debug, nil
return slog.LevelDebug, nil
case "TRACE":
return hclog.Trace, nil
return log.LevelTrace, nil
default:
return hclog.NoLevel, fmt.Errorf("unknown log level: %s", level)
return slog.Level(0), fmt.Errorf("unknown log level: %s", level)
}
}
func initLog(path string, flagLevel string) error {
golog.SetOutput(io.Discard)
level, err := logLevel(flagLevel)
if err != nil {
return err
}
//golog.SetOutput(io.Discard)
// Logger is only enabled when the log path is specified.
// This is because either interactive/non-interactive mode controls the terminal rendering,
// logging to stdout/stderr will impact the rendering.
if path != "" {
level, err := logLevel(flagLevel)
if err != nil {
return err
}
// #nosec G304
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)
if err != nil {
return fmt.Errorf("creating log file %s: %v", path, err)
}
logger := hclog.New(&hclog.LoggerOptions{
Name: "aztfexport",
Level: level,
Output: f,
}).StandardLogger(&hclog.StandardLoggerOptions{
InferLevels: true,
})
logger := slog.New(slog.NewTextHandler(f, &slog.HandlerOptions{Level: level}))
// Enable log for aztfexport
log.SetLogger(logger)
@ -634,9 +631,10 @@ func initLog(path string, flagLevel string) error {
// Enable log for azure sdk
os.Setenv("AZURE_SDK_GO_LOGGING", "all") // #nosec G104
azlog.SetListener(func(cls azlog.Event, msg string) {
logger.Printf("[TRACE] %s: %s\n", cls, msg)
logger.Log(context.Background(), log.LevelTrace, msg, "event", cls)
})
}
return nil
}
@ -659,7 +657,7 @@ func subscriptionIdFromCLI() (string, error) {
return strconv.Unquote(strings.TrimSpace(stdout.String()))
}
func realMain(ctx context.Context, cfg config.Config, batch, mockMeta, plainUI, genMapFile bool, profileType string, effectiveCLI string) (result error) {
func realMain(ctx context.Context, cfg config.Config, batch, mockMeta, plainUI, genMapFile bool, profileType string, effectiveCLI string, tfClientPluginPath string) (result error) {
switch strings.ToLower(profileType) {
case "cpu":
defer profile.Start(profile.CPUProfile, profile.ProfilePath("."), profile.NoShutdownHook).Stop()
@ -673,21 +671,34 @@ func realMain(ctx context.Context, cfg config.Config, batch, mockMeta, plainUI,
return
}
// Initialize the TFClient
if tfClientPluginPath != "" {
// #nosec G204
tfc, err := tfclient.New(tfclient.Option{
Cmd: exec.Command(flagset.hflagTFClientPluginPath),
Logger: slog2hclog.New(log.GetLogger(), nil),
})
if err != nil {
return err
}
cfg.TFClient = tfc
}
tc := cfg.TelemetryClient
defer func() {
if result == nil {
log.Printf("[INFO] aztfexport ends")
log.Info("aztfexport ends")
tc.Trace(telemetry.Info, "aztfexport ends")
} else {
log.Printf("[ERROR] aztfexport ends with error: %v", result)
log.Error("aztfexport ends with error", "error", result)
tc.Trace(telemetry.Error, fmt.Sprintf("aztfexport ends with error"))
tc.Trace(telemetry.Error, fmt.Sprintf("Error detail: %v", result))
}
tc.Close()
}()
log.Printf("[INFO] aztfexport starts with config: %#v", cfg)
log.Info("aztfexport starts", "config", fmt.Sprintf("%#v", cfg))
tc.Trace(telemetry.Info, "aztfexport starts")
tc.Trace(telemetry.Info, "Effective CLI: "+effectiveCLI)

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

@ -1,19 +1,69 @@
package log
type Logger interface {
Printf(format string, v ...any)
import (
"context"
"io"
"log/slog"
"github.com/magodo/slog2hclog"
)
var logger = slog.New(slog.NewTextHandler(io.Discard, nil))
const LevelTrace = slog2hclog.SlogLevelTrace
func SetLogger(l *slog.Logger) {
logger = l
}
var log Logger = NullLogger{}
type NullLogger struct{}
func (NullLogger) Printf(format string, v ...any) {}
func SetLogger(l Logger) {
log = l
func GetLogger() *slog.Logger {
return logger
}
func Printf(format string, v ...any) {
log.Printf(format, v...)
func Trace(msg string, args ...any) {
logger.Log(context.Background(), LevelTrace, msg, args...)
}
func TraceContext(ctx context.Context, msg string, args ...any) {
logger.Log(ctx, LevelTrace, msg, args...)
}
func Debug(msg string, args ...any) {
logger.Debug(msg, args...)
}
func DebugContext(ctx context.Context, msg string, args ...any) {
logger.DebugContext(ctx, msg, args...)
}
func Info(msg string, args ...any) {
logger.Info(msg, args...)
}
func InfoContext(ctx context.Context, msg string, args ...any) {
logger.InfoContext(ctx, msg, args...)
}
func Warn(msg string, args ...any) {
logger.Warn(msg, args...)
}
func WarnContext(ctx context.Context, msg string, args ...any) {
logger.WarnContext(ctx, msg, args...)
}
func Error(msg string, args ...any) {
logger.Error(msg, args...)
}
func ErrorContext(ctx context.Context, msg string, args ...any) {
logger.ErrorContext(ctx, msg, args...)
}
func Log(ctx context.Context, level slog.Level, msg string, args ...any) {
logger.Log(ctx, level, msg, args...)
}
func LogAttrs(ctx context.Context, level slog.Level, msg string, attrs ...slog.Attr) {
logger.LogAttrs(ctx, level, msg, attrs...)
}