Skip to content

Commit

Permalink
remove uai validation to support token audience as a valid input
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaxyi committed Jan 14, 2025
1 parent 42a5d7e commit cbd8032
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
10 changes: 3 additions & 7 deletions internal/services/signalr/web_pubsub_hub_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-sdk/resource-manager/webpubsub/2023-02-01/webpubsub"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
Expand Down Expand Up @@ -95,12 +94,9 @@ func resourceWebPubSubHub() *pluginsdk.Resource {
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"managed_identity_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.Any(
validation.IsUUID,
commonids.ValidateUserAssignedIdentityID,
),
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
Expand Down
54 changes: 53 additions & 1 deletion internal/services/signalr/web_pubsub_hub_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,21 @@ func TestAccWebPubsubHub_usingAuthGuid(t *testing.T) {
})
}

func TestAccWebPubsubHub_withAuthUpdate(t *testing.T) {
func TestAccWebPubsubHub_usingAuthTokenAudience(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_web_pubsub_hub", "test")
r := WebPubsubHubResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.usingAuthTokenAudience(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r)),
},
data.ImportStep(),
})
}

func TestAccWebPubsubHub_usingAuthUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_web_pubsub_hub", "test")
r := WebPubsubHubResource{}

Expand All @@ -95,6 +109,20 @@ func TestAccWebPubsubHub_withAuthUpdate(t *testing.T) {
),
},
data.ImportStep(),
{
Config: r.usingAuthTokenAudience(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.usingAuthGuid(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

Expand Down Expand Up @@ -246,6 +274,30 @@ resource "azurerm_web_pubsub_hub" "test" {
`, r.template(data), data.RandomInteger)
}

func (r WebPubsubHubResource) usingAuthTokenAudience(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_web_pubsub_hub" "test" {
name = "acctestwpsh%d"
web_pubsub_id = azurerm_web_pubsub.test.id
event_handler {
url_template = "https://test.com/api/{hub}/{event}"
user_event_pattern = "*"
system_events = ["connect", "connected"]
auth {
managed_identity_id = "api://AzureADTokenExchange"
}
}
anonymous_connections_enabled = true
depends_on = [
azurerm_web_pubsub.test
]
}
`, r.template(data), data.RandomInteger)
}

func (r WebPubsubHubResource) requiresImport(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down

0 comments on commit cbd8032

Please sign in to comment.