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

[WIP] Adds parseurl function #32328

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

flynnhandley
Copy link

@flynnhandley flynnhandley commented Dec 4, 2022

Description

Introduces the parseurl language function which parses a URL string into a map containing the URL segments
Fixes #23893

Usage

locals {
    url = "https://username:[email protected]:8000/search?q=items#top"
}

output "url_parts" {
    value = parseurl(local.url)
}

output "port" {
    value = parseurl(local.url)["Port"]
}

output "hostname" {
    value = parseurl(local.url)["Hostname"]
}
Outputs:

hostname = "example.com"
port = "8000"
url_parts = tomap({
  "Fragment" = "top"
  "Hostname" = "example.com"
  "Password" = "password"
  "Path" = "/search"
  "Port" = "8000"
  "RawQuery" = "q=items"
  "Scheme" = "https"
  "Username" = "username"
})

Target Release

1.4.0

Draft CHANGELOG entry

NEW FEATURES

  • Introduces parseurl language function which parses a URL string into a map containing the URL segments

@hashicorp-cla
Copy link

hashicorp-cla commented Dec 4, 2022

CLA assistant check
All committers have signed the CLA.

Copy link

@lra lra left a comment

Choose a reason for hiding this comment

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

Looks like this is missing the optional port in the URL, see https://url.spec.whatwg.org/#url-representation

@icco
Copy link

icco commented Dec 4, 2022

Looks like this is missing the optional port in the URL, see https://url.spec.whatwg.org/#url-representation

Host contains the port, as it's calling url.Host and not https://pkg.go.dev/net/url#URL.Hostname.

@flynnhandley
Copy link
Author

Looks like this is missing the optional port in the URL, see https://url.spec.whatwg.org/#url-representation

Good find 💪

I think it would be useful to seperate the hostname and port, will push the changes shortly.

@crw
Copy link
Contributor

crw commented Dec 5, 2022

Thanks for this submission! I suspect this function would need to be built as a plugin function provider, as opposed to a function built into Terraform. As such it would be waiting for the implementation of plugin function providers. Please see:

That said, I'll bring it to triage and see if it could be considered as a built-in function. Thanks again for this submission!

@flynnhandley flynnhandley changed the title Adds parseurl function [WIP] Adds parseurl function Dec 5, 2022
@Manouchehri
Copy link

This would be quite nice to have built in IMO. =)

@crw
Copy link
Contributor

crw commented Feb 1, 2023

For posterity, the core team conversation on the parseurl function focused on concerns around details of the net/url implementation and concerns that there may be other functions that would want to share a namespace with a parseurl function. So, leaning towards provider function rather than built-in.

@MauriceArikoglu
Copy link

would love to see this!

@skyzyx
Copy link
Contributor

skyzyx commented Feb 14, 2024

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

Successfully merging this pull request may close these issues.

urlparse function to get url parts
8 participants