Skip to content

Commit

Permalink
VPC resource changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SunithaGudisagarIBM1 committed Sep 3, 2024
1 parent 5b29c0a commit 5823af3
Show file tree
Hide file tree
Showing 10 changed files with 280 additions and 5 deletions.
8 changes: 8 additions & 0 deletions common/github.com/IBM/vpc-go-sdk/vpcv1/vpc_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -88080,6 +88080,9 @@ type VPC struct {
// The name for this VPC. The name is unique across all VPCs in the region.
Name *string `json:"name" validate:"required"`

// The public address ranges attached to this VPC.
PublicAddressRanges []PublicAddressRangeReference `json:"public_address_ranges" validate:"required"`

// The resource group for this VPC.
ResourceGroup *ResourceGroupReference `json:"resource_group" validate:"required"`

Expand Down Expand Up @@ -88188,6 +88191,11 @@ func UnmarshalVPC(m map[string]json.RawMessage, result interface{}) (err error)
err = core.SDKErrorf(err, "", "name-error", common.GetComponentInfo())
return
}
err = core.UnmarshalModel(m, "public_address_ranges", &obj.PublicAddressRanges, UnmarshalPublicAddressRangeReference)
if err != nil {
err = core.SDKErrorf(err, "", "public_address_ranges-error", common.GetComponentInfo())
return
}
err = core.UnmarshalModel(m, "resource_group", &obj.ResourceGroup, UnmarshalResourceGroupReference)
if err != nil {
err = core.SDKErrorf(err, "", "resource_group-error", common.GetComponentInfo())
Expand Down
84 changes: 84 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,54 @@ func DataSourceIBMISVPC() *schema.Resource {
},
},
},
"public_address_ranges": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The public address ranges attached to this VPC.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"crn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this public address range.",
},
"deleted": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "If present, this property indicates the referenced resource has been deleted, and providessome supplementary information.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"more_info": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about deleted resources.",
},
},
},
},
"href": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this public address range.",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this public address range.",
},
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The name for this public address range. The name is unique across all public address ranges in the region.",
},
"resource_type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The resource type.",
},
},
},
},
},
}
}
Expand Down Expand Up @@ -581,6 +629,20 @@ func setVpcDetails(d *schema.ResourceData, vpc *vpcv1.VPC, meta interface{}, ses
} else {
d.Set(isVPCDefaultSecurityGroup, nil)
}

publicAddressRanges := []map[string]interface{}{}
if vpc.PublicAddressRanges != nil {
for _, modelItem := range vpc.PublicAddressRanges {
modelMap, err := DataSourceIBMIsVPCPublicAddressRangeReferenceToMap(&modelItem)
if err != nil {
log.Printf(
"An error occured during reading of vpc (%s) public address range : %s", d.Id(), err)
}
publicAddressRanges = append(publicAddressRanges, modelMap)
}
}
d.Set("public_address_ranges", publicAddressRanges)

tags, err := flex.GetGlobalTagsUsingCRN(meta, *vpc.CRN, "", isVPCUserTagType)
if err != nil {
log.Printf(
Expand Down Expand Up @@ -1016,3 +1078,25 @@ func dataSourceIBMIsVPCRegionReferenceToMap(model *vpcv1.RegionReference) (map[s
modelMap["name"] = model.Name
return modelMap, nil
}

func DataSourceIBMIsVPCPublicAddressRangeReferenceToMap(model *vpcv1.PublicAddressRangeReference) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["crn"] = *model.CRN
if model.Deleted != nil {
deletedMap, err := DataSourceIBMIsVPCDeletedToMap(model.Deleted)
if err != nil {
return modelMap, err
}
modelMap["deleted"] = []map[string]interface{}{deletedMap}
}
modelMap["href"] = *model.Href
modelMap["id"] = *model.ID
modelMap["name"] = *model.Name
modelMap["resource_type"] = *model.ResourceType
return modelMap, nil
}
func DataSourceIBMIsVPCDeletedToMap(model *vpcv1.Deleted) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["more_info"] = *model.MoreInfo
return modelMap, nil
}
57 changes: 57 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_vpcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,54 @@ func DataSourceIBMISVPCs() *schema.Resource {
},
},
},
"public_address_ranges": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The public address ranges attached to this VPC.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"crn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this public address range.",
},
"deleted": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "If present, this property indicates the referenced resource has been deleted, and providessome supplementary information.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"more_info": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about deleted resources.",
},
},
},
},
"href": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this public address range.",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this public address range.",
},
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The name for this public address range. The name is unique across all public address ranges in the region.",
},
"resource_type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The resource type.",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -570,6 +618,15 @@ func dataSourceIBMISVPCListRead(context context.Context, d *schema.ResourceData,
l[isVPCDefaultSecurityGroupName] = *vpc.DefaultSecurityGroup.Name
l[isVPCDefaultSecurityGroupCRN] = vpc.DefaultSecurityGroup.CRN
}
publicAddressRanges := []map[string]interface{}{}
for _, publicAddressRangesItem := range vpc.PublicAddressRanges {
publicAddressRangesItemMap, err := DataSourceIBMIsVPCPublicAddressRangeReferenceToMap(&publicAddressRangesItem)
if err != nil {
return diag.FromErr(err)
}
publicAddressRanges = append(publicAddressRanges, publicAddressRangesItemMap)
}
l["public_address_ranges"] = publicAddressRanges
tags, err := flex.GetGlobalTagsUsingCRN(meta, *vpc.CRN, "", isVPCUserTagType)
if err != nil {
log.Printf(
Expand Down
84 changes: 84 additions & 0 deletions ibm/service/vpc/resource_ibm_is_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,54 @@ func ResourceIBMISVPC() *schema.Resource {
},
},
},
"public_address_ranges": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The public address ranges attached to this VPC.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"crn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this public address range.",
},
"deleted": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "If present, this property indicates the referenced resource has been deleted, and providessome supplementary information.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"more_info": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about deleted resources.",
},
},
},
},
"href": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this public address range.",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this public address range.",
},
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The name for this public address range. The name is unique across all public address ranges in the region.",
},
"resource_type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The resource type.",
},
},
},
},
},
}
}
Expand Down Expand Up @@ -1039,6 +1087,20 @@ func vpcGet(d *schema.ResourceData, meta interface{}, id string) error {
d.Set(isVPCResourceGroup, *vpc.ResourceGroup.ID)
d.Set(flex.ResourceGroupName, *vpc.ResourceGroup.Name)
}

//public address range
publicAddressRanges := []map[string]interface{}{}
for _, publicAddressRangesItem := range vpc.PublicAddressRanges {
publicAddressRangesItemMap, err := ResourceIBMIsVPCPublicAddressRangeReferenceToMap(&publicAddressRangesItem)
if err != nil {
return err
}
publicAddressRanges = append(publicAddressRanges, publicAddressRangesItemMap)
}
if err = d.Set("public_address_ranges", publicAddressRanges); err != nil {
return fmt.Errorf("Error setting public_address_ranges: %s", err)
}

//set the cse ip addresses info
if vpc.CseSourceIps != nil {
cseSourceIpsList := make([]map[string]interface{}, 0)
Expand Down Expand Up @@ -1875,3 +1937,25 @@ func resourceIBMIsVPCAccountReferenceToMap(model *vpcv1.AccountReference) (map[s
modelMap["resource_type"] = model.ResourceType
return modelMap, nil
}

func ResourceIBMIsVPCPublicAddressRangeReferenceToMap(model *vpcv1.PublicAddressRangeReference) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["crn"] = *model.CRN
if model.Deleted != nil {
deletedMap, err := ResourceIBMIsVPCDeletedToMap(model.Deleted)
if err != nil {
return modelMap, err
}
modelMap["deleted"] = []map[string]interface{}{deletedMap}
}
modelMap["href"] = *model.Href
modelMap["id"] = *model.ID
modelMap["name"] = *model.Name
modelMap["resource_type"] = *model.ResourceType
return modelMap, nil
}
func ResourceIBMIsVPCDeletedToMap(model *vpcv1.Deleted) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["more_info"] = *model.MoreInfo
return modelMap, nil
}
2 changes: 1 addition & 1 deletion website/docs/d/is_public_address_range.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ After your data source is created, you can read values from the following attrib
- `id` - (String) The unique identifier for this resource group.
- `name` - (String) The name for this resource group.
- `resource_type` - (String) The resource type.
- `target` - (List) The target this public address range is bound to.If absent, this pubic address range is not bound to a target.
- `target` - (List) The target this public address range is bound to.If absent, this public address range is not bound to a target.
Nested schema for **target**:
- `vpc` - (List) The VPC this public address range is bound to.
Nested schema for **vpc**:
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/is_public_address_ranges.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ After your data source is created, you can read values from the following attrib
- `id` - (String) The unique identifier for this resource group.
- `name` - (String) The name for this resource group.
- `resource_type` - (String) The resource type.
- `target` - (List) The target this public address range is bound to.If absent, this pubic address range is not bound to a target.
- `target` - (List) The target this public address range is bound to.If absent, this public address range is not bound to a target.
Nested schema for **target**:
- `vpc` - (List) The VPC this public address range is bound to.
Nested schema for **vpc**:
Expand Down
10 changes: 10 additions & 0 deletions website/docs/d/is_vpc.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ In addition to all argument reference list, you can access the following attribu
- `more_info` - (String) Link to documentation about the reason for this health state.

- `health_state` - (String) The health of this resource.- `ok`: No abnormal behavior detected- `degraded`: Experiencing compromised performance, capacity, or connectivity- `faulted`: Completely unreachable, inoperative, or otherwise entirely incapacitated- `inapplicable`: The health state does not apply because of the current lifecycle state. A resource with a lifecycle state of `failed` or `deleting` will have a health state of `inapplicable`. A `pending` resource may also have this state.[`degraded`, `faulted`, `inapplicable`, `ok`]
- `public_address_ranges` - (List) The public address ranges attached to this VPC.
Nested schema for `public_address_ranges`:
- `crn` - (String) The CRN for this public address range.
- `deleted` - (List) If present, this property indicates the referenced resource has been deleted, and providessome supplementary information.
Nested schema for `deleted`:
- `more_info` - (String) Link to documentation about deleted resources.
- `href` - (String) The URL for this public address range.
- `id` - (String) The unique identifier for this public address range.
- `name` - (String) The name for this public address range. The name is unique across all public address ranges in the region.
- `resource_type` - (String) The resource type.
- `resource_group` - (String) The resource group ID where the VPC created.
- `security_group` - (String) A list of security groups attached to VPC. The nested security group block has the following structure:

Expand Down
10 changes: 10 additions & 0 deletions website/docs/d/is_vpcs.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ You can access the following attribute references after your data source is crea

- `id` - (String) The ID of the VPC.
- `name` - (String) The name of the VPC.
- `public_address_ranges` - (List) The public address ranges attached to this VPC.
Nested schema for `public_address_ranges`:
- `crn` - (String) The CRN for this public address range.
- `deleted` - (List) If present, this property indicates the referenced resource has been deleted, and providessome supplementary information.
Nested schema for `deleted`:
- `more_info` - (String) Link to documentation about deleted resources.
- `href` - (String) The URL for this public address range.
- `id` - (String) The unique identifier for this public address range.
- `name` - (String) The name for this public address range. The name is unique across all public address ranges in the region.
- `resource_type` - (String) The resource type.
- `resource_group` - (String) The resource group ID where the VPC created.
- `security_group` - (String) A list of security groups attached to VPC. The nested security group block has the following structure:

Expand Down
18 changes: 15 additions & 3 deletions website/docs/r/is_public_address_range.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ provider "ibm" {
```

## Example Usage
The following example shows how you can create a public gateway for all the subnets that are located in a specific zone.
The following example shows how you can create a public address range for a vpc that are located in a specific zone.

```terraform
resource "ibm_is_public_address_range" "public_address_range_instance" {
Expand All @@ -43,6 +43,18 @@ resource "ibm_is_public_address_range" "public_address_range_instance" {
}
```

An example shows how you can create public address range not attached to vpc and zone

```terraform
resource "ibm_is_public_address_range" "public_address_range_instance" {
ipv4_address_count = "16"
name = "example-public-address-range"
resource_group {
id = "11caaa983d9c4beb82690daab08717e9"
}
}
```

## Argument Reference

You can specify the following arguments for this resource.
Expand All @@ -52,7 +64,7 @@ You can specify the following arguments for this resource.
- `resource_group` - (Optional, List) The resource group for this public address range.
Nested schema for **resource_group**:
- `id` - (Required, String) The unique identifier for this resource group.
- `target` - (Optional, List) The target this public address range is bound to.If absent, this pubic address range is not bound to a target.
- `target` - (Optional, List) The target this public address range is bound to.If absent, this public address range is not bound to a target.
Nested schema for `target`:
- `vpc` - (Required, List) The VPC this public address range is bound to. If present, any of the below value must be specified.
Nested schema for **vpc**:
Expand All @@ -79,7 +91,7 @@ In addition to all argument reference list, you can access the following attribu
- `href` - (String) The URL for this resource group.
- `id` - (String) The unique identifier for this resource group.
- `name` - (String) The name for this resource group.
- `target` - (List) The target this public address range is bound to.If absent, this pubic address range is not bound to a target.
- `target` - (List) The target this public address range is bound to.If absent, this public address range is not bound to a target.
Nested schema for **target**:
- `vpc` - (List) The VPC this public address range is bound to.
Nested schema for **vpc**:
Expand Down
Loading

0 comments on commit 5823af3

Please sign in to comment.