Skip to content
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
17 changes: 16 additions & 1 deletion nullplatform/cloud/azure/cloud/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ resource "nullplatform_provider_config" "azure" {
dimensions = var.dimensions

attributes = jsonencode({
authentication = {},
authentication = {
for k, v in {
client_id = var.client_id
client_secret = var.client_secret
subscription_id = var.subscription_id
tenant_id = var.tenant_id
} : k => v if v != null
},
networking = {
application_domain = var.application_domain,
domain_name = var.domain_name,
Expand All @@ -17,6 +24,14 @@ resource "nullplatform_provider_config" "azure" {
}
})
lifecycle {
precondition {
condition = (
(var.client_id == null) == (var.client_secret == null) &&
(var.client_id == null) == (var.subscription_id == null) &&
(var.client_id == null) == (var.tenant_id == null)
)
error_message = "Authentication credentials must all be set or all be null (client_id, client_secret, subscription_id, tenant_id)."
}
ignore_changes = [attributes]
}
}
48 changes: 48 additions & 0 deletions nullplatform/cloud/azure/cloud/tests/azure_cloud.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,54 @@ run "attributes_contain_resource_groups" {
}
}

run "with_authentication_credentials" {
command = plan

variables {
client_id = "11111111-0000-0000-0000-000000000001"
client_secret = "dummy-secret-for-testing-purposes-only!"
subscription_id = "22222222-0000-0000-0000-000000000002"
tenant_id = "33333333-0000-0000-0000-000000000003"
}

assert {
condition = strcontains(nullplatform_provider_config.azure.attributes, "11111111-0000-0000-0000-000000000001")
error_message = "Attributes should contain the client_id when provided"
}

assert {
condition = strcontains(nullplatform_provider_config.azure.attributes, "22222222-0000-0000-0000-000000000002")
error_message = "Attributes should contain the subscription_id when provided"
}

assert {
condition = strcontains(nullplatform_provider_config.azure.attributes, "33333333-0000-0000-0000-000000000003")
error_message = "Attributes should contain the tenant_id when provided"
}
}

run "without_authentication_credentials" {
command = plan

assert {
condition = strcontains(nullplatform_provider_config.azure.attributes, "\"authentication\":{}") || strcontains(nullplatform_provider_config.azure.attributes, "\"authentication\": {}")
error_message = "Authentication block should be empty when no credentials provided (inherits from parent)"
}
}

run "partial_authentication_fails" {
command = plan

variables {
client_id = "11111111-0000-0000-0000-000000000001"
# client_secret, subscription_id, tenant_id omitted intentionally
}

expect_failures = [
nullplatform_provider_config.azure,
]
}

run "with_domain_name" {
command = plan

Expand Down
25 changes: 25 additions & 0 deletions nullplatform/cloud/azure/cloud/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@ variable "nrn" {
description = "The NRN of your nullplatform account"
}

variable "client_id" {
type = string
description = "Azure Service Principal client ID. If omitted, inherits from a parent cloud provider."
default = null
}

variable "client_secret" {
type = string
description = "Azure Service Principal client secret. If omitted, inherits from a parent cloud provider."
sensitive = true
default = null
}

variable "subscription_id" {
type = string
description = "Azure subscription ID. If omitted, inherits from a parent cloud provider."
default = null
}

variable "tenant_id" {
type = string
description = "Azure Active Directory tenant ID. If omitted, inherits from a parent cloud provider."
default = null
}

variable "domain_name" {
description = "The domain name to be used"
type = string
Expand Down