Skip to content
This repository was archived by the owner on Aug 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

ENHANCEMENTS:
- `azapi` resources/data sources: Update embedded schema to the latest version.
- Support specifying the provider version used in the migration in the `terraform` block.


## v2.3.0
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Azure/azapi-lsp
go 1.23.0

require (
github.com/Azure/aztfmigrate v1.15.1-0.20250407062114-3a221613fd4c
github.com/Azure/aztfmigrate v1.15.1-0.20250408084920-0db194f765f0
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1
github.com/apparentlymart/go-textseg v1.0.0
github.com/creachadair/jrpc2 v0.32.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/Azure/aztfmigrate v1.15.1-0.20250407062114-3a221613fd4c h1:6OOBvqvbIpKrK+aNSjSQvddNgIciZ4GVIqibRD1OOHI=
github.com/Azure/aztfmigrate v1.15.1-0.20250407062114-3a221613fd4c/go.mod h1:P199MOJpYH3vD3BsO28KEjRDVeKuhCPwFXNkvOpjrWw=
github.com/Azure/aztfmigrate v1.15.1-0.20250408084920-0db194f765f0 h1:6Dzz58+EP8kCuwVZfpTKGF8NsLPIzZA1aIPYk2NNZTo=
github.com/Azure/aztfmigrate v1.15.1-0.20250408084920-0db194f765f0/go.mod h1:P199MOJpYH3vD3BsO28KEjRDVeKuhCPwFXNkvOpjrWw=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1 h1:DSDNVxqkoXJiko6x8a90zidoYqnYYa6c1MTzDKzKkTo=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.1/go.mod h1:zGqV2R4Cr/k8Uye5w+dgQ06WJtEcbQG/8J7BB6hnCr4=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.2 h1:F0gBpfdPLGsw+nsgk6aqqkZS1jiixa5WwFe3fk/T3Ys=
Expand Down
53 changes: 4 additions & 49 deletions internal/langserver/handlers/command/aztfmigrate_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
lsp "github.com/Azure/azapi-lsp/internal/protocol"
"github.com/Azure/azapi-lsp/internal/utils"
"github.com/Azure/aztfmigrate/azurerm"
"github.com/Azure/aztfmigrate/cmd"
"github.com/Azure/aztfmigrate/helper"
"github.com/Azure/aztfmigrate/tf"
"github.com/Azure/aztfmigrate/types"
"github.com/hashicorp/hcl/v2"
Expand Down Expand Up @@ -236,7 +238,7 @@ func (c AztfMigrateCommand) Handle(ctx context.Context, arguments []json.RawMess
return nil, err
}

if err = os.WriteFile(filepath.Join(tempDir, importFileName), []byte(importConfig(resources)), 0600); err != nil {
if err = os.WriteFile(filepath.Join(tempDir, importFileName), []byte(cmd.ImportConfig(resources, helper.FindHclBlock(workingDirectory, "terraform", nil))), 0600); err != nil {
return nil, err
}

Expand All @@ -247,7 +249,7 @@ func (c AztfMigrateCommand) Handle(ctx context.Context, arguments []json.RawMess
log.Printf("[ERROR] %+v", err)
_ = clientNotifier.Notify(ctx, "window/showMessage", lsp.ShowMessageParams{
Type: lsp.Error,
Message: "Failed to generate new config for " + r.OldAddress(nil),
Message: fmt.Sprintf("Failed to generate new config for %s: %v", r.OldAddress(nil), err),
})
}
}
Expand Down Expand Up @@ -345,53 +347,6 @@ func (c AztfMigrateCommand) Handle(ctx context.Context, arguments []json.RawMess
return nil, nil
}

func importConfig(resources []types.AzureResource) string {
const providerConfig = `
terraform {
required_providers {
azapi = {
source = "Azure/azapi"
}
}
}

provider "azurerm" {
features {}
subscription_id = "%s"
}

provider "azapi" {
}
`

config := ""
for _, r := range resources {
config += r.EmptyImportConfig()
}
subscriptionId := ""
for _, r := range resources {
switch resource := r.(type) {
case *types.AzapiResource:
for _, instance := range resource.Instances {
if strings.HasPrefix(instance.ResourceId, "/subscriptions/") {
subscriptionId = strings.Split(instance.ResourceId, "/")[2]
break
}
}
case *types.AzapiUpdateResource:
if strings.HasPrefix(resource.Id, "/subscriptions/") {
subscriptionId = strings.Split(resource.Id, "/")[2]
}
}
if subscriptionId != "" {
break
}
}
config = fmt.Sprintf(providerConfig, subscriptionId) + config

return config
}

func reportProgress(ctx context.Context, message string, percentage uint32) {
clientCaller, err := context2.ClientCaller(ctx)
if err != nil {
Expand Down
29 changes: 29 additions & 0 deletions vendor/github.com/Azure/aztfmigrate/cmd/commands.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

242 changes: 242 additions & 0 deletions vendor/github.com/Azure/aztfmigrate/cmd/migrate_command.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading