Skip to content

Commit 074db10

Browse files
furkhatFurkhat Kasymov Genii Uulu
andauthored
feat: add new field federation_id to castai_aks_cluster resource (#621)
* aks_cluster support federation_id * test federation_id on the same onboarding for faster execution * use new sub * generate sdk * fix env var names * fix order of steps so that federation_id tested explicitly before being starting NC tests * datasource azure subnet for node config * requires explicitly provide empty feature to azurerm provider * fix node config resource name * re generate sdk * format code * re-generate sdk --------- Co-authored-by: Furkhat Kasymov Genii Uulu <furkhat@cast.ai>
1 parent 51f2b8f commit 074db10

File tree

9 files changed

+556
-13
lines changed

9 files changed

+556
-13
lines changed

.github/workflows/acceptance-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,8 @@ jobs:
6666
SSO_CLIENT_SECRET: ${{ secrets.SSO_CLIENT_SECRET }}
6767
SSO_DOMAIN: ${{ secrets.SSO_DOMAIN }}
6868
ACCEPTANCE_TEST_ORGANIZATION_ID: ${{ vars.TF_ACCEPTANCE_TEST_ORGANIZATION_ID }}
69+
AZURE_TF_ACCEPTANCE_TEST_FEDERATION_ID: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_FEDERATION_ID }}
70+
AZURE_TF_ACCEPTANCE_TEST_FEDERATION_TENANT_ID: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_ARM_TENANT_ID_V2 }}
71+
AZURE_TF_ACCEPTANCE_TEST_FEDERATION_CLIENT_ID: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_FEDERATION_CLIENT_ID }}
6972
run: make testacc-${{ matrix.cloud }}
7073

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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,15 @@ func TestAccAKS_ResourceAKSCluster(t *testing.T) {
440440
resource.TestCheckResourceAttrSet(clusterResourceName, "cluster_token"),
441441
),
442442
},
443+
{
444+
Config: testAccAKSWithFederationIDConfig(clusterName),
445+
Check: resource.ComposeTestCheckFunc(
446+
resource.TestCheckResourceAttr(clusterResourceName, "name", clusterName),
447+
resource.TestCheckResourceAttrSet(clusterResourceName, "credentials_id"),
448+
resource.TestCheckResourceAttr(clusterResourceName, "region", "westeurope"),
449+
resource.TestCheckResourceAttrSet(clusterResourceName, "cluster_token"),
450+
),
451+
},
443452
{
444453
Config: testAccAKSNodeConfigurationConfig(rName, clusterName, resourceGroupName),
445454
Check: resource.ComposeTestCheckFunc(
@@ -510,3 +519,23 @@ resource "castai_aks_cluster" "test" {
510519
511520
`, clusterName, subscriptionID, tenantID, clientID, clientSecret)
512521
}
522+
523+
func testAccAKSWithFederationIDConfig(clusterName string) string {
524+
subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID")
525+
federationID := os.Getenv("AZURE_TF_ACCEPTANCE_TEST_FEDERATION_ID")
526+
tenantID := os.Getenv("AZURE_TF_ACCEPTANCE_TEST_FEDERATION_TENANT_ID")
527+
clientID := os.Getenv("AZURE_TF_ACCEPTANCE_TEST_FEDERATION_CLIENT_ID")
528+
529+
return fmt.Sprintf(`
530+
resource "castai_aks_cluster" "test" {
531+
name = %[3]q
532+
533+
region = "westeurope"
534+
subscription_id = %[1]q
535+
tenant_id = %[4]q
536+
client_id = %[5]q
537+
federation_id = %[2]q
538+
node_resource_group = "%[3]s-ng"
539+
}
540+
`, subscriptionID, federationID, clusterName, tenantID, clientID)
541+
}

castai/resource_node_configuration_aks_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
)
66

77
func testAccAKSNodeConfigurationConfig(rName, clusterName, resourceGroupName string) string {
8-
return ConfigCompose(testAccAKSWithClientSecretConfig(clusterName), fmt.Sprintf(`
8+
return ConfigCompose(testAccAKSWithFederationIDConfig(clusterName), fmt.Sprintf(`
99
provider "azurerm" {
1010
features {}
1111
}
@@ -38,7 +38,7 @@ resource "castai_node_configuration_default" "test" {
3838
}
3939

4040
func testAccAKSNodeConfigurationUpdated(rName, clusterName, resourceGroupName string) string {
41-
return ConfigCompose(testAccAKSWithClientSecretConfig(clusterName), fmt.Sprintf(`
41+
return ConfigCompose(testAccAKSWithFederationIDConfig(clusterName), fmt.Sprintf(`
4242
provider "azurerm" {
4343
features {}
4444
}

castai/sdk/api.gen.go

Lines changed: 57 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)