Acceptance tests fixes (#120)
* Update Kubernetes version * Update nodepool OS * Revert Kubernetes version to 1.24 * Add maintenance field to cluster-min * Remove hardcoded kubernetes version * Remove hardcoded setting * Revert minor version of Kubernetes upgrade * Fix post test check destroy * Fix missing pointer * Fix labels using wrong delimiters * Fix typo in provider config * Lint fix --------- Co-authored-by: Henrique Santos <henrique.santos@freiheit.com>
This commit is contained in:
parent
b6100ec8d5
commit
71bf63cbc9
4 changed files with 42 additions and 22 deletions
|
|
@ -229,7 +229,7 @@ func (r *projectResource) Create(ctx context.Context, req resource.CreateRequest
|
|||
// Read refreshes the Terraform state with the latest data.
|
||||
func (r *projectResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { // nolint:gocritic // function signature required by Terraform
|
||||
var model Model
|
||||
diags := req.State.Get(ctx, model)
|
||||
diags := req.State.Get(ctx, &model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
|
|
|
|||
|
|
@ -23,7 +23,11 @@ var projectResource = map[string]string{
|
|||
"new_label": "a-label",
|
||||
}
|
||||
|
||||
func resourceConfig(name, label string) string {
|
||||
func resourceConfig(name string, label *string) string {
|
||||
labelConfig := ""
|
||||
if label != nil {
|
||||
labelConfig = fmt.Sprintf("new_label = %q", *label)
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
%s
|
||||
|
||||
|
|
@ -41,7 +45,7 @@ func resourceConfig(name, label string) string {
|
|||
projectResource["parent_container_id"],
|
||||
name,
|
||||
projectResource["billing_reference"],
|
||||
label,
|
||||
labelConfig,
|
||||
testutil.TestProjectServiceAccountEmail,
|
||||
)
|
||||
}
|
||||
|
|
@ -53,7 +57,7 @@ func TestAccResourceManagerResource(t *testing.T) {
|
|||
Steps: []resource.TestStep{
|
||||
// Creation
|
||||
{
|
||||
Config: resourceConfig(projectResource["name"], ""),
|
||||
Config: resourceConfig(projectResource["name"], nil),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
// Project data
|
||||
resource.TestCheckResourceAttrSet("stackit_resourcemanager_project.project", "container_id"),
|
||||
|
|
@ -71,7 +75,7 @@ func TestAccResourceManagerResource(t *testing.T) {
|
|||
data "stackit_resourcemanager_project" "project" {
|
||||
container_id = stackit_resourcemanager_project.project.container_id
|
||||
}`,
|
||||
resourceConfig(projectResource["name"], ""),
|
||||
resourceConfig(projectResource["name"], nil),
|
||||
),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
// Project data
|
||||
|
|
@ -108,7 +112,7 @@ func TestAccResourceManagerResource(t *testing.T) {
|
|||
},
|
||||
// Update
|
||||
{
|
||||
Config: resourceConfig(fmt.Sprintf("%s-new", projectResource["name"]), "new_label='a-label'"),
|
||||
Config: resourceConfig(fmt.Sprintf("%s-new", projectResource["name"]), utils.Ptr("a-label")),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
// Project data
|
||||
resource.TestCheckResourceAttrSet("stackit_resourcemanager_project.project", "container_id"),
|
||||
|
|
@ -156,15 +160,20 @@ func testAccCheckResourceManagerDestroy(s *terraform.State) error {
|
|||
|
||||
items := *projectsResp.Items
|
||||
for i := range items {
|
||||
if utils.Contains(projectsToDestroy, *items[i].ContainerId) {
|
||||
err := client.DeleteProjectExecute(ctx, *items[i].ContainerId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("destroying project %s during CheckDestroy: %w", *items[i].ContainerId, err)
|
||||
}
|
||||
_, err = wait.DeleteProjectWaitHandler(ctx, client, *items[i].ContainerId).WaitWithContext(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("destroying project %s during CheckDestroy: waiting for deletion %w", *items[i].ContainerId, err)
|
||||
}
|
||||
if *items[i].LifecycleState == resourcemanager.LIFECYCLESTATE_DELETING {
|
||||
continue
|
||||
}
|
||||
if !utils.Contains(projectsToDestroy, *items[i].ContainerId) {
|
||||
continue
|
||||
}
|
||||
|
||||
err := client.DeleteProjectExecute(ctx, *items[i].ContainerId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("destroying project %s during CheckDestroy: %w", *items[i].ContainerId, err)
|
||||
}
|
||||
_, err = wait.DeleteProjectWaitHandler(ctx, client, *items[i].ContainerId).WaitWithContext(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("destroying project %s during CheckDestroy: waiting for deletion %w", *items[i].ContainerId, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue