Skip to content

Commit

Permalink
azurerm_log_analytics_cluster - support UserAssigned and
Browse files Browse the repository at this point in the history
`SystemAssigned, UserAssigned` identity
  • Loading branch information
ziyeqf committed May 13, 2024
1 parent cee11b3 commit fd50552
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (l LogAnalyticsClusterResource) Arguments() map[string]*schema.Schema {

"location": commonschema.Location(),

"identity": commonschema.SystemAssignedIdentityRequiredForceNew(),
"identity": commonschema.SystemAssignedUserAssignedIdentityRequiredForceNew(),

"size_gb": {
Type: pluginsdk.TypeInt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,46 @@ func TestAccLogAnalyticsCluster_basic(t *testing.T) {
})
}

func TestAccLogAnalyticsCluster_userAssignedIdentity(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_log_analytics_cluster", "test")
r := LogAnalyticsClusterResource{}

if os.Getenv("ARM_RUN_TEST_LOG_ANALYTICS_CLUSTERS") == "" {
t.Skip("Skipping as ARM_RUN_TEST_LOG_ANALYTICS_CLUSTERS is not specified")
return
}

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

func TestAccLogAnalyticsCluster_systemAssignedUserAssignedIdentity(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_log_analytics_cluster", "test")
r := LogAnalyticsClusterResource{}

if os.Getenv("ARM_RUN_TEST_LOG_ANALYTICS_CLUSTERS") == "" {
t.Skip("Skipping as ARM_RUN_TEST_LOG_ANALYTICS_CLUSTERS is not specified")
return
}

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

func TestAccLogAnalyticsCluster_resize(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_log_analytics_cluster", "test")
r := LogAnalyticsClusterResource{}
Expand Down Expand Up @@ -161,3 +201,53 @@ resource "azurerm_log_analytics_cluster" "import" {
}
`, r.basic(data))
}

func (r LogAnalyticsClusterResource) userAssignedIdentity(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_user_assigned_identity" "test" {
name = "acctestuai-%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
}
resource "azurerm_log_analytics_cluster" "test" {
name = "acctest-LA-%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
identity {
type = "UserAssigned"
identity_ids = [
azurerm_user_assigned_identity.test.id,
]
}
}
`, r.template(data), data.RandomInteger)
}

func (r LogAnalyticsClusterResource) systemAssigendUserAssignedIdentity(data acceptance.TestData) string {

Check failure on line 230 in internal/services/loganalytics/log_analytics_cluster_resource_test.go

View workflow job for this annotation

GitHub Actions / golint

func `LogAnalyticsClusterResource.systemAssigendUserAssignedIdentity` is unused (unused)
return fmt.Sprintf(`
%s
resource "azurerm_user_assigned_identity" "test" {
name = "acctestuai-%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
}
resource "azurerm_log_analytics_cluster" "test" {
name = "acctest-LA-%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
identity {
type = "SystemAssigned, UserAssigned"
identity_ids = [
azurerm_user_assigned_identity.test.id,
]
}
}
`, r.template(data), data.RandomInteger)
}
8 changes: 6 additions & 2 deletions website/docs/r/log_analytics_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ The following arguments are supported:

An `identity` block supports the following:

* `type` - (Required) Specifies the type of Managed Service Identity that should be configured on this Log Analytics Cluster. The only possible value is `SystemAssigned`. Changing this forces a new resource to be created.
* `type` - (Required) Specifies the type of Managed Service Identity that should be configured on this Log Analytics Cluster. Possible values are `SystemAssigned`, `UserAssigned` and `SystemAssigned, UserAssigned` (to enable both). Changing this forces a new resource to be created.

~> **NOTE:** The assigned `principal_id` and `tenant_id` can be retrieved after the identity `type` has been set to `SystemAssigned` and the Log Analytics Cluster has been created. More details are available below.

* `identity_ids` - (Optional) A list of User Assigned Managed Identity IDs to be assigned to this Windows Web App Slot.

~> **NOTE:** This is required when `type` is set to `UserAssigned` or `SystemAssigned, UserAssigned`.

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:
Expand All @@ -79,7 +83,7 @@ An `identity` block exports the following:

* `tenant_id` - The Tenant ID associated with this Managed Service Identity.

* `type` - (Required) The identity type of this Managed Service Identity.
* `type` - The identity type of this Managed Service Identity.

-> You can access the Principal ID via `azurerm_log_analytics_cluster.example.identity[0].principal_id` and the Tenant ID via `azurerm_log_analytics_cluster.example.identity[0].tenant_id`

Expand Down

0 comments on commit fd50552

Please sign in to comment.