Skip to content

Commit

Permalink
fix: ensure mutual exclusivity
Browse files Browse the repository at this point in the history
- Adds use of `ConflictsWith` for `r/hcx_vmc` for `sddc_id` and `sddc_name` to ensure mutual exclusivity.
- Adds use of `ExactlyOneO` for `r/hcx_vmc` for `sddc_id` and `sddc_name` to ensure at least one of them is provided.

Signed-off-by: Ryan Johnson <[email protected]>
  • Loading branch information
tenthirtyam committed Jan 29, 2025
1 parent 2d54c11 commit 7321185
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions docs/resources/vmc.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ resource "hcx_site_pairing" "example" {

## Argument Reference

* `sddc_name` - (Optional) The name of the SDDC. Either `sddc_name` or `sddc_id`
must be specified.
* `sddc_id` - (Optional) The ID of the SDDC. Either `sddc_id` or `sddc_name`
must be specified.
* `sddc_name` - (Optional) Specifies the name of the SDDC.
* `sddc_id` - (Optional) Specifies the ID of the SDDC.

~> **NOTE:** Either `sddc_name` or `sddc_id` **must** be provided, but not both.

## Attribute Reference

Expand Down
20 changes: 10 additions & 10 deletions resource_vmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ func resourceVmc() *schema.Resource {

Schema: map[string]*schema.Schema{
"sddc_id": {
Type: schema.TypeString,
Description: "The ID of the SDDC.",
Optional: true,
Type: schema.TypeString,
Description: "The ID of the SDDC.",
Optional: true,
ConflictsWith: []string{"sddc_name"}, // Ensures mutual exclusivity.
ExactlyOneOf: []string{"sddc_id", "sddc_name"}, // Enforces that at least one of them is provided.
},
"sddc_name": {
Type: schema.TypeString,
Description: "The name of the SDDC.",
Optional: true,
Type: schema.TypeString,
Description: "The name of the SDDC.",
Optional: true,
ConflictsWith: []string{"sddc_id"}, // Ensures mutual exclusivity.
ExactlyOneOf: []string{"sddc_id", "sddc_name"}, // Enforces that at least one of them is provided.
},
"cloud_url": {
Type: schema.TypeString,
Expand Down Expand Up @@ -62,10 +66,6 @@ func resourceVmcCreate(ctx context.Context, d *schema.ResourceData, m interface{
sddcName := d.Get("sddc_name").(string)
sddcID := d.Get("sddc_id").(string)

if sddcName == "" && sddcID == "" {
return diag.Errorf("SDDC name or Id must be specified")
}

// Authenticate with VMware Cloud Services
accessToken, err := hcx.VmcAuthenticate(token)
if err != nil {
Expand Down

0 comments on commit 7321185

Please sign in to comment.