Skip to content

fix: Stack creation panics if no project is provided in the creation options#1284

Open
arybolovlev wants to merge 4 commits intomainfrom
fix-stacks-create-options-valid
Open

fix: Stack creation panics if no project is provided in the creation options#1284
arybolovlev wants to merge 4 commits intomainfrom
fix-stacks-create-options-valid

Conversation

@arybolovlev
Copy link
Copy Markdown
Contributor

Description

When a new Stack is created without the mandatory Project field in the StackCreateOptions structure, the creation process panics instead of returning a validation error.

The following code will panic because the Project field is a pointer, and the validation method does not check whether it is nil:

s, err := client.Stacks.Create(context.TODO(), tfc.StackCreateOptions{
    Name: "a-stack",
})

This PR adds a nil pointer check to ensure that the ErrRequiredProject error is returned if the Project field is not set, or if it is set but Project.ID is empty.

Testing plan

I have added a unit test for the valid() method of the StackCreateOptions structure.

External links

Output from tests

Including output from tests may require access to a TFE instance. Ignore this section if you have no environment to test against.

$ go test . -timeout 1m -count 1 -v -run='Test_validStackCreateOptions'
=== RUN   Test_validStackCreateOptions
=== PAUSE Test_validStackCreateOptions
=== CONT  Test_validStackCreateOptions
=== RUN   Test_validStackCreateOptions/with_empty_stack_name
=== RUN   Test_validStackCreateOptions/with_empty_project_option
=== RUN   Test_validStackCreateOptions/with_empty_project_ID
=== RUN   Test_validStackCreateOptions/with_valid_options
--- PASS: Test_validStackCreateOptions (0.00s)
    --- PASS: Test_validStackCreateOptions/with_empty_stack_name (0.00s)
    --- PASS: Test_validStackCreateOptions/with_empty_project_option (0.00s)
    --- PASS: Test_validStackCreateOptions/with_empty_project_ID (0.00s)
    --- PASS: Test_validStackCreateOptions/with_valid_options (0.00s)
PASS
ok  	github.com/hashicorp/go-tfe	0.333s

Rollback Plan

Roll back to the previous version.

Changes to Security Controls

No.

@arybolovlev arybolovlev marked this pull request as ready for review February 19, 2026 12:42
@arybolovlev arybolovlev requested a review from a team as a code owner February 19, 2026 12:42
@datadog-terraform-cloud-hashicorp
Copy link
Copy Markdown

datadog-terraform-cloud-hashicorp Bot commented Feb 19, 2026

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 8bbcf65 | Docs | Give us feedback!

ctrombley
ctrombley previously approved these changes May 6, 2026
Copy link
Copy Markdown
Collaborator

@ctrombley ctrombley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @arybolovlev !

@hashicorp-cla-app
Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes


1 out of 2 committers have signed the CLA.

  • ctrombley
  • Aleksandr Rybolovlev

Aleksandr Rybolovlev seems not to be a GitHub user.
You need a GitHub account to be able to sign the CLA.
If you have already a GitHub account, please add the email address used for this commit to your account.

Have you signed the CLA already but the status is still pending? Recheck it.

1 similar comment
@hashicorp-cla-app
Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes


1 out of 2 committers have signed the CLA.

  • ctrombley
  • Aleksandr Rybolovlev

Aleksandr Rybolovlev seems not to be a GitHub user.
You need a GitHub account to be able to sign the CLA.
If you have already a GitHub account, please add the email address used for this commit to your account.

Have you signed the CLA already but the status is still pending? Recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants