Skip to content

Commit

Permalink
Fix VPC external address importer
Browse files Browse the repository at this point in the history
In addition, remove unnecessary linter ignore comments

Signed-off-by: Anna Khmelnitsky <[email protected]>
  • Loading branch information
annakhm committed Sep 23, 2024
1 parent c77e287 commit b8e0c44
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
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`.

0 comments on commit b8e0c44

Please sign in to comment.