|
| 1 | +locals { |
| 2 | + // Private and public URLs are shown in the Nullstone UI |
| 3 | + // Typically, they are created through capabilities attached to the application |
| 4 | + // If this module has URLs, add them here as list(string) |
| 5 | + additional_private_urls = [aws_instance.this.private_dns] |
| 6 | + additional_public_urls = [] |
| 7 | + |
| 8 | + private_urls = concat([for url in try(local.capabilities.private_urls, []) : url["url"]], local.additional_private_urls) |
| 9 | + public_urls = concat([for url in try(local.capabilities.public_urls, []) : url["url"]], local.additional_public_urls) |
| 10 | +} |
| 11 | + |
| 12 | +locals { |
| 13 | + uri_matcher = "^(?:(?P<scheme>[^:/?#]+):)?(?://(?P<authority>[^/?#]*))?" |
| 14 | +} |
| 15 | + |
| 16 | +locals { |
| 17 | + authority_matcher = "^(?:(?P<user>[^@]*)@)?(?:(?P<host>[^:]*))(?:[:](?P<port>[\\d]*))?" |
| 18 | + // These tests are here to verify the authority_matcher regex above |
| 19 | + // To verify, uncomment the following lines and issue "echo 'local.tests' | terraform console" |
| 20 | + /* |
| 21 | + tests = tomap({ |
| 22 | + "nullstone.io" : regex(local.authority_matcher, "nullstone.io"), |
| 23 | + "brad@nullstone.io" : regex(local.authority_matcher, "brad@nullstone.io"), |
| 24 | + "brad:password@nullstone.io" : regex(local.authority_matcher, "brad:password@nullstone.io"), |
| 25 | + "nullstone.io:9000" : regex(local.authority_matcher, "nullstone.io:9000"), |
| 26 | + "brad@nullstone.io:9000" : regex(local.authority_matcher, "brad@nullstone.io:9000"), |
| 27 | + "brad:password@nullstone.io:9000" : regex(local.authority_matcher, "brad:password@nullstone.io:9000"), |
| 28 | + }) |
| 29 | + */ |
| 30 | +} |
| 31 | + |
| 32 | +locals { |
| 33 | + private_hosts = [for url in local.private_urls : lookup(regex(local.authority_matcher, lookup(regex(local.uri_matcher, url), "authority")), "host")] |
| 34 | + public_hosts = [for url in local.public_urls : lookup(regex(local.authority_matcher, lookup(regex(local.uri_matcher, url), "authority")), "host")] |
| 35 | +} |
0 commit comments