Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Resource: generating Kubernetes Fleet Member #3416

Merged
merged 10 commits into from
Feb 6, 2024
17 changes: 17 additions & 0 deletions config/resources/containerservice.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,21 @@ HERE
}
}
}

api "2023-10-15" {
package "FleetMembers" {
definition "kubernetes_fleet_member" {
id = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/fleets/{fleetName}/members/{memberName}"
display_name = "Kubernetes Fleet Member"
website_subcategory = "Container"
description = "Manages a Kubernetes Fleet Member"
overrides "cluster_resource_id" {
updated_name = "kubernetes_cluster_id"
}
overrides "fleet_id" {
updated_name = "kubernetes_fleet_id"
}
}
Copy link
Member

@stephybun stephybun Jan 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will rename the property cluster_resource_id to kubernetes_cluster_id which will allow us to use the existing test dependency defined for the tests.

Suggested change
}
overrides "cluster_resource_id" {
updated_name = "kubernetes_cluster_id"
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package resourceids

import (
"github.com/hashicorp/pandora/tools/importer-rest-api-specs/models"
"github.com/hashicorp/pandora/tools/sdk/resourcemanager"
)

var _ commonIdMatcher = commonIdKubernetesFleet{}

type commonIdKubernetesFleet struct{}

func (c commonIdKubernetesFleet) id() models.ParsedResourceId {
name := "KubernetesFleet"
return models.ParsedResourceId{
CommonAlias: &name,
Constants: map[string]resourcemanager.ConstantDetails{},
Segments: []resourcemanager.ResourceIdSegment{
models.StaticResourceIDSegment("subscriptions", "subscriptions"),
models.SubscriptionIDResourceIDSegment("subscriptionId"),
models.StaticResourceIDSegment("resourceGroups", "resourceGroups"),
models.ResourceGroupResourceIDSegment("resourceGroupName"),
models.StaticResourceIDSegment("providers", "providers"),
models.ResourceProviderResourceIDSegment("resourceProvider", "Microsoft.ContainerService"),
models.StaticResourceIDSegment("fleets", "fleets"),
models.UserSpecifiedResourceIDSegment("fleetName"),
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type testDependencies struct {
needsKeyVaultAccessPolicy bool
needsKeyVaultKey bool
needsKubernetesCluster bool
needsKubernetesFleetManager bool
needsMachineLearningWorkspace bool
needsNetworkInterface bool
needsPublicIP bool
Expand Down Expand Up @@ -88,6 +89,13 @@ func (d *testDependencies) setNeedsKubernetesCluster() {
d.variables.needsRandomString = true
}

func (d *testDependencies) setNeedsKubernetesFleetManager() {
d.setNeedsResourceGroup()
d.needsKubernetesFleetManager = true

d.variables.needsRandomString = true
}

func (d *testDependencies) setNeedsMachineLearningWorkspace() {
d.setNeedsResourceGroup()
d.setNeedsKeyVault()
Expand Down Expand Up @@ -164,6 +172,7 @@ func DetermineDependencies(field, providerPrefix string, dependencies *testDepen
"key_vault_access_policy_id": {dependencies.setNeedsKeyVaultAccessPolicy, fmt.Sprintf("%s_key_vault_access_policy.test.id", providerPrefix)},
"key_vault_key_id": {dependencies.setNeedsKeyVaultKey, fmt.Sprintf("%s_key_vault_key.test.id", providerPrefix)},
"kubernetes_cluster_id": {dependencies.setNeedsKubernetesCluster, fmt.Sprintf("%s_kubernetes_cluster.test.id", providerPrefix)},
"kubernetes_fleet_id": {dependencies.setNeedsKubernetesFleetManager, fmt.Sprintf("%s_kubernetes_fleet_manager.test.id", providerPrefix)},
"machine_learning_workspace_id": {dependencies.setNeedsMachineLearningWorkspace, fmt.Sprintf("%s_machine_learning_workspace.test.id", providerPrefix)},
"network_interface_id": {dependencies.setNeedsNetworkInterface, fmt.Sprintf("%s_network_interface.test.id", providerPrefix)},
"storage_account_id": {dependencies.setNeedsStorageAccount, fmt.Sprintf("%s_storage_account.test.id", providerPrefix)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ resource "%[1]s_kubernetes_cluster" "test" {
`, tb.providerPrefix))
}

if dependencies.needsKubernetesFleetManager {
components = append(components, fmt.Sprintf(`
resource "%[1]s_kubernetes_fleet_manager" "test" {
name = "acctestkfm${var.random_string}"
location = %[1]s_resource_group.test.location
resource_group_name = %[1]s_resource_group.test.name
hub_profile {
dns_prefix = "val-${var.random_string}"
}
}
`, tb.providerPrefix))
}

if dependencies.needsMachineLearningWorkspace {
components = append(components, fmt.Sprintf(`
resource "%[1]s_machine_learning_workspace" "test" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,23 @@ resource "example_virtual_network" "test" {
actual := builder.generateTemplateConfigForDependencies(dependencies)
testhelpers.AssertTemplatedCodeMatches(t, expected, actual)
}

func TestDependenciesTemplate_NeedsKubernetesFleetManager(t *testing.T) {
builder := NewTestBuilder("example", "resource", resourcemanager.TerraformResourceDetails{})
dependencies := testDependencies{
variables: testVariables{},
needsKubernetesFleetManager: true,
}
expected := `
resource "example_kubernetes_fleet_manager" "test" {
name = "acctestkfm${var.random_string}"
location = example_resource_group.test.location
resource_group_name = example_resource_group.test.name
hub_profile {
dns_prefix = "val-${var.random_string}"
}
}
`
actual := builder.generateTemplateConfigForDependencies(dependencies)
testhelpers.AssertTemplatedCodeMatches(t, expected, actual)
}
Loading