Skip to content

Commit

Permalink
Add vcd_tm_region_storage_policy + vcd_tm_content_library resource an…
Browse files Browse the repository at this point in the history
…d data source (#1339)

Signed-off-by: abarreiro <abarreiro@vmware.com>
  • Loading branch information
adambarreiro authored Oct 21, 2024
1 parent 861513e commit 9334ae8
Show file tree
Hide file tree
Showing 19 changed files with 782 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .changes/v4.0.0/1339-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* **New Data Source:** `vcd_tm_region_storage_policy` to read Region Storage Policies [GH-1339]
* **New Resource:** `vcd_tm_content_library` to manage Content Libraries [GH-1339]
* **New Data Source:** `vcd_tm_content_library` to read Content Libraries [GH-1339]
3 changes: 3 additions & 0 deletions .github/workflows/check-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
with:
fetch-depth: 0 # Required to have tag information available

- name: Install Terraform binary
uses: hashicorp/setup-terraform@v3

- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
Expand Down
5 changes: 4 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ TEST?=$$(go list ./... )
GOFMT_FILES?=$$(find . -name '*.go' )
WEBSITE_REPO=github.com/hashicorp/terraform-website
GIT_DESCRIBE=$(shell git describe --tags)

PKG_NAME=vcd

default: build
Expand Down Expand Up @@ -137,6 +136,10 @@ testnetwork: fmtcheck
testextnetwork: fmtcheck
@sh -c "'$(CURDIR)/scripts/runtest.sh' extnetwork"

# Runs the acceptance test for tm
testtm: fmtcheck
@sh -c "'$(CURDIR)/scripts/runtest.sh' tm"

# vets all .go files
vet:
@echo "go vet ."
Expand Down
7 changes: 5 additions & 2 deletions scripts/runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ function acceptance_test {
if [ -n "$VERBOSE" ]
then
echo "# check for config file"
echo "TF_ACC=1 go test -tags '$tags' -v -timeout $timeout"
echo "TF_ACC=1 go test -tags '$tags' -vcd-add-provider -v -timeout $timeout"
fi

if [ -z "$DRY_RUN" ]
then
check_for_config_file
TF_ACC=1 go test -tags "$tags" $testoptions -v -timeout $timeout
TF_ACC=1 go test -tags "$tags" $testoptions -vcd-add-provider -v -timeout $timeout
check_exit_code
fi
}
Expand Down Expand Up @@ -403,6 +403,9 @@ case $wanted in
vm)
acceptance_test vm
;;
tm)
acceptance_test tm
;;
network)
acceptance_test network
;;
Expand Down
14 changes: 13 additions & 1 deletion vcd/config_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build api || functional || catalog || vapp || network || extnetwork || org || query || vm || vdc || gateway || disk || binary || lb || lbServiceMonitor || lbServerPool || lbAppProfile || lbAppRule || lbVirtualServer || access_control || user || standaloneVm || search || auth || nsxt || role || alb || certificate || vdcGroup || ldap || rde || uiPlugin || providerVdc || cse || slz || multisite || ALL
//go:build api || functional || catalog || vapp || network || extnetwork || org || query || vm || vdc || gateway || disk || binary || lb || lbServiceMonitor || lbServerPool || lbAppProfile || lbAppRule || lbVirtualServer || access_control || user || standaloneVm || search || auth || nsxt || role || alb || certificate || vdcGroup || ldap || rde || uiPlugin || providerVdc || cse || slz || multisite || tm || ALL

package vcd

Expand Down Expand Up @@ -107,6 +107,12 @@ type TestConfig struct {
UseVcdConnectionCache bool `json:"useVcdConnectionCache"`
MaxRetryTimeout int `json:"maxRetryTimeout"`
} `json:"provider"`
Tm struct {
Org string `json:"org"` // temporary field to make skipIfNotTm work
Region string `json:"region"`
RegionStoragePolicy string `json:"regionStoragePolicy"`
Vdc string `json:"vdc"`
} `json:"tm,omitempty"`
VCD struct {
Org string `json:"org"`
Vdc string `json:"vdc"`
Expand Down Expand Up @@ -416,6 +422,12 @@ func skipIfNotSysAdmin(t *testing.T) {
}
}

func skipIfNotTm(t *testing.T) {
if testConfig.Tm.Org == "" {
t.Skip(t.Name() + " requires 'tm' branch filled in")
}
}

// Gets a list of all variables mentioned in a template
func GetVarsFromTemplate(tmpl string) []string {
var varList []string
Expand Down
98 changes: 98 additions & 0 deletions vcd/datasource_vcd_tm_content_library.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package vcd

import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func datasourceVcdTmContentLibrary() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceVcdTmContentLibraryRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "The name of the Content Library",
},
"storage_policy_ids": {
Type: schema.TypeSet,
Computed: true,
Description: "A set of Region Storage Policy or VDC Storage Policy IDs used by this Content Library",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"auto_attach": {
Type: schema.TypeBool,
Computed: true,
Description: "For Tenant Content Libraries this field represents whether this Content Library should be " +
"automatically attached to all current and future namespaces in the tenant organization",
},
"creation_date": {
Type: schema.TypeString,
Computed: true,
Description: "The ISO-8601 timestamp representing when this Content Library was created",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The description of the Content Library",
},
"is_shared": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether this Content Library is shared with other Organziations",
},
"is_subscribed": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether this Content Library is subscribed from an external published library",
},
"library_type": {
Type: schema.TypeString,
Computed: true,
Description: "The type of content library, can be either PROVIDER (Content Library that is scoped to a " +
"provider) or TENANT (Content Library that is scoped to a tenant organization)",
},
"owner_org_id": {
Type: schema.TypeString,
Computed: true,
Description: "The reference to the Organization that the Content Library belongs to",
},
"subscription_config": {
Type: schema.TypeList,
Computed: true,
Description: "A block representing subscription settings of a Content Library",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"subscription_url": {
Type: schema.TypeString,
Computed: true,
Description: "Subscription url of this Content Library",
},
"password": {
Type: schema.TypeString,
Computed: true,
Description: "Password to use to authenticate with the publisher",
},
"need_local_copy": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether to eagerly download content from publisher and store it locally",
},
},
},
},
"version_number": {
Type: schema.TypeInt,
Computed: true,
Description: "Version number of this Content library",
},
},
}
}

func datasourceVcdTmContentLibraryRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
return genericVcdTmContentLibraryRead(ctx, d, meta, "datasource")
}
50 changes: 50 additions & 0 deletions vcd/datasource_vcd_tm_region_storage_policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package vcd

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func datasourceVcdTmRegionStoragePolicy() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceVcdTmRegionStoragePolicyRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "Region Storage Policy name",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "Description of the Region Storage Policy",
},
"region_id": {
Type: schema.TypeString,
Computed: true,
Description: "The Region that this Region Storage Policy belongs to",
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "The creation status of the Region Storage Policy. Can be [NOT_READY, READY]",
},
"storage_capacity_mb": {
Type: schema.TypeInt,
Computed: true,
Description: "Storage capacity in megabytes for this Region Storage Policy",
},
"storage_consumed_mb": {
Type: schema.TypeInt,
Computed: true,
Description: "Consumed storage in megabytes for this Region Storage Policy",
},
},
}
}

func datasourceVcdTmRegionStoragePolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
return genericVcdTmRegionStoragePolicyRead(ctx, d, meta, "datasource")
}
5 changes: 5 additions & 0 deletions vcd/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ var globalDataSourceMap = map[string]*schema.Resource{
"vcd_nsxt_alb_virtual_service_http_req_rules": datasourceVcdAlbVirtualServiceReqRules(), // 3.14
"vcd_nsxt_alb_virtual_service_http_resp_rules": datasourceVcdAlbVirtualServiceRespRules(), // 3.14
"vcd_nsxt_alb_virtual_service_http_sec_rules": datasourceVcdAlbVirtualServiceSecRules(), // 3.14

"vcd_tm_region_storage_policy": datasourceVcdTmRegionStoragePolicy(), // 4.0
"vcd_tm_content_library": datasourceVcdTmContentLibrary(), // 4.0
}

var globalResourceMap = map[string]*schema.Resource{
Expand Down Expand Up @@ -301,6 +304,8 @@ var globalResourceMap = map[string]*schema.Resource{
"vcd_nsxt_alb_virtual_service_http_req_rules": resourceVcdAlbVirtualServiceReqRules(), // 3.14
"vcd_nsxt_alb_virtual_service_http_resp_rules": resourceVcdAlbVirtualServiceRespRules(), // 3.14
"vcd_nsxt_alb_virtual_service_http_sec_rules": resourceVcdAlbVirtualServiceSecRules(), // 3.14

"vcd_tm_content_library": resourceVcdTmContentLibrary(), // 4.0
}

// Provider returns a terraform.ResourceProvider.
Expand Down
2 changes: 1 addition & 1 deletion vcd/provider_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build api || functional || catalog || vapp || network || extnetwork || org || query || vm || vdc || gateway || disk || binary || lb || lbAppProfile || lbAppRule || lbServiceMonitor || lbServerPool || lbVirtualServer || user || access_control || standaloneVm || search || auth || nsxt || role || alb || certificate || vdcGroup || ldap || rde || uiPlugin || providerVdc || cse || slz || multisite || ALL
//go:build api || functional || catalog || vapp || network || extnetwork || org || query || vm || vdc || gateway || disk || binary || lb || lbAppProfile || lbAppRule || lbServiceMonitor || lbServerPool || lbVirtualServer || user || access_control || standaloneVm || search || auth || nsxt || role || alb || certificate || vdcGroup || ldap || rde || uiPlugin || providerVdc || cse || slz || multisite || tm || ALL

package vcd

Expand Down
5 changes: 5 additions & 0 deletions vcd/remove_leftovers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func removeLeftovers(govcdClient *govcd.VCDClient, verbose bool) error {
fmt.Printf("Start leftovers removal\n")
}

if govcdClient.Client.IsTm() {
fmt.Printf("Skipping leftover removal for TM\n")
return nil
}

// NSX-T ALB configuration Hierarchical cleanup is separate from main hierarchy as even if the
// Org is going to be deleted - NSX-T ALB configuration must be cleaned up first
// Only System user can control ALB resources
Expand Down
Loading

0 comments on commit 9334ae8

Please sign in to comment.