Skip to content

Commit 730c4db

Browse files
author
Furkhat Kasymov Genii Uulu
committed
aks_cluster support federation_id
1 parent db52a9a commit 730c4db

17 files changed

+103
-218
lines changed

castai/provider_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ func testAccPreCheck(t *testing.T) {
8888
})
8989
}
9090

91-
// ConfigCompose can be called to concatenate multiple strings to build test configurations
92-
func ConfigCompose(config ...string) string {
91+
// concatenateConfigs can be called to concatenate multiple strings to build test configurations
92+
func concatenateConfigs(config ...string) string {
9393
var str strings.Builder
9494
for _, conf := range config {
9595
str.WriteString(conf)

castai/resource_aks_cluster.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
FieldAKSClusterNodeResourceGroup = "node_resource_group"
2222
FieldAKSClusterClientID = "client_id"
2323
FieldAKSClusterClientSecret = "client_secret"
24+
FieldAKSClusterFederationID = "federation_id"
2425
FieldAKSClusterTenantID = "tenant_id"
2526
FieldAKSHttpProxyConfig = "http_proxy_config"
2627
FieldAKSHttpProxyDestination = "http_proxy"
@@ -84,10 +85,18 @@ func resourceAKSCluster() *schema.Resource {
8485
},
8586
FieldAKSClusterClientSecret: {
8687
Type: schema.TypeString,
87-
Required: true,
88+
Optional: true,
8889
Sensitive: true,
8990
ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsNotWhiteSpace),
9091
Description: "Azure AD application password that will be used by CAST AI.",
92+
ExactlyOneOf: []string{FieldAKSClusterClientSecret, FieldAKSClusterFederationID},
93+
},
94+
FieldAKSClusterFederationID: {
95+
Type: schema.TypeString,
96+
Optional: true,
97+
ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsNotWhiteSpace),
98+
Description: "Azure federation used by CAST AI for secretless auth via impersonation.",
99+
ExactlyOneOf: []string{FieldAKSClusterClientSecret, FieldAKSClusterFederationID},
91100
},
92101
FieldClusterToken: {
93102
Type: schema.TypeString,
@@ -256,13 +265,14 @@ func updateAKSClusterSettings(ctx context.Context, data *schema.ResourceData, cl
256265
if !data.HasChanges(
257266
FieldAKSClusterClientID,
258267
FieldAKSClusterClientSecret,
259-
FieldAKSClusterTenantID,
268+
FieldAKSClusterFederationID,
260269
FieldAKSClusterSubscriptionID,
261-
FieldClusterCredentialsId,
270+
FieldAKSClusterTenantID,
262271
FieldAKSHttpProxyConfig,
263272
FieldAKSHttpProxyDestination,
264273
FieldAKSHttpsProxyDestination,
265274
FieldAKSNoProxyDestinations,
275+
FieldClusterCredentialsId,
266276
) {
267277
log.Printf("[INFO] Nothing to update in cluster setttings.")
268278
return nil
@@ -275,9 +285,10 @@ func updateAKSClusterSettings(ctx context.Context, data *schema.ResourceData, cl
275285
clientID := data.Get(FieldAKSClusterClientID).(string)
276286
tenantID := data.Get(FieldAKSClusterTenantID).(string)
277287
clientSecret := data.Get(FieldAKSClusterClientSecret).(string)
288+
federationId := data.Get(FieldAKSClusterFederationID).(string)
278289
subscriptionID := data.Get(FieldAKSClusterSubscriptionID).(string)
279290

280-
credentials, err := sdk.ToCloudCredentialsAzure(clientID, clientSecret, tenantID, subscriptionID)
291+
credentials, err := sdk.ToCloudCredentialsAzure(clientID, clientSecret, federationId, tenantID, subscriptionID)
281292
if err != nil {
282293
return err
283294
}

castai/resource_aks_cluster_test.go

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io"
99
"net/http"
10+
"os"
1011
"testing"
1112

1213
"github.com/golang/mock/gomock"
@@ -414,7 +415,7 @@ func TestAKSClusterResourceUpdateContext(t *testing.T) {
414415
})
415416
}
416417

417-
func TestAccAKS_ResourceAKSCluster(t *testing.T) {
418+
func TestAccAKS_ResourceAKSCluster_SecretFlow(t *testing.T) {
418419
rName := fmt.Sprintf("%v-aks-%v", ResourcePrefix, acctest.RandString(8))
419420
resourceName := "castai_aks_cluster.test"
420421
clusterName := "core-tf-acc"
@@ -452,7 +453,7 @@ func TestAccAKS_ResourceAKSCluster(t *testing.T) {
452453
}
453454

454455
func testAccAKSClusterConfig(rName string, clusterName string, resourceGroupName, nodeResourceGroup string) string {
455-
return ConfigCompose(testAccAzureConfig(rName, resourceGroupName, nodeResourceGroup), fmt.Sprintf(`
456+
return concatenateConfigs(testAccAzureConfigUsingClientSecret(rName, resourceGroupName, nodeResourceGroup), fmt.Sprintf(`
456457
resource "castai_aks_cluster" "test" {
457458
name = %[1]q
458459
@@ -468,7 +469,52 @@ resource "castai_aks_cluster" "test" {
468469
`, clusterName, nodeResourceGroup))
469470
}
470471

471-
func testAccAzureConfig(rName, rgName, ngName string) string {
472+
func TestAccAKS_ResourceAKSCluster_ImpersonationFlow(t *testing.T) {
473+
const resourceName = "castai_aks_cluster.test"
474+
const clusterName = "terraform-tests-december-2025"
475+
resource.Test(t, resource.TestCase{
476+
PreCheck: func() { testAccPreCheck(t) },
477+
ProviderFactories: providerFactories,
478+
Steps: []resource.TestStep{
479+
{
480+
Config: testAccAzureClusterWithFederationID(clusterName),
481+
Check: resource.ComposeTestCheckFunc(
482+
resource.TestCheckResourceAttr(resourceName, "name", clusterName),
483+
resource.TestCheckResourceAttrSet(resourceName, "credentials_id"),
484+
resource.TestCheckResourceAttr(resourceName, "region", "westeurope"),
485+
resource.TestCheckResourceAttrSet(resourceName, "cluster_token"),
486+
),
487+
},
488+
},
489+
ExternalProviders: map[string]resource.ExternalProvider{
490+
"azurerm": {
491+
Source: "hashicorp/azurerm",
492+
},
493+
},
494+
})
495+
}
496+
497+
func testAccAzureClusterWithFederationID(clusterName string) string {
498+
subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID")
499+
federationID := os.Getenv("AZURE_TF_ACCEPTANCE_TEST_FEDERATION_ID")
500+
tenantID := os.Getenv("AZURE_TF_ACCEPTANCE_TEST_FEDERATION_TENANT_ID")
501+
clientID := os.Getenv("AZURE_TF_ACCEPTANCE_TEST_FEDERATION_CLIENT_ID")
502+
503+
return fmt.Sprintf(`
504+
resource "castai_aks_cluster" "test" {
505+
name = %[3]q
506+
507+
region = "westeurope"
508+
subscription_id = %[1]q
509+
tenant_id = %[4]q
510+
client_id = %[5]q
511+
federation_id = %[2]q
512+
node_resource_group = "%[3]s-ng"
513+
}
514+
`, subscriptionID, federationID, clusterName, tenantID, clientID)
515+
}
516+
517+
func testAccAzureConfigUsingClientSecret(rName, rgName, ngName string) string {
472518
return fmt.Sprintf(`
473519
provider "azurerm" {
474520
features {}

castai/resource_allocation_group_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func allocationGroupWithAllClusterIds() string {
9393
cluster_ids = []
9494
}
9595
`
96-
return ConfigCompose(cfg)
96+
return concatenateConfigs(cfg)
9797
}
9898

9999
func allocationGroupConfig() string {
@@ -116,7 +116,7 @@ func allocationGroupConfig() string {
116116
}
117117
`
118118

119-
return ConfigCompose(cfg)
119+
return concatenateConfigs(cfg)
120120
}
121121

122122
func allocationGroupUpdatedConfig() string {
@@ -140,5 +140,5 @@ func allocationGroupUpdatedConfig() string {
140140
}
141141
`
142142

143-
return ConfigCompose(cfg)
143+
return concatenateConfigs(cfg)
144144
}

castai/resource_autoscaler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ func testAccAutoscalerConfig(rName, clusterName string, enabled bool, updated bo
10461046
delaySeconds = 300
10471047
}
10481048

1049-
return ConfigCompose(testAccEKSClusterConfig(rName, clusterName), fmt.Sprintf(`
1049+
return concatenateConfigs(testAccEKSClusterConfig(rName, clusterName), fmt.Sprintf(`
10501050
resource "castai_autoscaler" "test" {
10511051
cluster_id = castai_eks_cluster.test.id
10521052

castai/resource_edge_location_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func testAccEdgeLocationAWSConfigWithParams(rName, clusterName, description stri
203203
}
204204
zonesConfig += "]"
205205

206-
return ConfigCompose(testOmniClusterConfig(clusterName), fmt.Sprintf(`
206+
return concatenateConfigs(testOmniClusterConfig(clusterName), fmt.Sprintf(`
207207
resource "castai_edge_location" "test" {
208208
organization_id = %[5]q
209209
cluster_id = castai_omni_cluster.test.id
@@ -292,7 +292,7 @@ func testAccEdgeLocationGCPConfigWithParams(rName, clusterName, description stri
292292
networkTagsConfig += fmt.Sprintf("%q", tag)
293293
}
294294

295-
return ConfigCompose(testOmniClusterConfig(clusterName), fmt.Sprintf(`
295+
return concatenateConfigs(testOmniClusterConfig(clusterName), fmt.Sprintf(`
296296
resource "castai_edge_location" "test" {
297297
organization_id = %[6]q
298298
cluster_id = castai_omni_cluster.test.id
@@ -337,7 +337,7 @@ func testAccEdgeLocationOCIConfigWithParams(rName, description, ociCredentials s
337337
organizationID := testAccGetOrganizationID()
338338
clusterName := "test-oci-cluster"
339339

340-
return ConfigCompose(testOmniClusterConfig(clusterName), fmt.Sprintf(`
340+
return concatenateConfigs(testOmniClusterConfig(clusterName), fmt.Sprintf(`
341341
resource "castai_edge_location" "test" {
342342
organization_id = %[3]q
343343
cluster_id = castai_omni_cluster.test.id

castai/resource_node_configuration_aks_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestAccAKS_ResourceNodeConfiguration(t *testing.T) {
7373
}
7474

7575
func testAccAKSNodeConfigurationConfig(rName, clusterName, rgName, ngName string) string {
76-
return ConfigCompose(testAccAKSClusterConfig(rName, clusterName, rgName, ngName), fmt.Sprintf(`
76+
return concatenateConfigs(testAccAKSClusterConfig(rName, clusterName, rgName, ngName), fmt.Sprintf(`
7777
resource "castai_node_configuration" "test" {
7878
name = %[1]q
7979
cluster_id = castai_aks_cluster.test.id
@@ -97,7 +97,7 @@ resource "castai_node_configuration_default" "test" {
9797
}
9898

9999
func testAccAKSNodeConfigurationUpdated(rName, clusterName, rgName, ngName string) string {
100-
return ConfigCompose(testAccAKSClusterConfig(rName, clusterName, rgName, ngName), fmt.Sprintf(`
100+
return concatenateConfigs(testAccAKSClusterConfig(rName, clusterName, rgName, ngName), fmt.Sprintf(`
101101
resource "castai_node_configuration" "test" {
102102
name = %[2]q
103103
cluster_id = castai_aks_cluster.test.id

castai/resource_node_configuration_eks_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestAccEKS_ResourceNodeConfiguration(t *testing.T) {
102102
}
103103

104104
func testAccEKSNodeConfigurationConfig(rName, clusterName string) string {
105-
return ConfigCompose(testAccEKSClusterConfig(rName, clusterName), fmt.Sprintf(`
105+
return concatenateConfigs(testAccEKSClusterConfig(rName, clusterName), fmt.Sprintf(`
106106
variable "init_script" {
107107
type = string
108108
default = <<EOF
@@ -159,7 +159,7 @@ resource "castai_node_configuration_default" "test" {
159159
}
160160

161161
func testAccEKSNodeConfigurationUpdated(rName, clusterName string) string {
162-
return ConfigCompose(testAccEKSClusterConfig(rName, clusterName), fmt.Sprintf(`
162+
return concatenateConfigs(testAccEKSClusterConfig(rName, clusterName), fmt.Sprintf(`
163163
resource "castai_node_configuration" "test" {
164164
name = %[1]q
165165
cluster_id = castai_eks_cluster.test.id
@@ -186,7 +186,7 @@ resource "castai_node_configuration" "test" {
186186
}
187187

188188
func testAccEKSClusterConfig(rName string, clusterName string) string {
189-
return ConfigCompose(testAccAWSConfig(rName), fmt.Sprintf(`
189+
return concatenateConfigs(testAccAWSConfig(rName), fmt.Sprintf(`
190190
resource "castai_eks_clusterid" "test" {
191191
account_id = data.aws_caller_identity.current.account_id
192192
region = "eu-central-1"

castai/resource_node_configuration_gke_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func testAccGKENodeConfigurationConfigWithMaxPodsFormula(rName, clusterName, pro
150150
}
151151

152152
func testAccGKENodeConfigurationConfigWithGKEConfig(rName, clusterName, projectID, gkeParams string) string {
153-
return ConfigCompose(testAccGKEClusterConfig(rName, clusterName, projectID), fmt.Sprintf(`
153+
return concatenateConfigs(testAccGKEClusterConfig(rName, clusterName, projectID), fmt.Sprintf(`
154154
resource "castai_node_configuration" "test" {
155155
name = %[1]q
156156
cluster_id = castai_gke_cluster.test.id
@@ -174,7 +174,7 @@ resource "castai_node_configuration_default" "test" {
174174
}
175175

176176
func testAccGKENodeConfigurationUpdated(rName, clusterName, projectID string) string {
177-
return ConfigCompose(testAccGKEClusterConfig(rName, clusterName, projectID), fmt.Sprintf(`
177+
return concatenateConfigs(testAccGKEClusterConfig(rName, clusterName, projectID), fmt.Sprintf(`
178178
resource "castai_node_configuration" "test" {
179179
name = %[1]q
180180
cluster_id = castai_gke_cluster.test.id
@@ -213,7 +213,7 @@ resource "castai_node_configuration" "test" {
213213
`, rName))
214214
}
215215
func testAccGKEClusterConfig(rName string, clusterName string, projectID string) string {
216-
return ConfigCompose(testAccGCPConfig(rName, clusterName, projectID), fmt.Sprintf(`
216+
return concatenateConfigs(testAccGCPConfig(rName, clusterName, projectID), fmt.Sprintf(`
217217
resource "castai_gke_cluster" "test" {
218218
project_id = %[1]q
219219
location = "us-central1-c"

castai/resource_node_template_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,17 +383,17 @@ func Test_flattenPriceAdjustmentConfiguration(t *testing.T) {
383383
name: "configuration with adjustments",
384384
input: &sdk.NodetemplatesV1PriceAdjustmentConfiguration{
385385
InstanceTypeAdjustments: &map[string]string{
386-
"r7a.xlarge": "1.0",
387-
"r7i.xlarge": "1.20",
388-
"c6a.xlarge": "0.90",
386+
"r7a.xlarge": "1.0",
387+
"r7i.xlarge": "1.20",
388+
"c6a.xlarge": "0.90",
389389
},
390390
},
391391
want: []map[string]any{
392392
{
393393
FieldNodeTemplateInstanceTypeAdjustments: map[string]string{
394-
"r7a.xlarge": "1.0",
395-
"r7i.xlarge": "1.20",
396-
"c6a.xlarge": "0.90",
394+
"r7a.xlarge": "1.0",
395+
"r7i.xlarge": "1.20",
396+
"c6a.xlarge": "0.90",
397397
},
398398
},
399399
},
@@ -898,7 +898,7 @@ func TestAccEKS_ResourceNodeTemplate_basic(t *testing.T) {
898898
}
899899

900900
func testAccNodeTemplateConfig(rName, clusterName string) string {
901-
return ConfigCompose(testAccEKSClusterConfig(rName, clusterName), testAccNodeConfig(rName), testAccEdgeLocationsConfig(rName, clusterName), fmt.Sprintf(`
901+
return concatenateConfigs(testAccEKSClusterConfig(rName, clusterName), testAccNodeConfig(rName), testAccEdgeLocationsConfig(rName, clusterName), fmt.Sprintf(`
902902
resource "castai_node_template" "test" {
903903
cluster_id = castai_eks_cluster.test.id
904904
name = %[1]q
@@ -1054,7 +1054,7 @@ resource "castai_edge_location" "test_2" {
10541054
}
10551055

10561056
func testNodeTemplateUpdated(rName, clusterName string) string {
1057-
return ConfigCompose(testAccEKSClusterConfig(rName, clusterName), testAccNodeConfig(rName), testAccEdgeLocationsConfig(rName, clusterName), fmt.Sprintf(`
1057+
return concatenateConfigs(testAccEKSClusterConfig(rName, clusterName), testAccNodeConfig(rName), testAccEdgeLocationsConfig(rName, clusterName), fmt.Sprintf(`
10581058
resource "castai_node_template" "test" {
10591059
cluster_id = castai_eks_cluster.test.id
10601060
name = %[1]q
@@ -1170,7 +1170,7 @@ func testAccCheckNodeTemplateDestroy(templateName string) func(s *terraform.Stat
11701170
}
11711171

11721172
func testAccNodeConfig(rName string) string {
1173-
return ConfigCompose(fmt.Sprintf(`
1173+
return concatenateConfigs(fmt.Sprintf(`
11741174
data "aws_subnets" "cost" {
11751175
tags = {
11761176
Name = "*cost-terraform-cluster/SubnetPublic*"

0 commit comments

Comments
 (0)