Skip to content

Commit

Permalink
update doc examples to use the values in tests by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-henglu committed Mar 11, 2024
1 parent 67f110c commit 60f2524
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,85 @@ resource "azurerm_load_test" "example" {
}
testhelpers.AssertTemplatedCodeMatches(t, expected, *actual)
}

func TestResourceExampleFromTests_WithTemplate_FleetMember(t *testing.T) {
input := resourcemanager.TerraformResourceTestsDefinition{
BasicConfiguration: `
resource "azurerm_kubernetes_fleet_member" "test" {
kubernetes_cluster_id = azurerm_kubernetes_cluster.test.id
kubernetes_fleet_id = azurerm_kubernetes_fleet_manager.test.id
name = "acctestkfm-${var.random_string}"
}
`,
TemplateConfiguration: pointer.To(`
variable "primary_location" {}
variable "random_integer" {}
variable "random_string" {}
resource "azurerm_kubernetes_cluster" "test" {
name = "acctestaks${var.random_string}"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
dns_prefix = "acctestaks${var.random_string}"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
}
identity {
type = "SystemAssigned"
}
}
resource "azurerm_kubernetes_fleet_manager" "test" {
name = "acctestkfm${var.random_string}"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}
resource "azurerm_resource_group" "test" {
name = "acctestrg-${var.random_integer}"
location = var.primary_location
}
`),
}
expected := `
resource "azurerm_kubernetes_cluster" "example" {
name = "example"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
dns_prefix = "acctestaksexample"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_DS2_v2"
}
identity {
type = "SystemAssigned"
}
}
resource "azurerm_kubernetes_fleet_manager" "example" {
name = "example"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
resource "azurerm_kubernetes_fleet_member" "example" {
kubernetes_cluster_id = azurerm_kubernetes_cluster.example.id
kubernetes_fleet_id = azurerm_kubernetes_fleet_manager.example.id
name = "example"
}
`
actual, err := ResourceExampleFromTests(input)
if err != nil {
t.Fatalf(err.Error())
}
testhelpers.AssertTemplatedCodeMatches(t, expected, *actual)
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,5 @@ func updatedValueForAttribute(resourceKey, fieldKey string, value string) (*hclw
return &updatedValue, nil
}

out := hclwrite.TokensForValue(cty.StringVal("example-value"))
return &out, nil
return nil, nil
}

0 comments on commit 60f2524

Please sign in to comment.