-
Notifications
You must be signed in to change notification settings - Fork 26
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
Feature subnet #156
Closed
Closed
Feature subnet #156
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
86b1cc0
Initial implementation of subnet resource.
minsikl 936a6fc
Updated attribute names for subnet.
minsikl 2cd5637
Changed network to optional attribute.
minsikl d954fbb
Added subnet_test.
minsikl 54ea415
Added doc for subnet resource.
minsikl 0c5ff3c
Added IPv6 support for subnet resource.
minsikl cfc94e7
Fixed capacity information for ipv6 on subnet resource.
minsikl 894f6b9
Checked activeTransaction for subnet provisioning.
minsikl c470697
Updated attributes for softlayer_subnet.
minsikl fb09e1e
Updated the doc for subnet.
minsikl da3490a
Updated the name of subnet_cidr attribute.
minsikl bcb7e55
Checked the subnet type strictly.
minsikl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#### `softlayer_subnet` | ||
|
||
`softlayer_subnet` provides portable and static subnets that consist of either IPv4 and IPv6 addresses. Users are able to create | ||
public portable subnets, private portable subnets, and public static subnets with an IPv4 option and public portable subnets and public static | ||
subnets with an IPv6 option. | ||
|
||
The portable IPv4 subnet is created as a seconday subnet on a VLAN. IP addresses in the portable subnet can be assigned as secondary IP | ||
addresses for SoftLayer resources in the VLAN. Each portable subnet has a default gateway IP address, network IP address, and broadcast | ||
IP address. For example, if a portable subnet is `10.0.0.0/30`, `10.0.0.0` is a network IP address, `10.0.0.1` is a default gateway IP address, | ||
and `10.0.0.3` is a broadcast IP address. Therefore, only `10.0.0.2` can be assigned to SoftLayer resources as a secondary IP address. | ||
Number of usuable IP addresses is `capacity` - 3. If `capacity` is 4, the number of usuable IP addresses is 4 - 3 = 1. If `capacity` is 8, the | ||
number of usuable IP addresses is 8 - 3 = 5. For additional details, refer to [Static and Portable IP blocks](https://knowledgelayer.softlayer.com/articles/static-and-portable-ip-blocks). | ||
|
||
The static IPv4 subnet provides secondary IP addresses for primary IP addresses. It provides secondary IP addresses for SoftLayer resources such as | ||
virtual servers, bare metal servers, and netscaler VPXs. Suppose that a virtual server requires secondary IP addresses. Then, users can create | ||
a static subnet on the public IP address of the virtual server. Unlike the portable subnet, `capacity` is same with a number of usuable IP address. | ||
For example, if a static subnet is `10.0.0.0/30`, `capacity` is 4 and four IP addresses(10.0.0.0 ~ 10.0.0.3) can be used as secondary IP addresses. | ||
For additional details, refer to [Subnet](https://knowledgelayer.softlayer.com/topic/subnets). | ||
|
||
Both the public portable IPv6 subnet and the public static IP only accept `64` as a value of `capacity` attribute. They provide 2^64 IP addresses. For additional detail, refer to [IPv6 address](http://blog.softlayer.com/tag/ipv6) | ||
|
||
The following example will create a private portable subnet which has one available IPv4 address. | ||
##### Example Usage of portable subnet | ||
|
||
```hcl | ||
# Create a new portable subnet | ||
resource "softlayer_subnet" "portable_subnet" { | ||
type = "Portable" | ||
network = "PRIVATE" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same with the type of network. if there can only be two types, public and private, then make it a boolean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
ip_version = 4 | ||
capacity = 4 | ||
vlan_id = 1234567 | ||
notes = "portable_subnet" | ||
} | ||
``` | ||
|
||
The following example will create a public static subnet which has four available IPv4 address. | ||
##### Example Usage of static subnet | ||
|
||
```hcl | ||
# Create a new static subnet | ||
resource "softlayer_subnet" "static_subnet" { | ||
type = "Static" | ||
network = "PUBLIC" | ||
ip_version = 4 | ||
capacity = 4 | ||
endpoint_ip="151.1.1.1" | ||
notes = "static_subnet_updated" | ||
} | ||
``` | ||
|
||
Sometimes, users need to get IP addresses on a subnet. Terraform built-in functions can be used to get IP addresses from `subnet`. | ||
The following example returns first IP address in the subnet `test`: | ||
```hcl | ||
resource "softlayer_subnet" "test" { | ||
type = "Static" | ||
network = "PUBLIC" | ||
ip_version = 4 | ||
capacity = 4 | ||
endpoint_ip="159.8.181.82" | ||
} | ||
|
||
# Use a built-in function cidrhost with index 0. | ||
output "first_ip_address" { | ||
value = "${cidrhost(softlayer_subnet.test.subnet,0)}" | ||
} | ||
``` | ||
|
||
##### Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `network` | *string* | ||
* Set the network property of the subnet if it is public or private. Accepted values are PRIVATE and PUBLIC. | ||
* **Required** | ||
* `type` | *string* | ||
* Set the type of the subnet. Accepted values are Portable and Static. | ||
* **Required** | ||
* `ip_version` | *int* | ||
* Set the IP version of the subnet. Accepted values are 4 and 6. | ||
* **Required** | ||
* `capacity` | *int* | ||
* Set the size of the subnet. | ||
* Accepted values for a public portable IPv4 subnet are 4, 8, 16, and 32. | ||
* Accepted values for a private portable IPv4 subnet are 4, 8, 16, 32, and 64. | ||
* Accepted values for a public static IPv4 subnet are 1, 2, 4, 8, 16, and 32. | ||
* Accepted value for a public portable IPv6 subnet is 64. /64 block is created and 2^64 IP addresses are provided. | ||
* Accepted value for a public static IPv6 subnet is 64. /64 block is created and 2^64 IP addresses are provided. | ||
* **Required** | ||
* `vlan_id` | *int* | ||
* VLAN id for portable subnet. It should be configured when the subnet is a portable subnet. Both public VLAN ID and private VLAN ID can | ||
be configured. Accepted values can be found [here](https://control.softlayer.com/network/vlans). Click on the desired VLAN and note the | ||
ID on the resulting URL. Or, you can also [refer to a VLAN by name using a data source](https://github.com/softlayer/terraform-provider-softlayer/blob/master/docs/datasources/softlayer_vlan.md). | ||
* **Optional** | ||
* `endpoint_ip` | *string* | ||
* Target primary IP address for static subnet. It should be configured when the subnet is a static subnet. Only public IP address can be | ||
configured as a `endpoint_ip`. It can be public IP address of virtual servers, bare metal servers, and netscaler VPXs. `static subnet` will | ||
be created on VLAN where `endpoint_ip` is located in. | ||
* **Optional** | ||
* `notes` | *string* | ||
* Set comments for the subnet. | ||
* **Optional** | ||
|
||
##### Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `id` - id of the subnet. | ||
* `subnet` - It rovides IP address/netmask format (ex. 10.10.10.10/28). It can be used to get an available IP address in `subnet`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there can only be two types, portable or static, make it a boolean then
portable = true
orstatic = true
to avoid possible spelling errors. If it is not portable, then it is static and vice-versa.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SoftLayer internally uses some subnet types:
PRIMARY, ADDITIONAL_PRIMARY, SECONDARY, ROUTED_TO_VLAN, SECONDARY_ON_VLAN, STORAGE_NETWORK, and STATIC_IP_ROUTED
. From an end user perspective, the types can be simplified to:Primary, Static, Portable, and Global
. We can ignore Global type becausesoftlayer_global_ip
is already provided. As of now,softlayer_subnet
only supportsStatic
andPortable
because Primary subnet cannot be ordered manually. However, I think that Primary subnet ordering will be supported in the future. Then, we can extend this resource without schema update.softlayer_subnet
data source also can be added later. Unlikesoftlayer_subnet
resource, the data source may supportsPrimary, Portable, Static
. In this case, we can use the same attribute nametype
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@minsikl ok, in that case, why not use the same type strings as the SL API? What would
static
map to?STATIC_IP_ROUTED
? What aboutportable
?The point is, if we can't make it fool-proof with booleans because there could be more than two types, then let's go with the raw API type names and then we can point there for the list of allowed types and spelling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@renier The initial code used
ROUTED_TO_VLAN
for portable subnets andSTATIC_IP_ROUTED
for static subnets. The subnet type can be retrieved usingSoftLayer_Network_Subnet ::subnetType
. However, I realized that SL API returns additional types such asSECONDARY_ON_VLAN
,SUBNET_ON_VLAN
, andSTATIC_IP_ROUTED
. After IPv6 feature is added, I got additional types such asSTATIC_IP6_ROUTED
. The raw subnet type is not an input parameter of a create function and I'm not able to guess which type will be returned from SL API. In end-user perspective, these raw types are meaningless and SL Portal uses terminologyPortable
,Static
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we go with the portal or with the API? is the question.
If we go with the portal names, it would be good to at least document what that means in API types.
What kinds of subnets can you create then? and how do you specify the kind upon creation? (over the API)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I explained that primary subnet and portable subnet has the same attributes. How will you distinguish the primary subnet if you don't have type attribute?
primary = true
is okay. But, what isprimary = false
? Is that mean that the subnet will beglobal
,secondary
,third
, orportable
? Will you add an attribute per types such asstatic = true
andsecondary = true
?primary
is one of subnet types. If you usetype
attribute, you don't have to add additional true/false attributes to support different types. Why do you use true/false for type names?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can a user order a primary subnet today? If not, then I stand by that we should not add a required pseudo-attribute based on something that has not happened in the API yet. We don't have enough information on how to handle until it actually does. Does this make sense?
Is it that we know that orderable primary subnets is in the works and we expect that to be available any moment now? If so, do we know exactly how the ordering of a primary subnet will look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@renier
softlayer_vlan
already provides a function to create the first primary subnet. When you create a new VLAN using terraform, you should define the size of the first primary subnet. Then,placeOrder
insoftlayer_vlan
resource sends priceId of VLAN and priceId of the primary subnet and creates a new VLAN with a primary subnet. So, primary subnets ordering requires same information with portable subnets ordering.Subnet types are not pseudo-attributes. price item key names contain them, SL portal, automatic tickets, and knowledgelayer use them. Only SL API provides it's internal subnet types.
Boolean attributes should be only used when SL API provides boolean properties or the attributes are optional values such as
advanced monitering
orredundant power supply
. Or they will be pseudo-attributes, and it's hard to understand the meaning.I defined a general
softlayer_subnet
resource and it is a pseudo resource. That's why thetype
attribute is important insoftlayer_subnet
resource.type
is added to define a real resource type of subnets. In the later, if a new attribute is added to describe a new subnet type such asprimary=true/false
,primary
andtype
will provide duplicated information, and I don't think that it is a good design. Currentsoftlayer_subnet
only supports parts of SL subnet types. At least, we need to provide extensible schema if we want to usesoftlayer_subnet
.If you don't want to use
type
attribute, let's just define separate resourcessoftlayer_portable_subnet
andsoftlayer_static_subnet
. There is no advantage to usingsoftlayer_subnet
and ifsoftlayer_subnet
is provided withouttype
, it will just make confusion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's good to know and understand. I had not made the link between the vlan and the primary subnet. Why were you thinking that
primary
could be an additional type tosoftlayer_subnet
, when it is already being provided bysoftlayer_vlan
?In this case, the type is an attribute that is not synced with the API and is only managed locally. Thus, it is a pseudo-attribute of the resource by definition. Just as any boolean flags in other resources that are also only managed locally. The most common pseudo-attributes are booleans, because you usually don't need to make those kinds of attributes more complex and should not if possible.
Based on my definition above, a pseudo-resource would be something that is not sync-ed with the cloud and it would be managed completely locally. For example, the random provider in terraform only has pseudo-resources. It follows that
softlayer_subnet
is not a pseudo-resource.It doesn't have to be confusing if we document that portable subnets are created when you fill out the vlan_id, otherwise if you provide the endpoint_ip, it is static. Even less if you provide a documented computed attribute to the resource computing this fact for them as a word (portable or static).
Creating multiple resources, one per subnet type, is also an option, as long as 99% of the code is shared among them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave you the primary subnet provisioning example as an answer to your question:
Can a user order a primary subnet today? If not, then I stand by that we should not add a required pseudo-attribute based on something that has not happened in the API yet. We don't have enough information on how to handle until it actually does.
. You can see thatprimary subnet
requires same attributes withportable subnet
when you create a newprimary subnet
.If you get a chance to deploy middle/large size systems or some cluster solutions on SoftLayer, you will find several
primary subnet
requirements which are not provided in SoftLayer. You can only create the first primary subnet as I explained above. You are not able to create 2nd/3rd primary subnets with a specific CIDR. Some cluster solutions require specific CIDR and some users want to reserve primary subnets in their VLAN for their firewall rules or applications.primary subnet
,portable subnet
,static subnet
, andglobal subnet
are combinations of interface and routing commands on physical routers and switches.subnet
is a general network terminology which provides IP range and CIDR information. But,primary subnet
,portable subnet
,static subnet
, andglobal subnet
are not general terminologies and only used in SoftLayer. They are offering names and you can create and manage them on SoftLayer.subnet
is used to refer to these soft layer offerings, not the actual resource name.Documents must, of course, be provided. Nevertheless, if there is a better way to define a resource, that method should be used.
Indirect resource definition methods also affect
tf
file readability. In atf
file where dozens of subnets are defined, people have to extract the subnet type by identifying the manual, deducing the subnet type, or creating a separate script.I'll create create two different subnets
softlayer_subnet_portable
andsoftlayer_subnet_static
.