You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by "ianc769 (via GitHub)" <gi...@apache.org> on 2025/11/06 18:27:38 UTC
[PR] feat: Update `resource_cloudstack_security_group` to allow `domainid` or `projectid` [cloudstack-terraform-provider]
ianc769 opened a new pull request, #262:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/262
Update `resource_cloudstack_security_group` to allow `domainid` or `projectid`
https://cloudstack.apache.org/api/apidocs-4.21/apis/createSecurityGroup.html
This is breaking since I'm renaming `project` to `projectid` (just more descriptive as to what is expected in this field and matches the actual api call)
With the code:
```hcl
data "cloudstack_domain" "root" {
filter {
name = "name"
value = "ROOT"
}
}
resource "cloudstack_security_group" "foo" {
name = "terraform-security-group-account"
description = "terraform-security-group-account-text"
account = "admin"
domainid = "ROOT"
}
resource "cloudstack_security_group" "foo2" {
name = "terraform-security-group-project"
description = "terraform-security-group-project-text"
projectid = "fdaa5a01-bc8c-4e50-a0ea-9135a1c54fb3"
}
```
```shell
12:15:41.534 STDOUT terraform: Terraform used the selected providers to generate the following execution
12:15:41.534 STDOUT terraform: plan. Resource actions are indicated with the following symbols:
12:15:41.535 STDOUT terraform: + create
12:15:41.535 STDOUT terraform: ~ update in-place
12:15:41.535 STDOUT terraform: Terraform will perform the following actions:
12:15:41.535 STDOUT terraform: # cloudstack_security_group.foo will be created
12:15:41.535 STDOUT terraform: + resource "cloudstack_security_group" "foo" {
12:15:41.535 STDOUT terraform: + account = "admin"
12:15:41.535 STDOUT terraform: + description = "terraform-security-group-account-text"
12:15:41.535 STDOUT terraform: + domainid = "03ff694f-a2d5-11f0-95ca-52540047021e"
12:15:41.535 STDOUT terraform: + id = (known after apply)
12:15:41.535 STDOUT terraform: + name = "terraform-security-group-account"
12:15:41.535 STDOUT terraform: + projectid = (known after apply)
12:15:41.535 STDOUT terraform: }
12:15:41.535 STDOUT terraform: # cloudstack_security_group.foo2 will be created
12:15:41.535 STDOUT terraform: + resource "cloudstack_security_group" "foo2" {
12:15:41.535 STDOUT terraform: + description = "terraform-security-group-project-text"
12:15:41.535 STDOUT terraform: + domainid = (known after apply)
12:15:41.535 STDOUT terraform: + id = (known after apply)
12:15:41.535 STDOUT terraform: + name = "terraform-security-group-project"
12:15:41.535 STDOUT terraform: + projectid = "fdaa5a01-bc8c-4e50-a0ea-9135a1c54fb3"
12:15:41.535 STDOUT terraform: }
12:15:57.912 STDOUT terraform: Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Update `resource_cloudstack_security_group` to allow `domainid` or `projectid` [cloudstack-terraform-provider]
Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti commented on PR #262:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/262#issuecomment-4933342321
Hi @ianc769 Can you check and address the outstanding comments. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Update `resource_cloudstack_security_group` to allow `domainid` or `projectid` [cloudstack-terraform-provider]
Posted by "vishesh92 (via GitHub)" <gi...@apache.org>.
vishesh92 commented on code in PR #262:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/262#discussion_r2910994084
##########
cloudstack/resource_cloudstack_security_group.go:
##########
@@ -51,7 +51,20 @@ func resourceCloudStackSecurityGroup() *schema.Resource {
ForceNew: true,
},
- "project": {
+ "account": {
+ Type: schema.TypeString,
+ Optional: true,
+ ForceNew: true,
+ },
+
+ "domainid": {
+ Type: schema.TypeString,
+ Optional: true,
+ Computed: true,
+ ForceNew: true,
+ },
+
+ "projectid": {
Review Comment:
```suggestion
"project": {
```
to maintain consistency with other resources.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Update `resource_cloudstack_security_group` to allow `domainid` or `projectid` [cloudstack-terraform-provider]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #262:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/262#discussion_r2911014084
##########
cloudstack/resources.go:
##########
@@ -162,6 +162,19 @@ func setProjectid(p cloudstack.ProjectIDSetter, cs *cloudstack.CloudStackClient,
return nil
}
+// If there is a domain supplied, we retrieve and set the domain id
+func setDomainid(p cloudstack.DomainIDSetter, cs *cloudstack.CloudStackClient, d *schema.ResourceData) error {
+ if domain, ok := d.GetOk("domain"); ok {
+ domainid, e := retrieveID(cs, "domain", domain.(string))
+ if e != nil {
+ return e.Error()
+ }
+ p.SetDomainid(domainid)
+ }
+
+ return nil
+}
Review Comment:
`setDomainid` is introduced but not used anywhere in the current codebase (search only finds its definition). If this helper is intended for upcoming changes, consider adding the call sites in this PR; otherwise, it’s dead code that increases maintenance surface and can be removed until needed.
##########
cloudstack/resource_cloudstack_security_group.go:
##########
@@ -97,7 +140,7 @@ func resourceCloudStackSecurityGroupRead(d *schema.ResourceData, meta interface{
// Get the security group details
sg, count, err := cs.SecurityGroup.GetSecurityGroupByID(
d.Id(),
- cloudstack.WithProject(d.Get("project").(string)),
+ cloudstack.WithProject(d.Get("projectid").(string)),
)
Review Comment:
Import uses importStatePassthrough, which populates the state attribute `project`, but this resource now reads project context from `projectid` (WithProject(d.Get("projectid"))). Importing with a project prefix (e.g., `my-project/<id>`) will therefore lose the project scope and may fail to read/delete the SG. Consider switching this resource to a dedicated importer that sets `projectid` from the prefix (and optionally also supports legacy `project` for backward compatibility).
##########
cloudstack/resource_cloudstack_security_group.go:
##########
@@ -66,6 +79,18 @@ func resourceCloudStackSecurityGroupCreate(d *schema.ResourceData, meta interfac
name := d.Get("name").(string)
+ // Validate that account is used with domainid
+ if account, ok := d.GetOk("account"); ok {
+ if _, domainOk := d.GetOk("domainid"); !domainOk {
+ return fmt.Errorf("account parameter requires domainid to be set")
+ }
+ // Account and projectid are mutually exclusive
+ if _, projectOk := d.GetOk("projectid"); projectOk {
+ return fmt.Errorf("account and projectid parameters are mutually exclusive")
+ }
+ log.Printf("[DEBUG] Creating security group %s for account %s", name, account)
+ }
Review Comment:
`account` from `d.GetOk("account")` is an `interface{}`; logging it with `%s` will produce `%!s(interface {}=...)` in logs. Cast to string (or use `%v`) before logging.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Update `resource_cloudstack_security_group` to allow `domainid` or `projectid` [cloudstack-terraform-provider]
Posted by "ianc769 (via GitHub)" <gi...@apache.org>.
ianc769 closed pull request #262: feat: Update `resource_cloudstack_security_group` to allow `domainid` or `projectid`
URL: https://github.com/apache/cloudstack-terraform-provider/pull/262
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org