Skip to content
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

Fix VPC external address importer #1378

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions nsxt/policy_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func getOrGenerateID(d *schema.ResourceData, m interface{}, presenceChecker func
return id, nil
}

//lint:ignore U1000 Ignore unused function temporarily until used in autogenerated resource
func getOrGenerateIDWithParent(d *schema.ResourceData, m interface{}, presenceChecker func(utl.SessionContext, string, string, client.Connector) (bool, error)) (string, error) {
connector := getPolicyConnector(m)

Expand Down Expand Up @@ -440,7 +439,6 @@ func nsxtPolicyPathResourceImporterHelper(d *schema.ResourceData, m interface{})
return []*schema.ResourceData{d}, ErrNotAPolicyPath
}

//lint:ignore U1000 Ignore unused function temporarily until used in autogenerated resource
func nsxtParentPathResourceImporter(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
importID := d.Id()
if isSpaceString(importID) {
Expand Down Expand Up @@ -665,7 +663,6 @@ func getPolicyLbMonitorPortSchema() *schema.Schema {
}
}

//lint:ignore U1000 Ignore unused function temporarily until used in autogenerated resource
func getVpcParentsFromContext(context utl.SessionContext) []string {
return []string{utl.DefaultOrgID, context.ProjectID, context.VPCID}
}
16 changes: 15 additions & 1 deletion nsxt/resource_nsxt_vpc_external_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func resourceNsxtVpcExternalAddress() *schema.Resource {
Update: resourceNsxtVpcExternalAddressUpdate,
Delete: resourceNsxtVpcExternalAddressDelete,
Importer: &schema.ResourceImporter{
State: nsxtParentPathResourceImporter,
State: nsxtVpcExternalAddressImporter,
},
Schema: map[string]*schema.Schema{
"parent_path": getPolicyPathSchema(true, true, "port path for address binding"),
Expand Down Expand Up @@ -107,3 +107,17 @@ func resourceNsxtVpcExternalAddressUpdate(d *schema.ResourceData, m interface{})
func resourceNsxtVpcExternalAddressDelete(d *schema.ResourceData, m interface{}) error {
return updatePort(d, m, true)
}

func nsxtVpcExternalAddressImporter(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
importID := d.Id()
if isSpaceString(importID) {
return []*schema.ResourceData{d}, ErrEmptyImportID
}
if isPolicyPath(importID) {
// Since external address is part of Port API, parent path is the port URL
d.SetId(newUUID())
d.Set("parent_path", importID)
return []*schema.ResourceData{d}, nil
}
return []*schema.ResourceData{d}, ErrNotAPolicyPath
}
2 changes: 1 addition & 1 deletion website/docs/r/vpc_external_address.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ An existing VPC External Address Binding can be [imported][docs-import] into thi
terraform import nsxt_vpc_external_address.external_address1 PATH
```

The above command imports the VPC External Address Binding named `external_address` with the NSX Policy path `PATH`.
The above command imports the VPC External Address Binding named `external_address` with the NSX Policy path of the parent port `PATH`.
Loading