From 8f8518739e722d67d77aed7d16c32ba60ace6a47 Mon Sep 17 00:00:00 2001 From: DXTimer Date: Wed, 5 Oct 2022 17:46:07 +0700 Subject: [PATCH 1/4] Deprecate contact_id in certificate resource --- CONTRIBUTING.md | 14 +++----------- dnsimple/datasource_dnsimple_certificate_test.go | 6 +++--- .../resource_dnsimple_lets_encrypt_certificate.go | 6 +++--- ...ource_dnsimple_lets_encrypt_certificate_test.go | 11 ++++++----- docs/resources/lets_encrypt_certificate.md | 5 ++--- 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bd85f0f2..2ffb0fc9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,17 +43,9 @@ Our sandbox environment does not allow purchasing or issue certificates. For tha `resource_dnsimple_lets_encrypt_certificate` you will have to run the tests in production (setting `DNSIMPLE_SANDBOX=false` in the shell). -For the Let's Encrypt Resource you will... - have to go to the `resource_dnsimple_lets_encrypt_certificate_test` and change the `domain` (line 21) -to a real domain ID you want test against. - -After that you will have to change the `testAccLetsEncrypConfig` (in that same file) changing the arguments marked: - - contact_id (required) - - and name (optional, but you might have to change it if you run the tests for a second time) - -For the Certificate Data-Source you will... - have to go to the `datasource_dnsimple_certificate_test` and change the `certificate_id` in lines 26 and 39 to -a real certificate ID in the domain you are going to test against. +You will have to set the following env variables in your shell: + - `DNSIMPLE_CERTIFICATE_NAME` the name for which to request the certificate i.e. **www** + - `DNSIMPLE_CERTIFICATE_ID` the certificate ID used in the datasource test ## Sideload the plugin diff --git a/dnsimple/datasource_dnsimple_certificate_test.go b/dnsimple/datasource_dnsimple_certificate_test.go index 0f83047b..9b782d41 100644 --- a/dnsimple/datasource_dnsimple_certificate_test.go +++ b/dnsimple/datasource_dnsimple_certificate_test.go @@ -18,12 +18,12 @@ func TestAccDNSimpleCertificateBasic(t *testing.T) { ProviderFactories: testAccProviderFactories, Steps: []resource.TestStep{ { - Config: fmt.Sprintf(testAccCheckDNSimpleCertificateConfigBasic, domain), + Config: fmt.Sprintf(testAccCheckDNSimpleCertificateConfigBasic, domain, os.Getenv("DNSIMPLE_CERTIFICATE_ID")), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "data.dnsimple_certificate.foobar", "domain", domain), resource.TestCheckResourceAttr( - "data.dnsimple_certificate.foobar", "certificate_id", "PROD_CERT_ID"), + "data.dnsimple_certificate.foobar", "certificate_id", os.Getenv("DNSIMPLE_CERTIFICATE_ID")), ), }, }, @@ -36,5 +36,5 @@ func TestAccDNSimpleCertificateBasic(t *testing.T) { const testAccCheckDNSimpleCertificateConfigBasic = ` data "dnsimple_certificate" "foobar" { domain = "%s" - certificate_id = "USE A CERTIFICATE IN PROD (ALSO DON'T FORGET TO CHANGE IT IN LINE26)" + certificate_id = %s }` diff --git a/dnsimple/resource_dnsimple_lets_encrypt_certificate.go b/dnsimple/resource_dnsimple_lets_encrypt_certificate.go index 010d6024..6baa4f22 100644 --- a/dnsimple/resource_dnsimple_lets_encrypt_certificate.go +++ b/dnsimple/resource_dnsimple_lets_encrypt_certificate.go @@ -32,8 +32,9 @@ func resourceDNSimpleLetsEncryptCertificate() *schema.Resource { Optional: true, }, "contact_id": { - Type: schema.TypeInt, - Required: true, + Type: schema.TypeInt, + Optional: true, + Deprecated: "contact_id is deprecated and will be removed in the next major version.", }, "name": { Type: schema.TypeString, @@ -122,7 +123,6 @@ func resourceDNSimpleLetsEncryptCertificateCreate(ctx context.Context, data *sch domainID := data.Get("domain_id").(string) certificateAttributes := dnsimple.LetsencryptCertificateAttributes{ - ContactID: int64(data.Get("contact_id").(int)), AutoRenew: data.Get("auto_renew").(bool), Name: data.Get("name").(string), } diff --git a/dnsimple/resource_dnsimple_lets_encrypt_certificate_test.go b/dnsimple/resource_dnsimple_lets_encrypt_certificate_test.go index 111bfa39..25b61efa 100644 --- a/dnsimple/resource_dnsimple_lets_encrypt_certificate_test.go +++ b/dnsimple/resource_dnsimple_lets_encrypt_certificate_test.go @@ -3,11 +3,12 @@ package dnsimple import ( "context" "fmt" - "github.com/dnsimple/dnsimple-go/dnsimple" "os" "strconv" "testing" + "github.com/dnsimple/dnsimple-go/dnsimple" + _ "github.com/dnsimple/dnsimple-go/dnsimple" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" @@ -18,13 +19,13 @@ func TestAccDNSimpleLetsEncryptCertificateCreate(t *testing.T) { if sandbox == "false" { var certificate dnsimple.Certificate - domain := "CHANGE ME TO THE ACTUAL DOMAIN ID" + domain := os.Getenv("DNSIMPLE_DOMAIN") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProviderFactories: testAccProviderFactories, Steps: []resource.TestStep{ { - Config: fmt.Sprintf(testAccLetsEncryptConfig, domain), + Config: fmt.Sprintf(testAccLetsEncryptConfig, domain, os.Getenv("DNSIMPLE_CERTIFICATE_NAME")), Check: resource.ComposeTestCheckFunc( testAccCheckLetsEncryptCertificate("dnsimple_lets_encrypt_certificate.foobar", &certificate)), }, @@ -72,7 +73,7 @@ func testAccCheckLetsEncryptCertificate(resourceName string, certificate *dnsimp const testAccLetsEncryptConfig = ` resource "dnsimple_lets_encrypt_certificate" "foobar" { domain_id = "%s" - contact_id = "FIND YOUR CONTACT ID IN THE ADMIN" + contact_id = 1234 auto_renew = false - name = "www" + name = "%s" }` diff --git a/docs/resources/lets_encrypt_certificate.md b/docs/resources/lets_encrypt_certificate.md index 6f38e560..7ff518bd 100644 --- a/docs/resources/lets_encrypt_certificate.md +++ b/docs/resources/lets_encrypt_certificate.md @@ -11,7 +11,6 @@ Provides a DNSimple Let's Encrypt certificate resource. ```hcl resource "dnsimple_lets_encrypt_certificate" "foobar" { domain_id = "${var.dnsimple.domain_id}" - contact_id = "${var.dnsimple.contact_id}" auto_renew = false name = "www" } @@ -22,7 +21,7 @@ resource "dnsimple_lets_encrypt_certificate" "foobar" { The following argument(s) are supported: * `domain_id` - (Required) The domain to be issued the certificate for -* `contact_id` - (Required) The contact id for the certificate +* `contact_id` - (Deprecated) The contact id for the certificate ## Attribute Reference @@ -36,4 +35,4 @@ The following attributes are exported: * `state` - The state of the certificate * `authority_identifier` - The identifying certification authority (CA) * `auto_renew` - Set to true if the certificate will auto-renew -* `csr` - The certificate signing request \ No newline at end of file +* `csr` - The certificate signing request From 902df5bc4ac9e0db3f513e94cc175126b0f8c1cc Mon Sep 17 00:00:00 2001 From: Ivan Bakalov Date: Fri, 7 Oct 2022 09:40:47 +0300 Subject: [PATCH 2/4] Update dnsimple/resource_dnsimple_lets_encrypt_certificate.go Co-authored-by: Simone Carletti --- dnsimple/resource_dnsimple_lets_encrypt_certificate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnsimple/resource_dnsimple_lets_encrypt_certificate.go b/dnsimple/resource_dnsimple_lets_encrypt_certificate.go index 6baa4f22..63915e05 100644 --- a/dnsimple/resource_dnsimple_lets_encrypt_certificate.go +++ b/dnsimple/resource_dnsimple_lets_encrypt_certificate.go @@ -34,7 +34,7 @@ func resourceDNSimpleLetsEncryptCertificate() *schema.Resource { "contact_id": { Type: schema.TypeInt, Optional: true, - Deprecated: "contact_id is deprecated and will be removed in the next major version.", + Deprecated: "contact_id is deprecated and has no effect. The attribute will be removed in the next major version.", }, "name": { Type: schema.TypeString, From 8e3122d67d214633c0909b5a74710b821d5d5bde Mon Sep 17 00:00:00 2001 From: DXTimer Date: Fri, 7 Oct 2022 13:49:06 +0700 Subject: [PATCH 3/4] Remove redundant underscore import --- dnsimple/resource_dnsimple_lets_encrypt_certificate_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/dnsimple/resource_dnsimple_lets_encrypt_certificate_test.go b/dnsimple/resource_dnsimple_lets_encrypt_certificate_test.go index 25b61efa..3be01092 100644 --- a/dnsimple/resource_dnsimple_lets_encrypt_certificate_test.go +++ b/dnsimple/resource_dnsimple_lets_encrypt_certificate_test.go @@ -8,8 +8,6 @@ import ( "testing" "github.com/dnsimple/dnsimple-go/dnsimple" - - _ "github.com/dnsimple/dnsimple-go/dnsimple" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) From 1ec51aa33be54f98b214c98f66b51cb63ef0da9b Mon Sep 17 00:00:00 2001 From: DXTimer Date: Tue, 11 Oct 2022 09:29:34 +0700 Subject: [PATCH 4/4] Update the changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a149e728..88fef1d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## master + +* Deprecate the use of `contact_id` in the `dnsimple_lets_encrypt_certificate` resource. The field is no longer in use and there is no replacement for it. + ## 0.14.1 * Avoid panic when looking for a record and it does not exist on the prefetched list