Skip to content

Commit

Permalink
test: fix ACC test for kubernetes cloud resource
Browse files Browse the repository at this point in the history
  • Loading branch information
anvial committed Oct 5, 2024
1 parent e1c2331 commit e0e45f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
14 changes: 9 additions & 5 deletions internal/provider/resource_kubernetes_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ func (r *kubernetesCloudResource) Schema(_ context.Context, req resource.SchemaR
"credential": schema.StringAttribute{
Description: "The name of the credential created for this cloud.",
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"kubernetes_config": schema.StringAttribute{
Description: "The kubernetes config file path for the cloud. Cloud credentials will be added to the Juju controller for you.",
Expand Down Expand Up @@ -175,11 +178,12 @@ func (r *kubernetesCloudResource) Create(ctx context.Context, req resource.Creat
return
}

r.trace(fmt.Sprintf("Created kubernetes cloud %s", plan.CloudName.ValueString()))

plan.CloudCredential = types.StringValue(cloudCredentialName)
plan.ID = types.StringValue(newKubernetesCloudID(plan.CloudName.ValueString(), plan.CloudCredential.ValueString()))
plan.ID = types.StringValue(newKubernetesCloudID(plan.CloudName.ValueString(), cloudCredentialName))

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)

r.trace(fmt.Sprintf("Created kubernetes cloud %s", plan.CloudName.ValueString()))
}

// Read reads the current state of the kubernetes cloud.
Expand Down Expand Up @@ -209,12 +213,12 @@ func (r *kubernetesCloudResource) Read(ctx context.Context, req resource.ReadReq
return
}

state.ParentCloudName = types.StringValue(readKubernetesCloudOutput.ParentCloudName)
state.ParentCloudRegion = types.StringValue(readKubernetesCloudOutput.ParentCloudRegion)
state.CloudName = types.StringValue(readKubernetesCloudOutput.Name)
state.CloudCredential = types.StringValue(readKubernetesCloudOutput.CredentialName)
state.ID = types.StringValue(newKubernetesCloudID(readKubernetesCloudOutput.Name, readKubernetesCloudOutput.CredentialName))

r.trace(fmt.Sprintf("Read kubernetes cloud %s", state.CloudName))

// Set the state onto the Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
Expand Down
26 changes: 0 additions & 26 deletions internal/provider/resource_kubernetes_cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,11 @@ import (
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func getFakeCloudConfig() string {
return `<<-EOT
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: ZmFrZS1jZXJ0aWZpY2F0ZS1hdXRob3JpdHktZGF0YQ==
server: https://10.172.195.202:16443
name: microk8s-cluster
contexts:
- context:
cluster: microk8s-cluster
user: admin
name: fake-cloud-context
current-context: fake-cloud-context
kind: Config
preferences: {}
users:
- name: admin
user:
client-certificate-data: ZmFrZS1jbGllbnQtY2VydGlmaWNhdGUtZGF0YQ==
client-key-data: ZmFrZS1jbGllbnQta2V5LWRhdGE=
EOT
`
}

func TestAcc_ResourceKubernetesCloud(t *testing.T) {
if testingCloud != LXDCloudTesting {
t.Skip(t.Name() + " only runs with LXD")
}
cloudName := acctest.RandomWithPrefix("tf-test-k8scloud")

cloudConfig := os.Getenv("MICROK8S_CONFIG")

//Debug print plan
Expand Down

0 comments on commit e0e45f9

Please sign in to comment.