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

feat: add ds records and name servers resources for domains #818

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

App13Pie
Copy link

@App13Pie App13Pie commented Feb 2, 2025

Description

Added two resources for OVH domains:

  • ovh_domain_name_servers: Resource to set external name servers for a domain.
  • ovh_domain_ds_records: Resource to set ds_records for a domain

TODO: I haven't updated the documentation.

Fixes #146 (issue)

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

I created a public zone on GPC Cloud DNS to have valid values to pass down to the below tests.

You'll have to export these environment variables:

export OVH_ZONE_TEST="..."
export OVH_DOMAIN_NS1_HOST_TEST="..."
export OVH_DOMAIN_NS1_IP_TEST="..."
export OVH_DOMAIN_NS2_HOST_TEST="..."
export OVH_DOMAIN_NS3_HOST_TEST="..."
export OVH_DOMAIN_DS_RECORD_ALGORITHM_TEST="..."
export OVH_DOMAIN_DS_RECORD_PUBLIC_KEY_TEST="..."
export OVH_DOMAIN_DS_RECORD_TAG_TEST="..."
  • Test A: make testacc TESTARGS="-run TestAccDomainNameServers_Basic"

Test Configuration:

  • Terraform version: terraform version: Terraform v1.10.5
  • Existing HCL configuration you used:
resource "ovh_domain_name_servers" "test" {
	domain = "test.ovh"

	servers {
		host = "ns-cloud-a1.googledomains.com"
		ip = "216.239.32.106"
	}

	servers {
		host = "ns-cloud-a2.googledomains.com"
		ip = ""
    }
}
  • Test B: make testacc TESTARGS="-run TestAccDomainDsRecords_Basic"

Test Configuration:

  • Terraform version: terraform version: Terraform v1.10.5
  • Existing HCL configuration you used:
resource "ovh_domain_ds_records" "test" {
	domain = "test.ovh"

	ds_records {
		algorithm = "RSASHA256"
		flags = "KEY_SIGNING_KEY"
		public_key = "YOUR_PUBLIC_KEY"
		tag = 12345
	}
}

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or issues
  • I have added acceptance tests that prove my fix is effective or that my feature works
  • New and existing acceptance tests pass locally with my changes
  • I ran succesfully go mod vendor if I added or modify go.mod file

@App13Pie App13Pie marked this pull request as ready for review February 11, 2025 22:43
@App13Pie App13Pie requested a review from a team as a code owner February 11, 2025 22:43

log.Printf("[DEBUG] Will read domain name DS records: %s\n", domainName)

responseData := &[]int{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
responseData := &[]int{}
var responseData []int

@@ -0,0 +1,16 @@
package ovh

type DomainTask struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is the exact same struct as DomainZoneTask in file types_domain_zone.go, could you keep only one ? (keeping this one is fine by me since these tasks are common to all /domain section)

"time"
)

func waitDomainTask(client *ovh.Client, domainName string, taskId int) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should move this in types_domain.go to keep consistency with the existing code

Comment on lines +109 to +116
responseData := &DomainDsRecord{}
endpoint := fmt.Sprintf("/domain/%s/dsRecord/%d", url.PathEscape(domainName), dsRecordId)

if err := config.OVHClient.Get(endpoint, &responseData); err != nil {
return helpers.CheckDeleted(resourceData, err, endpoint)
}

domainDsRecords.DsRecords = append(domainDsRecords.DsRecords, *responseData)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
responseData := &DomainDsRecord{}
endpoint := fmt.Sprintf("/domain/%s/dsRecord/%d", url.PathEscape(domainName), dsRecordId)
if err := config.OVHClient.Get(endpoint, &responseData); err != nil {
return helpers.CheckDeleted(resourceData, err, endpoint)
}
domainDsRecords.DsRecords = append(domainDsRecords.DsRecords, *responseData)
responseData := DomainDsRecord{}
endpoint := fmt.Sprintf("/domain/%s/dsRecord/%d", url.PathEscape(domainName), dsRecordId)
if err := config.OVHClient.Get(endpoint, &responseData); err != nil {
return helpers.CheckDeleted(resourceData, err, endpoint)
}
domainDsRecords.DsRecords = append(domainDsRecords.DsRecords, responseData)

func resourceDomainDsRecordsUpdate(resourceData *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
domainName := resourceData.Get("domain").(string)
task := &DomainTask{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
task := &DomainTask{}
task := DomainTask{}

}

for _, nameServerId := range *responseData {
responseData := &DomainNameServer{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
responseData := &DomainNameServer{}
responseData := DomainNameServer{}

domainNameServers.Servers = append(domainNameServers.Servers, *responseData)
}

sort.Slice(domainNameServers.Servers, func(i, j int) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure why we want to sort this array ? I think the field servers could be a TypeSet so we could avoid this sort

func resourceDomainNameServersUpdate(resourceData *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
domainName := resourceData.Get("domain").(string)
task := &DomainTask{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
task := &DomainTask{}
task := DomainTask{}


provider := testAccProvider.Meta().(*Config)

responseData := &[]int{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
responseData := &[]int{}
var responseData []int

var domainNameServerList []DomainNameServer

for _, nameServerId := range *responseData {
responseData := &DomainNameServer{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
responseData := &DomainNameServer{}
responseData := DomainNameServer{}

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

Successfully merging this pull request may close these issues.

New resource: ovh_domain
2 participants