-
Notifications
You must be signed in to change notification settings - Fork 6
vcfa_provider_gateway + vcfa_tier0_gateway #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1deefc3
vcfa_ip_space
Didainius d4ebd88
Self review
Didainius be4286a
Add IP Space locking mechanism
Didainius 11cad5b
Remove comment field
Didainius a8a7d6c
vcdMutexKv to vcfaMutexKv
Didainius 4b9add7
WIP
Didainius b2bfaec
Changelog
Didainius 4a99fa5
update resource index
Didainius 7ceddd5
Merge main
Didainius 4a8a884
Add missing test helper for IP Spaces
Didainius 86f9222
Add extra sleep after vCenter ops
Didainius 5c796f7
Name tuning
Didainius 658da22
Patch TestAccDataSourceNotFound/vcfa_tier0_gateway
Didainius 0cf9484
Handle broken provider gateway resoruce creation and tainted recovery
Didainius 858c4a3
Bump govcd
Didainius 1cc19a2
Apply comments
Didainius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| * **New Resource:** `vcfa_provider_gateway` to manage TM Provider Gateways [GH-10] | ||
| * **New Data Source:** `vcfa_provider_gateway` to read IP Spaces [GH-10] | ||
| * **New Data Source:** `vcfa_tier0_gateway` to read available Tier 0 Gateways in NSX-T [GH-10] | ||
Didainius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package vcfa | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
| "github.com/vmware/go-vcloud-director/v3/govcd" | ||
| "github.com/vmware/go-vcloud-director/v3/types/v56" | ||
| ) | ||
|
|
||
| func datasourceVcfaProviderGateway() *schema.Resource { | ||
| return &schema.Resource{ | ||
| ReadContext: datasourceVcfaProviderGatewayRead, | ||
|
|
||
| Schema: map[string]*schema.Schema{ | ||
| "name": { | ||
| Type: schema.TypeString, | ||
| Required: true, | ||
| Description: fmt.Sprintf("Name of %s", labelVcfaProviderGateway), | ||
| }, | ||
| "region_id": { | ||
| Type: schema.TypeString, | ||
| Required: true, | ||
| Description: fmt.Sprintf("Parent %s of %s", labelVcfaRegion, labelVcfaProviderGateway), | ||
| }, | ||
| "description": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: fmt.Sprintf("Description of %s", labelVcfaProviderGateway), | ||
| }, | ||
| "nsxt_tier0_gateway_id": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: fmt.Sprintf("Parent %s of %s", labelVcfaTier0Gateway, labelVcfaProviderGateway), | ||
| }, | ||
| "ip_space_ids": { | ||
| Type: schema.TypeSet, | ||
| Computed: true, | ||
| Description: fmt.Sprintf("A set of supervisor IDs used in this %s", labelVcfaRegion), | ||
| Elem: &schema.Schema{ | ||
| Type: schema.TypeString, | ||
| }, | ||
| }, | ||
| "status": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: fmt.Sprintf("Status of %s", labelVcfaProviderGateway), | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func datasourceVcfaProviderGatewayRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
| vcdClient := meta.(*VCDClient) | ||
| getProviderGateway := func(name string) (*govcd.TmProviderGateway, error) { | ||
| return vcdClient.GetTmProviderGatewayByNameAndRegionId(name, d.Get("region_id").(string)) | ||
| } | ||
| c := dsReadConfig[*govcd.TmProviderGateway, types.TmProviderGateway]{ | ||
| entityLabel: labelVcfaProviderGateway, | ||
| getEntityFunc: getProviderGateway, | ||
| stateStoreFunc: setProviderGatewayData, | ||
| } | ||
| return readDatasource(ctx, d, meta, c) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package vcfa | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
| "github.com/vmware/go-vcloud-director/v3/govcd" | ||
| "github.com/vmware/go-vcloud-director/v3/types/v56" | ||
| ) | ||
|
|
||
| const labelVcfaTier0Gateway = "Tier 0 Gateway" | ||
|
|
||
| func datasourceVcfaTier0Gateway() *schema.Resource { | ||
| return &schema.Resource{ | ||
| ReadContext: datasourceVcfaTier0GatewayRead, | ||
|
|
||
| Schema: map[string]*schema.Schema{ | ||
| "name": { | ||
| Type: schema.TypeString, | ||
| Required: true, | ||
| Description: fmt.Sprintf("Display Name of %s", labelVcfaTier0Gateway), | ||
| }, | ||
| "region_id": { | ||
| Type: schema.TypeString, | ||
| Required: true, | ||
| Description: fmt.Sprintf("Parent %s ID", labelVcfaRegion), | ||
| }, | ||
| "description": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: fmt.Sprintf("Description of %s", labelVcfaTier0Gateway), | ||
| }, | ||
| "parent_tier_0_id": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: fmt.Sprintf("Parent Tier 0 Gateway of %s", labelVcfaTier0Gateway), | ||
Didainius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| "already_imported": { | ||
| Type: schema.TypeBool, | ||
| Computed: true, | ||
| Description: fmt.Sprintf("Defines if the T0 is already imported of %s", labelVcfaTier0Gateway), | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func datasourceVcfaTier0GatewayRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
| vcdClient := meta.(*VCDClient) | ||
| // Fetching the region to conform to standard of returning 'ErrorEntityNotFound', because the API behind | ||
| // GetTmTier0GatewayWithContextByName does not handle it well | ||
| region, err := vcdClient.GetRegionById(d.Get("region_id").(string)) | ||
| if err != nil { | ||
| return diag.Errorf("no region with ID '%s' found: %s", d.Get("region_id").(string), err) | ||
| } | ||
|
|
||
| getT0ByName := func(name string) (*govcd.TmTier0Gateway, error) { | ||
| return vcdClient.GetTmTier0GatewayWithContextByName(name, region.Region.ID, true) | ||
| } | ||
|
|
||
| c := dsReadConfig[*govcd.TmTier0Gateway, types.TmTier0Gateway]{ | ||
| entityLabel: labelVcfaTier0Gateway, | ||
| getEntityFunc: getT0ByName, | ||
| stateStoreFunc: setTier0GatewayData, | ||
| } | ||
| return readDatasource(ctx, d, meta, c) | ||
| } | ||
|
|
||
| func setTier0GatewayData(_ *VCDClient, d *schema.ResourceData, t *govcd.TmTier0Gateway) error { | ||
| d.SetId(t.TmTier0Gateway.ID) // So far the API returns plain UUID (not URN) | ||
| dSet(d, "name", t.TmTier0Gateway.DisplayName) | ||
| dSet(d, "description", t.TmTier0Gateway.Description) | ||
| dSet(d, "parent_tier_0_id", t.TmTier0Gateway.ParentTier0ID) | ||
| dSet(d, "already_imported", t.TmTier0Gateway.AlreadyImported) | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.