Skip to content

Conversation

ianc769
Copy link
Contributor

@ianc769 ianc769 commented Apr 3, 2025

Adding project as a terraform managed resource option -> https://cloudstack.apache.org/api/apidocs-4.20/apis/createProject.html

Contributes to #82

Using this code for example:

resource "cloudstack_project" "foo" {
  name         = "terraform-test-project"
  display_text = "Terraform Test Project"
}
+ resource "cloudstack_project" "foo" {
  + display_text = "Terraform Test Project"
  + domain       = (known after apply)
  + id           = (known after apply)
  + name         = "terraform-test-project"
  }
cloudstack_project.foo: Creating...
cloudstack_project.foo: Creation complete after 1s [id=06c584de-8f5f-4c72-8eab-672668e3c165]

image

@ianc769
Copy link
Contributor Author

ianc769 commented Apr 14, 2025

I set this up for Cloudstack API 4.20, I see the tests are 4.18 and 4.19.

What's the back version compatibility of this project looking for?

There was a difference in the API between 4.18 and 4.19+ for this resource at a quick glance. So if there is a plan to add 4.20 Acceptance Tests and depreciate 4.18 I will wait for those results.

@ianc769
Copy link
Contributor Author

ianc769 commented Jun 11, 2025

Maybe supersedes #152

@ianc769
Copy link
Contributor Author

ianc769 commented Jun 12, 2025

@CodeBleu If possible can you kick a test off here? I merged your actions changes from earlier today to hopefully get the acceptance tests actually working

@CodeBleu
Copy link
Collaborator

CodeBleu commented Jun 12, 2025

@CodeBleu If possible can you kick a test off here? I merged your actions changes from earlier today to hopefully get the acceptance tests actually working

@ianc769
I kicked it off

@ianc769 ianc769 marked this pull request as ready for review June 16, 2025 16:41
@ianc769 ianc769 changed the title [WIP] Add CloudStack project resource Add CloudStack project resource Jun 16, 2025
@ianc769
Copy link
Contributor Author

ianc769 commented Jun 16, 2025

@CodeBleu Ok I think i resolved all the test issues, thanks for fixing the workflows!
If you can kick tests for this and #181 that would be much appreciated 😄

@ianc769 ianc769 changed the title Add CloudStack project resource Add CloudStack project resource Jul 10, 2025
@ianc769 ianc769 changed the title Add CloudStack project resource Add cloudstack_project resource Jul 14, 2025
Fix issue where getProjectByID() would always return "id not found" while
getProjectByName() could find the same project. CloudStack projects are only
unique within a domain context, so we now include domain ID in lookups.

- Modified getProjectByID() to accept optional domain parameter
- Updated all calls to include domain when available
- Updated test functions accordingly
- Updated documentation to clarify domain requirement for project imports
@ianc769
Copy link
Contributor Author

ianc769 commented Jul 17, 2025

After some more in depth testing with all the new resources I'm adding in #181 #195 and #197 I found some issues I had to fix when deleting project resources.

@DaanHoogland DaanHoogland requested a review from Copilot August 6, 2025 08:04
Copilot

This comment was marked as outdated.

@kiranchavala kiranchavala added this to the v0.6.0 milestone Aug 8, 2025
sureshanaparti and others added 3 commits August 11, 2025 11:48
Bumps [github.com/cloudflare/circl](https://github.com/cloudflare/circl) from 1.3.7 to 1.6.1.
- [Release notes](https://github.com/cloudflare/circl/releases)
- [Commits](cloudflare/circl@v1.3.7...v1.6.1)

---
updated-dependencies:
- dependency-name: github.com/cloudflare/circl
  dependency-version: 1.6.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds comprehensive support for the cloudstack_project resource to the CloudStack Terraform provider, implementing both the resource and data source functionality for managing CloudStack projects. The implementation includes full CRUD operations, import support, and proper error handling.

Key changes:

  • Added cloudstack_project resource with create, read, update, delete, and import operations
  • Added cloudstack_project data source for querying existing projects
  • Enhanced existing firewall resources to support project context

Reviewed Changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
cloudstack/resource_cloudstack_project.go Core implementation of the project resource with CRUD operations
cloudstack/resource_cloudstack_project_test.go Comprehensive test suite covering all project resource scenarios
cloudstack/data_source_cloudstack_project.go Data source implementation for querying projects with filtering
cloudstack/data_source_cloudstack_project_test.go Test cases for project data source functionality
cloudstack/provider.go Registration of new resource and data source
cloudstack/resources.go Added domain ID lookup support for project operations
cloudstack/resource_cloudstack_firewall.go Added project parameter support
cloudstack/resource_cloudstack_egress_firewall.go Added project parameter support
website/docs/r/project.html.markdown Documentation for the project resource
website/docs/d/project.html.markdown Documentation for the project data source
website/cloudstack.erb Added navigation link for project resource
go.mod Updated CloudStack Go SDK and dependencies
README.md Minor documentation updates

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


"display_text": {
Type: schema.TypeString,
Required: true, // Required for API version 4.18 and lower. TODO: Make this optional when support for API versions older than 4.18 is dropped.
Copy link
Preview

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

The TODO comment should be formatted as a proper Go comment starting with TODO: for better tooling support and clarity.

Suggested change
Required: true, // Required for API version 4.18 and lower. TODO: Make this optional when support for API versions older than 4.18 is dropped.
Required: true, // Required for API version 4.18 and lower.
// TODO: Make this optional when support for API versions older than 4.18 is dropped.

Copilot uses AI. Check for mistakes.

Comment on lines +116 to +119
// The CloudStack API parameter order differs between versions:
// - In API 4.18 and lower: displaytext is the first parameter and name is the second
// - In API 4.19 and higher: name is the first parameter and displaytext is optional
// The CloudStack Go SDK uses the API 4.18 parameter order
Copy link
Preview

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

[nitpick] This comment block explains the API version differences but is quite verbose. Consider condensing it to focus on the essential information that affects the current implementation.

Suggested change
// The CloudStack API parameter order differs between versions:
// - In API 4.18 and lower: displaytext is the first parameter and name is the second
// - In API 4.19 and higher: name is the first parameter and displaytext is optional
// The CloudStack Go SDK uses the API 4.18 parameter order
// The CloudStack Go SDK expects parameters in the API 4.18 order: displaytext, name.

Copilot uses AI. Check for mistakes.

Comment on lines +381 to +383
// Note: The 'name' parameter is only available in API 4.19 and higher
// If you're using API 4.18 or lower, the SetName method might not work
// In that case, you might need to update the display_text only
Copy link
Preview

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

This comment suggests conditional behavior based on API versions but the code doesn't implement this logic. Either implement the version checking or remove the misleading comment.

Suggested change
// Note: The 'name' parameter is only available in API 4.19 and higher
// If you're using API 4.18 or lower, the SetName method might not work
// In that case, you might need to update the display_text only

Copilot uses AI. Check for mistakes.

Comment on lines +417 to +423
// Note: accountid is not directly supported by the UpdateProject API,
// but we can use the account parameter instead if accountid has changed
if d.HasChange("accountid") && !d.HasChange("account") {
// If accountid has changed but account hasn't, we need to look up the account name
// This is a placeholder - in a real implementation, you would need to look up
// the account name from the accountid
log.Printf("[WARN] Updating accountid is not directly supported by the API. Please use account instead.")
Copy link
Preview

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

This code block acknowledges incomplete functionality with a placeholder comment. Either implement the account name lookup or remove this feature if it's not supported.

Suggested change
// Note: accountid is not directly supported by the UpdateProject API,
// but we can use the account parameter instead if accountid has changed
if d.HasChange("accountid") && !d.HasChange("account") {
// If accountid has changed but account hasn't, we need to look up the account name
// This is a placeholder - in a real implementation, you would need to look up
// the account name from the accountid
log.Printf("[WARN] Updating accountid is not directly supported by the API. Please use account instead.")
// Note: accountid is not directly supported by the UpdateProject API.
// If accountid has changed but account hasn't, updating the project owner is not supported.
if d.HasChange("accountid") && !d.HasChange("account") {
log.Printf("[WARN] Updating project owner using only accountid is not supported by the API. Please use the account parameter instead.")

Copilot uses AI. Check for mistakes.

@kiranchavala
Copy link
Collaborator

@ianc769, could you please resolve the conflict

// but we can use the account parameter instead if accountid has changed
if d.HasChange("accountid") && !d.HasChange("account") {
// If accountid has changed but account hasn't, we need to look up the account name
// This is a placeholder - in a real implementation, you would need to look up
Copy link
Member

Choose a reason for hiding this comment

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

@ianc769 Can we implement this? The changes should be small enough and this is most likely already being done at other places in the project.

Copy link
Member

@vishesh92 vishesh92 left a comment

Choose a reason for hiding this comment

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

clgtm. Just one comment.

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.

Improvement request - Support the following resource creation via terraform
6 participants