-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: dns resource #6
Merged
johanneswuerbach
merged 1 commit into
humanitec-architecture:main
from
johanneswuerbach:dns-resource
Jan 8, 2024
Merged
Changes from all commits
Commits
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
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,40 @@ | ||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| terraform | >= 1.3.0 | | ||
| humanitec | ~> 0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| humanitec | ~> 0 | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| dns\_basic | ../../humanitec-resource-defs/dns/basic | n/a | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [humanitec_application.example](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/application) | resource | | ||
| [humanitec_resource_definition_criteria.dns_basic](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| credentials | GCP credentials | `string` | n/a | yes | | ||
| managed\_zone | The name of the zone in which this record set will reside. | `string` | n/a | yes | | ||
| managed\_zone\_dns\_name | The DNS name of the managed zone. | `string` | n/a | yes | | ||
| project | GCP project ID | `string` | n/a | yes | | ||
| region | n/a | `string` | n/a | yes | | ||
| app\_name | n/a | `string` | `"dns-test"` | no | | ||
| resource\_packs\_gcp\_rev | GCP Resource Pack git ref | `string` | `"refs/heads/main"` | no | | ||
| resource\_packs\_gcp\_url | GCP Resource Pack git url | `string` | `"https://github.com/humanitec-architecture/resource-packs-gcp.git"` | no | | ||
<!-- END_TF_DOCS --> |
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,31 @@ | ||
locals { | ||
res_def_prefix = "${var.app_name}-" | ||
} | ||
|
||
resource "humanitec_application" "example" { | ||
id = var.app_name | ||
name = var.app_name | ||
} | ||
|
||
# cloud dns | ||
|
||
module "dns_basic" { | ||
source = "../../humanitec-resource-defs/dns/basic" | ||
|
||
prefix = local.res_def_prefix | ||
|
||
resource_packs_gcp_url = var.resource_packs_gcp_url | ||
resource_packs_gcp_rev = var.resource_packs_gcp_rev | ||
|
||
project = var.project | ||
region = var.region | ||
credentials = var.credentials | ||
|
||
managed_zone = var.managed_zone | ||
managed_zone_dns_name = var.managed_zone_dns_name | ||
} | ||
|
||
resource "humanitec_resource_definition_criteria" "dns_basic" { | ||
resource_definition_id = module.dns_basic.id | ||
app_id = humanitec_application.example.id | ||
} |
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,12 @@ | ||
terraform { | ||
required_providers { | ||
humanitec = { | ||
source = "humanitec/humanitec" | ||
version = "~> 0" | ||
} | ||
} | ||
|
||
required_version = ">= 1.3.0" | ||
} | ||
|
||
provider "humanitec" {} | ||
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,21 @@ | ||
app_name = "dns-test" | ||
|
||
# GCP credentials | ||
credentials = "" | ||
|
||
# The name of the zone in which this record set will reside. | ||
managed_zone = "" | ||
|
||
# The DNS name of the managed zone. | ||
managed_zone_dns_name = "" | ||
|
||
# GCP project ID | ||
project = "" | ||
|
||
region = "" | ||
|
||
# GCP Resource Pack git ref | ||
resource_packs_gcp_rev = "refs/heads/main" | ||
|
||
# GCP Resource Pack git url | ||
resource_packs_gcp_url = "https://github.com/humanitec-architecture/resource-packs-gcp.git" |
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,40 @@ | ||
variable "project" { | ||
description = "GCP project ID" | ||
type = string | ||
} | ||
|
||
variable "region" { | ||
type = string | ||
} | ||
|
||
variable "credentials" { | ||
description = "GCP credentials" | ||
type = string | ||
} | ||
|
||
variable "managed_zone" { | ||
description = "The name of the zone in which this record set will reside." | ||
type = string | ||
} | ||
|
||
variable "managed_zone_dns_name" { | ||
description = "The DNS name of the managed zone." | ||
type = string | ||
} | ||
|
||
variable "app_name" { | ||
type = string | ||
default = "dns-test" | ||
johanneswuerbach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
variable "resource_packs_gcp_url" { | ||
description = "GCP Resource Pack git url" | ||
type = string | ||
default = "https://github.com/humanitec-architecture/resource-packs-gcp.git" | ||
} | ||
|
||
variable "resource_packs_gcp_rev" { | ||
description = "GCP Resource Pack git ref" | ||
type = string | ||
default = "refs/heads/main" | ||
} |
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,39 @@ | ||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| terraform | >= 1.3.0 | | ||
| humanitec | ~> 0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| humanitec | ~> 0 | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [humanitec_resource_definition.main](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition) | resource | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| credentials | n/a | `any` | n/a | yes | | ||
| managed\_zone | The name of the zone in which this record set will reside. | `string` | n/a | yes | | ||
| managed\_zone\_dns\_name | The DNS name of the managed zone. | `string` | n/a | yes | | ||
| prefix | n/a | `string` | n/a | yes | | ||
| project | n/a | `string` | n/a | yes | | ||
| region | n/a | `any` | n/a | yes | | ||
| resource\_packs\_gcp\_rev | n/a | `string` | `"ref/heads/main"` | no | | ||
| resource\_packs\_gcp\_url | n/a | `string` | `"https://github.com/humanitec-architecture/resource-packs-gcp.git"` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| id | n/a | | ||
<!-- END_TF_DOCS --> |
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,33 @@ | ||
resource "humanitec_resource_definition" "main" { | ||
driver_type = "humanitec/terraform" | ||
id = "${var.prefix}clouddns-basic" | ||
name = "${var.prefix}clouddns-basic" | ||
type = "dns" | ||
|
||
driver_inputs = { | ||
secrets_string = jsonencode({ | ||
variables = { | ||
credentials = var.credentials | ||
} | ||
}) | ||
|
||
values_string = jsonencode({ | ||
source = { | ||
path = "modules/dns/basic" | ||
rev = var.resource_packs_gcp_rev | ||
url = var.resource_packs_gcp_url | ||
} | ||
|
||
variables = { | ||
project = var.project | ||
region = var.region | ||
app_id = "$${context.app.id}" | ||
env_id = "$${context.env.id}" | ||
johanneswuerbach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
res_id = "$${context.res.id}" | ||
managed_zone = var.managed_zone | ||
managed_zone_dns_name = var.managed_zone_dns_name | ||
subdomain = "$${context.app.id}-$${context.env.id}" | ||
} | ||
}) | ||
} | ||
} |
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,3 @@ | ||
output "id" { | ||
value = humanitec_resource_definition.main.id | ||
} |
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,10 @@ | ||
terraform { | ||
required_providers { | ||
humanitec = { | ||
source = "humanitec/humanitec" | ||
version = "~> 0" | ||
} | ||
} | ||
|
||
required_version = ">= 1.3.0" | ||
} |
13 changes: 13 additions & 0 deletions
13
humanitec-resource-defs/dns/basic/terraform.tfvars.example
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,13 @@ | ||
credentials = "" | ||
|
||
# The name of the zone in which this record set will reside. | ||
managed_zone = "" | ||
|
||
# The DNS name of the managed zone. | ||
managed_zone_dns_name = "" | ||
|
||
prefix = "" | ||
project = "" | ||
region = "" | ||
resource_packs_gcp_rev = "ref/heads/main" | ||
resource_packs_gcp_url = "https://github.com/humanitec-architecture/resource-packs-gcp.git" |
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,35 @@ | ||
variable "prefix" { | ||
type = string | ||
} | ||
|
||
variable "resource_packs_gcp_rev" { | ||
type = string | ||
default = "ref/heads/main" | ||
} | ||
|
||
variable "resource_packs_gcp_url" { | ||
type = string | ||
default = "https://github.com/humanitec-architecture/resource-packs-gcp.git" | ||
} | ||
|
||
variable "project" { | ||
type = string | ||
} | ||
|
||
variable "region" { | ||
type = any | ||
} | ||
|
||
variable "credentials" { | ||
type = any | ||
} | ||
|
||
variable "managed_zone" { | ||
description = "The name of the zone in which this record set will reside." | ||
type = string | ||
} | ||
|
||
variable "managed_zone_dns_name" { | ||
description = "The DNS name of the managed zone." | ||
type = string | ||
} |
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,43 @@ | ||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| terraform | >= 1.3.0 | | ||
| google | ~> 5.10 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| google | ~> 5.10 | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [google_dns_record_set.main](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/dns_record_set) | resource | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| app\_id | n/a | `string` | n/a | yes | | ||
| credentials | n/a | `string` | n/a | yes | | ||
| env\_id | n/a | `string` | n/a | yes | | ||
| managed\_zone | The name of the zone in which this record set will reside. | `string` | n/a | yes | | ||
| managed\_zone\_dns\_name | The DNS name of the managed zone. | `string` | n/a | yes | | ||
| project | n/a | `string` | n/a | yes | | ||
| region | n/a | `string` | n/a | yes | | ||
| res\_id | n/a | `string` | n/a | yes | | ||
| subdomain | The subdomain of the DNS name that the DNS record is for. | `string` | n/a | yes | | ||
| ip\_address | The IPv4 address that the DNS name should resolve to. | `string` | `""` | no | | ||
| ipv6\_address | The IPv6 address that the DNS name should resolve to. | `string` | `""` | no | | ||
| name | A valid fully qualified domain name that the DNS name should resolve to. | `string` | `""` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| host | The DNS name. | | ||
<!-- END_TF_DOCS --> |
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,32 @@ | ||
# Disabled due to https://github.com/hashicorp/terraform-provider-google/issues/16832 | ||
# data "google_dns_managed_zone" "main" { | ||
# name = var.managed_zone | ||
# } | ||
|
||
locals { | ||
types = ["A", "AAAA", "CNAME"] | ||
records = [var.ip_address, var.ipv6_address, var.name] | ||
rrdatas = [for r in local.records : r if r != ""] | ||
|
||
# If every record is empty, then the type is A, but this will be caught below. | ||
type = local.types[index(local.records, length(local.rrdatas) > 0 ? local.rrdatas[0] : "")] | ||
} | ||
|
||
resource "google_dns_record_set" "main" { | ||
# name = "${var.subdomain}.${data.google_dns_managed_zone.main.dns_name}" | ||
# managed_zone = data.google_dns_managed_zone.main.name | ||
|
||
name = "${var.subdomain}.${var.managed_zone_dns_name}" | ||
managed_zone = var.managed_zone | ||
type = local.type | ||
ttl = 300 | ||
|
||
rrdatas = local.rrdatas | ||
|
||
lifecycle { | ||
precondition { | ||
condition = length(local.rrdatas) > 0 | ||
error_message = "Only one of ip_address, ipv6_address or name is supported." | ||
} | ||
} | ||
} |
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,4 @@ | ||
output "host" { | ||
description = "The DNS name." | ||
value = google_dns_record_set.main.name | ||
} |
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.
I'm using here such a configuration:
But I don't have any opinion about its existence rather than it should be consistent
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.
For AWS I generally left those values out to reduce the amount of inputs, but we can also keep them.