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

Terraform Support for Managing Reserved IP Addresses #1598

Open
wants to merge 21 commits into
base: dev
Choose a base branch
from

Conversation

AniJ98
Copy link
Contributor

@AniJ98 AniJ98 commented Sep 26, 2024

📝 Description

This PR introduces comprehensive functionality and tests for Reserved IP Addresses in the terraform provider. The changes are necessary to provide robust support for managing Reserved IP addresses through terraform. The changes include:

Implementation of core Reserved IP operations:

  • Listing Reserved IPs
  • Getting a specific Reserved IP
  • Reserving a new IP
  • Deleting a Reserved IP

Test coverage:

  • Resource test - Covers testing the functionality of reserving and deleting a reserved IP Address
  • Datasource test - Covers testing the functionality of listing all reserved IP addresses and fetching a particular reserved IP Address.

✔️ How to Test

What are the steps to reproduce the issue or verify the changes?

  1. Ensure you have a valid Linode API token.
Set up your environment:


    export LINODE_TOKEN="your_token_here"


  2. To run only Reserved IP related tests:


    make int-test PKG_NAME="linode/networkreservedips"

To run a specific test:

  make int-test PKG_NAME="linode/networkreservedips" ARGS="-run TestAccDataSource_reservedIP"
  1. Verify the test output for any failures or unexpected behavior.

Note:

Ensure you have proper permissions and sufficient quota in your Linode account to perform Reserved IP operations. Some tests may create and delete resources, so use a testing environment if possible. This test expects the account to have 0 prior reservations.

@AniJ98 AniJ98 requested a review from a team as a code owner September 26, 2024 15:15
@AniJ98 AniJ98 requested review from zliang-akamai and yec-akamai and removed request for a team September 26, 2024 15:15
go.mod Outdated Show resolved Hide resolved
Copy link
Contributor

@yec-akamai yec-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your hard work on the IP reserve resource and data source. I left some suggestions to build this resource better:

linode/networkreservedips/framework_datasource.go Outdated Show resolved Hide resolved
linode/networkreservedips/framework_datasource.go Outdated Show resolved Hide resolved
linode/networkreservedips/framework_datasource.go Outdated Show resolved Hide resolved
linode/networkreservedips/framework_datasource_schema.go Outdated Show resolved Hide resolved
linode/networkreservedips/framework_datasource_schema.go Outdated Show resolved Hide resolved
linode/networkreservedips/framework_models.go Outdated Show resolved Hide resolved
linode/networkreservedips/resource_test.go Outdated Show resolved Hide resolved
linode/networkreservedips/resource_test.go Outdated Show resolved Hide resolved
linode/networkreservedips/resource_test.go Outdated Show resolved Hide resolved
linode/networkreservedips/tmpl/reserved_ip.gotf Outdated Show resolved Hide resolved
Comment on lines 22 to 70
var frameworkDataSourceFetchSchema = schema.Schema{
Attributes: map[string]schema.Attribute{
"region": schema.StringAttribute{
Description: "The Region in which to reserve the IP address.",
Optional: true,
},
"address": schema.StringAttribute{
Description: "The reserved IP address.",
Computed: true,
Optional: true,
},
"gateway": schema.StringAttribute{
Description: "The default gateway for this address.",
Computed: true,
},
"subnet_mask": schema.StringAttribute{
Description: "The mask that separates host bits from network bits for this address.",
Computed: true,
},
"prefix": schema.Int64Attribute{
Description: "The number of bits set in the subnet mask.",
Computed: true,
},
"type": schema.StringAttribute{
Description: "The type of address this is (ipv4, ipv6, ipv6/pool, ipv6/range).",
Computed: true,
},
"public": schema.BoolAttribute{
Description: "Whether this is a public or private IP address.",
Computed: true,
},
"rdns": schema.StringAttribute{
Description: "The reverse DNS assigned to this address.",
Computed: true,
},
"linode_id": schema.Int64Attribute{
Description: "The ID of the Linode this address currently belongs to.",
Computed: true,
},
"reserved": schema.BoolAttribute{
Description: "Whether this IP is reserved or not.",
Computed: true,
},
"id": schema.StringAttribute{
Description: "The unique ID of the reserved IP address.",
Computed: true,
},
},
}
Copy link
Member

@zliang-akamai zliang-akamai Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what's the required attribute for the data source? Maybe address?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah address should be a required attribute here. I will make that change now. Thanks!

Comment on lines 8 to 20
type ReservedIPObject struct {
ID types.String `tfsdk:"id"`
Address types.String `tfsdk:"address"`
Region types.String `tfsdk:"region"`
Gateway types.String `tfsdk:"gateway"`
SubnetMask types.String `tfsdk:"subnet_mask"`
Prefix types.Int64 `tfsdk:"prefix"`
Type types.String `tfsdk:"type"`
Public types.Bool `tfsdk:"public"`
RDNS types.String `tfsdk:"rdns"`
LinodeID types.Int64 `tfsdk:"linode_id"`
Reserved types.Bool `tfsdk:"reserved"`
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this struct used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! I must have forgotten to remove this before pushing. I have removed it now.

@zliang-akamai
Copy link
Member

I think a data source in TF is usually used to obtain information about a cloud resource (not necessarily a TF resource) with a given ID or attributes that are sufficient for identifying the resource on the cloud. Is that what you would like to implement here for data sources?

@zliang-akamai zliang-akamai requested review from a team, zliang-akamai, ezilber-akamai, jriddle-linode and lgarber-akamai and removed request for a team November 13, 2024 07:44
return &DataSource{
BaseDataSource: helper.NewBaseDataSource(
helper.BaseDataSourceConfig{
Name: "linode_reserved_ip_fetch",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name this data source linode_reserved_ip?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that removes the unnecessary long resource names. Will make the change.

return &DataSourceList{
BaseDataSource: helper.NewBaseDataSource(
helper.BaseDataSourceConfig{
Name: "linode_reserved_ip_list",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name this linode_reserved_ips?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can! I think this is more appropriate. I will be making this change

}

reservedIPs := make([]ReservedIPObject, len(ips))
for i, ip := range ips {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is vpc_nat_1_1 missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the schema of the closest existing resource - linode_networking_ip. We can still add this. Is it always null for reserved IPs? I see that when I reserve an IP address the vpc_nat_1_1 value is null. Need further clarification.

"github.com/hashicorp/terraform-plugin-framework/types"
)

type ReservedIPObject struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing vpc_nat_1_1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the schema of the closest existing resource - linode_networking_ip. We can still add this. Is it always null for reserved IPs? I see that when I reserve an IP address the vpc_nat_1_1 value is null. Need further clarification.

"github.com/linode/terraform-provider-linode/v2/linode/helper"
)

type ReservedIPModel struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we missing the ability to filter by fields? (If so, can be a follow up PR, probably)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filtering on region makes sense. I will be implementing the filter ability now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants