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

Support virtual endpoint gateway as target to subnet reserved IP #2521

Merged
merged 1 commit into from
Apr 27, 2021
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
12 changes: 12 additions & 0 deletions ibm/data_source_ibm_is_subnet_reserved_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package ibm
import (
"fmt"

"github.com/IBM/vpc-go-sdk/vpcv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -87,6 +88,11 @@ func dataSourceIBMISReservedIP() *schema.Resource {
Computed: true,
Description: "The resource type.",
},
isReservedIPTarget: {
Type: schema.TypeString,
Computed: true,
Description: "Reserved IP target id.",
},
},
}
}
Expand Down Expand Up @@ -116,5 +122,11 @@ func dataSdataSourceIBMISReservedIPRead(d *schema.ResourceData, meta interface{}
d.Set(isReservedIPName, *reserveIP.Name)
d.Set(isReservedIPOwner, *reserveIP.Owner)
d.Set(isReservedIPType, *reserveIP.ResourceType)
if reserveIP.Target != nil {
target, ok := reserveIP.Target.(*vpcv1.ReservedIPTarget)
if ok {
d.Set(isReservedIPTarget, target.ID)
}
}
return nil // By default there should be no error
}
10 changes: 9 additions & 1 deletion ibm/data_source_ibm_is_subnet_reserved_ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func dataSourceIBMISReservedIPs() *schema.Resource {
Computed: true,
Description: "The resource type.",
},
isReservedIPTarget: {
Type: schema.TypeString,
Computed: true,
Description: "Reserved IP target id",
},
},
},
},
Expand Down Expand Up @@ -140,7 +145,10 @@ func dataSdataSourceIBMISReservedIPsRead(d *schema.ResourceData, meta interface{
ipsOutput[isReservedIPName] = *data.Name
ipsOutput[isReservedIPOwner] = *data.Owner
ipsOutput[isReservedIPType] = *data.ResourceType

target, ok := data.Target.(*vpcv1.ReservedIPTarget)
if ok {
ipsOutput[isReservedIPTarget] = target.ID
}
reservedIPs = append(reservedIPs, ipsOutput)
}

Expand Down
20 changes: 19 additions & 1 deletion ibm/resource_ibm_is_subnet_reserved_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
isReservedIPProvisioning = "provisioning"
isReservedIPProvisioningDone = "done"
isReservedIP = "reserved_ip"
isReservedIPTarget = "target"
)

func resourceIBMISReservedIP() *schema.Resource {
Expand Down Expand Up @@ -56,6 +57,12 @@ func resourceIBMISReservedIP() *schema.Resource {
ValidateFunc: InvokeValidator("ibm_is_subnet_reserved_ip", isReservedIPName),
Description: "The user-defined or system-provided name for this reserved IP.",
},
isReservedIPTarget: {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "The unique identifier for target.",
},
/*
Response Parameters
===================
Expand Down Expand Up @@ -133,7 +140,12 @@ func resourceIBMISReservedIPCreate(d *schema.ResourceData, meta interface{}) err

autoDeleteBool := d.Get(isReservedIPAutoDelete).(bool)
options.AutoDelete = &autoDeleteBool

if t, ok := d.GetOk(isReservedIPTarget); ok {
targetId := t.(string)
options.Target = &vpcv1.ReservedIPTargetPrototype{
ID: &targetId,
}
}
rip, response, err := sess.CreateSubnetReservedIP(options)
if err != nil || response == nil || rip == nil {
return fmt.Errorf("Error creating the reserved IP: %s\n%s", err, response)
Expand Down Expand Up @@ -167,6 +179,12 @@ func resourceIBMISReservedIPRead(d *schema.ResourceData, meta interface{}) error
d.Set(isReservedIPName, *rip.Name)
d.Set(isReservedIPOwner, *rip.Owner)
d.Set(isReservedIPType, *rip.ResourceType)
if rip.Target != nil {
target, ok := rip.Target.(*vpcv1.ReservedIPTarget)
if ok {
d.Set(isReservedIPTarget, target.ID)
}
}
}
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions ibm/resource_ibm_is_subnet_reserved_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,19 @@ func testAccCheckISSubnetReservedIPConfigBasic(vpcName, subnetName, resIPName st
total_ipv4_address_count = 256
}

resource "ibm_is_virtual_endpoint_gateway" "endpoint_gateway" {
name = "my-endpoint-gateway-1"
target {
name = "ibm-ntp-server"
resource_type = "provider_infrastructure_service"
}
vpc = ibm_is_vpc.vpc1.id
}

resource "ibm_is_subnet_reserved_ip" "resIP1" {
subnet = ibm_is_subnet.subnet1.id
name = "%s"
target = ibm_is_virtual_endpoint_gateway.endpoint_gateway.id
}
`, vpcName, subnetName, resIPName)
}
1 change: 1 addition & 0 deletions website/docs/d/is_subnet_reserved_ip.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ The following attributes are exported as output/response:
* `reserved_ip` - Same as `id`
* `resource_type` - The type of resource
* `subnet` - The id for the subnet for the reserved IP
* `target` - The id for the target for the reserved IP
3 changes: 2 additions & 1 deletion website/docs/d/is_subnet_reserved_ips.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ The following attributes are exported as output/response:
- `name` - The user-defined or system-provided name for this reserved IP
- `owner` - The owner of a reserved IP, defining whether it is managed by the user or the provider
- `resource_type` - The resource type

- `target` - The id for the target for the reserved IP.

* `sort` - The keyword on which all the reserved IPs are sorted
* `subnet` - The id for the subnet for the reserved IP
* `total_count` - The number of reserved IP in the subnet
21 changes: 19 additions & 2 deletions website/docs/r/is_subnet_reserved_ip.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ In the following example, you can create a Reserved IP:
// Subnet ID with a given name
resource "ibm_is_subnet_reserved_ip" "res_ip_name" {
subnet = ibm_is_subnet.subnet1.id
name = "my-subnet"
name = "my-subnet-reserved-ip"
}

// Subnet ID with auto_delete
Expand All @@ -50,9 +50,24 @@ In the following example, you can create a Reserved IP:
// Subnet ID with both name and auto_delete
resource "ibm_is_subnet_reserved_ip" "res_ip_auto_delete_name" {
subnet = ibm_is_subnet.subnet1.id
name = "my-subnet"
name = "my-subnet-reserved-ip"
auto_delete = true
}

// Create a virtual endpoint gateway and set as a target for reserved IP
resource "ibm_is_virtual_endpoint_gateway" "endpoint_gateway" {
name = "my-endpoint-gateway-1"
target {
name = "ibm-ntp-server"
resource_type = "provider_infrastructure_service"
}
vpc = ibm_is_vpc.vpc1.id
}
resource "ibm_is_subnet_reserved_ip" "reserved_ip_1" {
subnet = ibm_is_subnet.subnet1.id
name = "%s"
target = ibm_is_virtual_endpoint_gateway.endpoint_gateway.id
}
```

## Argument Reference
Expand All @@ -63,6 +78,7 @@ The following arguments are supported:
* `name` - (Optional, string) The name of the reserved IP.
**NOTE**: Raise error if name is given with a prefix `ibm-`.
* `auto_delete` - (Optional, boolean) If reserved IP is auto deleted.
* `target` - The id for the target endpoint gateway for the reserved IP.


## Attribure Reference
Expand All @@ -74,6 +90,7 @@ The following arguments are supported:
* `owner` - The owner of a reserved IP, defining whether it is managed by the user or the provider.
* `resource_type` - The resource type.
* `address` - The IP address.
* `target` - The id for the target endpoint gateway for the reserved IP.

## Import

Expand Down