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

CIDR block inputs #87

Closed
bbros-dev opened this issue Oct 29, 2020 · 2 comments
Closed

CIDR block inputs #87

bbros-dev opened this issue Oct 29, 2020 · 2 comments

Comments

@bbros-dev
Copy link

bbros-dev commented Oct 29, 2020

Update: We think this can be treated as a documentation issue, where the source_address_start = cidrhost(var.cidr, "1") and source_address_end = cidrhost(var.cidr, "-1") examples are included in the Terraform registry docs for upcloud_network as well as the github docs.

For the same reasons/motivation as in issue #65 : to reuse terraform code across cloud vendors it helps to pass network ranges a cidr blocks instead of:

      source_address_end = "192.168.1.255"
      source_address_start = "192.168.1.1"

Right now we have to re-write all our resources that abstract away cloud provider specifics, to use different inputs.
This also makes it more costly/difficult to integrate UpCloud when other providers consume ["172.19.48.0/20", "172.19.64.0/20", "172.19.80.0/20",].

A workaround might be to provide two helper functions that takes as input a CIDR block and outputs either the start IP or end IP.

@bbros-dev
Copy link
Author

The workaround currently exists using Terraform cidrhost(...).
In case anyone else comes along this path, using this main.tf:

##############################################
# Variables
##############################################
variable "iprange" {
  default = "10.0.0.0/16"
}

variable "hostnum" {
  default = 2
}

##############################################
# Outputs
##############################################
output "ip_output" {
  value = "${cidrhost(var.iprange,var.hostnum)}"
}

You can get the start IP:

$ yes yes | terraform apply -var "iprange=172.16.0.0/20" -var "hostnum=1"
...
ip_output = 172.16.0.1

You can get the end IP:

$ yes yes | terraform apply -var "iprange=172.16.0.0/20" -var "hostnum=-1"
...
ip_output = 172.16.15.255

@isarpila
Copy link

isarpila commented Mar 4, 2021

Closing this as we discussed this over email already with you Mike.

regards,

-Ilkka

@isarpila isarpila closed this as completed Mar 4, 2021
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

No branches or pull requests

2 participants