From 8f5e28a93d446954b94eea8ec0a1d63a960d5782 Mon Sep 17 00:00:00 2001 From: Ales Stimec Date: Mon, 16 Dec 2024 08:15:51 +0100 Subject: [PATCH] fix: kubernetes cloud resource --- .github/workflows/test_integration_jaas.yaml | 2 ++ .../provider/resource_kubernetes_cloud.go | 12 +++++++---- .../resource_kubernetes_cloud_test.go | 20 +++++++++++-------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test_integration_jaas.yaml b/.github/workflows/test_integration_jaas.yaml index 6473a4cb..89046315 100644 --- a/.github/workflows/test_integration_jaas.yaml +++ b/.github/workflows/test_integration_jaas.yaml @@ -67,6 +67,8 @@ jobs: jimm-version: v3.1.10 juju-channel: 3/stable ghcr-pat: ${{ secrets.GITHUB_TOKEN }} + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 - name: Setup microk8s for juju_kubernetes_cloud test run: | sudo snap install microk8s --channel=1.28-strict/stable diff --git a/internal/provider/resource_kubernetes_cloud.go b/internal/provider/resource_kubernetes_cloud.go index d7a5858a..9f4a6932 100644 --- a/internal/provider/resource_kubernetes_cloud.go +++ b/internal/provider/resource_kubernetes_cloud.go @@ -128,8 +128,10 @@ func (r *kubernetesCloudResource) Create(ctx context.Context, req resource.Creat // Create the kubernetes cloud. cloudCredentialName, err := r.client.Clouds.CreateKubernetesCloud( &juju.CreateKubernetesCloudInput{ - Name: plan.CloudName.ValueString(), - KubernetesConfig: plan.KubernetesConfig.ValueString(), + Name: plan.CloudName.ValueString(), + KubernetesConfig: plan.KubernetesConfig.ValueString(), + ParentCloudName: plan.ParentCloudName.String(), + ParentCloudRegion: plan.ParentCloudRegion.String(), }, ) if err != nil { @@ -201,8 +203,10 @@ func (r *kubernetesCloudResource) Update(ctx context.Context, req resource.Updat // Update the kubernetes cloud. err := r.client.Clouds.UpdateKubernetesCloud( juju.UpdateKubernetesCloudInput{ - Name: plan.CloudName.ValueString(), - KubernetesConfig: plan.KubernetesConfig.ValueString(), + Name: plan.CloudName.ValueString(), + KubernetesConfig: plan.KubernetesConfig.ValueString(), + ParentCloudName: plan.ParentCloudName.String(), + ParentCloudRegion: plan.ParentCloudRegion.String(), }, ) if err != nil { diff --git a/internal/provider/resource_kubernetes_cloud_test.go b/internal/provider/resource_kubernetes_cloud_test.go index 5a6aafc1..d625be44 100644 --- a/internal/provider/resource_kubernetes_cloud_test.go +++ b/internal/provider/resource_kubernetes_cloud_test.go @@ -14,12 +14,6 @@ import ( ) func TestAcc_ResourceKubernetesCloud(t *testing.T) { - // Note (alesstimec): Skipping this test, because the default - // hosted cloud tf provider adds is "other", which cannot - // be parsed by JIMM - it needs a valid cloud/region to determine - // which controller to add the cloud to. - SkipJAAS(t) - // TODO: This test is not adding model as a resource, which is required. // The reason in the race that we (potentially) have in the Juju side. // Once the problem is fixed (https://bugs.launchpad.net/juju/+bug/2084448), @@ -30,12 +24,17 @@ func TestAcc_ResourceKubernetesCloud(t *testing.T) { cloudName := acctest.RandomWithPrefix("tf-test-k8scloud") cloudConfig := os.Getenv("MICROK8S_CONFIG") + jaasTest := false + if _, ok := os.LookupEnv("IS_JAAS"); ok { + jaasTest = true + } + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: frameworkProviderFactories, Steps: []resource.TestStep{ { - Config: testAccResourceKubernetesCloudWithoutModel(cloudName, cloudConfig), + Config: testAccResourceKubernetesCloudWithoutModel(cloudName, cloudConfig, jaasTest), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("juju_kubernetes_cloud."+cloudName, "name", cloudName), ), @@ -44,16 +43,21 @@ func TestAcc_ResourceKubernetesCloud(t *testing.T) { }) } -func testAccResourceKubernetesCloudWithoutModel(cloudName string, config string) string { +func testAccResourceKubernetesCloudWithoutModel(cloudName string, config string, jaasTest bool) string { return internaltesting.GetStringFromTemplateWithData( "testAccResourceSecret", ` resource "juju_kubernetes_cloud" "{{.CloudName}}" { name = "{{.CloudName}}" kubernetes_config = file("~/microk8s-config.yaml") + {{ if .JAASTest }} + parent_cloud_name = "localhost" + parent_cloud_region = "localhost" + {{ end }} } `, internaltesting.TemplateData{ "CloudName": cloudName, "Config": config, + "JAASTest": jaasTest, }) }