geek876
September 2, 2022, 10:59pm
1
Can I ask help with getting domain name from string please ?
For ex:
for x.domain.com I want domain.com
for x.x.domain.com I want domain.com
for *.x.domain.com I want domain.com
In short, regardless of how deep is the domain, i want to get domain.com .
Thanks.
Is it always going to be a domain.com type domain, or could it also be things like domain.co.uk ?
geek876
September 4, 2022, 10:35am
3
The @stuart-c . Thanks for replying. It could be anything like domain.com , domain.us or domain.co.uk
maxb
September 4, 2022, 10:53am
4
Then, you cannot do this via purely algorithmic string processing.
You need to refer to the Public Suffix List: https://publicsuffix.org/
Data processing of this complexity is best performed in you own custom code before you invoke Terraform - then feed Terraform the processed data via variables or JSON/YAML files.
1 Like
stmx38
November 21, 2023, 4:55pm
5
A very simple code, which is working for Top-level domain ’s and in case of the Second-level domain ’s, should be updated
locals {
input = "domain.com"
# input = "x.domain.com"
# input = "x.x.domain.com"
# input = "*.x.domain.com"
output = join(".", slice(split(".", local.input), length(split(".", local.input))-2, length(split(".", local.input))))
}
output "output" {
value = local.output
}
Outputs:
output = "domain.com"
# output = "domain.com"
# output = "domain.com"
# output = "domain.com"