Skip to content

Commit

Permalink
Normalize resource id for signalr service (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
magodo authored Jun 21, 2022
1 parent 37a492a commit 1b0effe
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/armtemplate/armtemplate_hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ func populateManagedResourcesByPath(res Resource, paths ...string) (*Resource, [
// API interaction with ARM, where a non-nil client builder is required.
func (res ResourceId) ProviderId(sub, rg string, b *client.ClientBuilder) (string, error) {
switch res.Type {
case "Microsoft.SignalRService/SignalR":
return res.providerIdForSignalR(sub, rg, b)
case "microsoft.insights/webtests":
return res.providerIdForInsightsWebtests(sub, rg, b)
case "Microsoft.Network/frontdoors":
Expand All @@ -142,6 +144,12 @@ func (res ResourceId) ProviderId(sub, rg string, b *client.ClientBuilder) (strin
}
}

func (res ResourceId) providerIdForSignalR(sub, rg string, b *client.ClientBuilder) (string, error) {
// See issue: https://github.com/Azure/aztfy/issues/154
res.Type = "Microsoft.SignalRService/signalR"
return res.ID(sub, rg), nil
}

func (res ResourceId) providerIdForFrontDoor(sub, rg string, b *client.ClientBuilder) (string, error) {
// See issue: https://github.com/Azure/aztfy/issues/118
res.Type = "Microsoft.Network/frontDoors"
Expand Down
44 changes: 44 additions & 0 deletions internal/test/case_signalr_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package test

import (
"encoding/json"
"fmt"

"github.com/Azure/aztfy/internal/resmap"
)

type CaseSignalRService struct{}

func (CaseSignalRService) Tpl(d Data) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "%[1]s"
location = "WestEurope"
}
resource "azurerm_signalr_service" "test" {
name = "test-%[2]s"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku {
name = "Free_F1"
capacity = 1
}
}
`, d.RandomRgName(), d.RandomStringOfLength(8))
}

func (CaseSignalRService) ResourceMapping(d Data) (resmap.ResourceMapping, error) {
rm := fmt.Sprintf(`{
"/subscriptions/%[1]s/resourceGroups/%[2]s": "azurerm_resource_group.test",
"/subscriptions/%[1]s/resourceGroups/%[2]s/providers/Microsoft.SignalRService/signalR/test-%[3]s": "azurerm_signalr_service.test"
}
`, d.subscriptionId, d.RandomRgName(), d.RandomStringOfLength(8))
m := resmap.ResourceMapping{}
if err := json.Unmarshal([]byte(rm), &m); err != nil {
return nil, err
}
return m, nil
}
7 changes: 7 additions & 0 deletions internal/test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ func TestComputeVMDisk(t *testing.T) {
runCase(t, d, c)
}

func TestSignalRService(t *testing.T) {
t.Parallel()
precheck(t)
c, d := CaseSignalRService{}, NewData()
runCase(t, d, c)
}

func TestApplicationInsightWebTest(t *testing.T) {
t.Parallel()
precheck(t)
Expand Down

0 comments on commit 1b0effe

Please sign in to comment.