forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add location field in DNS authorization resource. (GoogleCloudPlatfor…
…m#9968) * Add location field in DNS authorization resource * Fixed the provider version of the updated config --------- Co-authored-by: Hamza Hassan <hamzahassan@google.com>
- Loading branch information
Showing
4 changed files
with
184 additions
and
5 deletions.
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
3 changes: 2 additions & 1 deletion
3
mmv1/templates/terraform/examples/certificate_manager_dns_authorization_basic.tf.erb
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
91 changes: 91 additions & 0 deletions
91
mmv1/templates/terraform/state_migrations/certificate_manager_dns_authorization.go.erb
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,91 @@ | ||
func ResourceCertificateManagerDnsAuthorizationUpgradeV0(_ context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { | ||
log.Printf("[DEBUG] Attributes before migration: %#v", rawState) | ||
// Version 0 didn't support location. Default it to global. | ||
rawState["location"] = "global" | ||
log.Printf("[DEBUG] Attributes after migration: %#v", rawState) | ||
return rawState, nil | ||
} | ||
|
||
func resourceCertificateManagerDnsAuthorizationResourceV0() *schema.Resource { | ||
return &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"domain": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: `A domain which is being authorized. A DnsAuthorization resource covers a | ||
single domain and its wildcard, e.g. authorization for "example.com" can | ||
be used to issue certificates for "example.com" and "*.example.com".`, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: `Name of the resource; provided by the client when the resource is created. | ||
The name must be 1-64 characters long, and match the regular expression [a-zA-Z][a-zA-Z0-9_-]* which means the first character must be a letter, | ||
and all following characters must be a dash, underscore, letter or digit.`, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: `A human-readable description of the resource.`, | ||
}, | ||
"labels": { | ||
Type: schema.TypeMap, | ||
Optional: true, | ||
Description: `Set of label tags associated with the DNS Authorization resource. | ||
|
||
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration. | ||
Please refer to the field 'effective_labels' for all of the labels present on the resource.`, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"dns_resource_record": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: `The structure describing the DNS Resource Record that needs to be added | ||
to DNS configuration for the authorization to be usable by | ||
certificate.`, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"data": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `Data of the DNS Resource Record.`, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `Fully qualified name of the DNS Resource Record. | ||
E.g. '_acme-challenge.example.com'.`, | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `Type of the DNS Resource Record.`, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"effective_labels": { | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"terraform_labels": { | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
Description: `The combination of labels configured directly on the resource | ||
and default labels configured on the provider.`, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"project": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
}, | ||
}, | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...ervices/certificatemanager/resource_certificate_manager_dns_authorization_upgrade_test.go
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,78 @@ | ||
package certificatemanager_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
) | ||
|
||
// Tests schema version migration by creating a dns authorization with an old version of the provider (5.15.0) | ||
// and then updating it with the current version the provider. | ||
func TestAccCertificateManagerDnsAuthorization_migration(t *testing.T) { | ||
acctest.SkipIfVcr(t) | ||
t.Parallel() | ||
name := fmt.Sprintf("tf-test-%d", acctest.RandInt(t)) | ||
|
||
oldVersion := map[string]resource.ExternalProvider{ | ||
"google": { | ||
VersionConstraint: "5.15.0", // a version that doesn't support location yet. | ||
Source: "registry.terraform.io/hashicorp/google", | ||
}, | ||
} | ||
newVersion := map[string]func() (*schema.Provider, error){ | ||
"mynewprovider": func() (*schema.Provider, error) { return acctest.TestAccProviders["google"], nil }, | ||
} | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
CheckDestroy: testAccCheckCertificateManagerDnsAuthorizationDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: dnsAuthorizationResourceConfig(name), | ||
ExternalProviders: oldVersion, | ||
}, | ||
{ | ||
ResourceName: "google_certificate_manager_dns_authorization.default", | ||
ImportState: true, | ||
ImportStateVerifyIgnore: []string{"location"}, | ||
ExternalProviders: oldVersion, | ||
}, | ||
{ | ||
Config: dnsAuthorizationResourceConfigUpdated(name), | ||
ProviderFactories: newVersion, | ||
}, | ||
{ | ||
ResourceName: "google_certificate_manager_dns_authorization.default", | ||
ImportState: true, | ||
ImportStateVerifyIgnore: []string{"location"}, | ||
ProviderFactories: newVersion, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func dnsAuthorizationResourceConfig(name string) string { | ||
return fmt.Sprintf(` | ||
resource "google_certificate_manager_dns_authorization" "default" { | ||
name = "%s" | ||
description = "The default dns" | ||
domain = "domain.hashicorptest.com" | ||
} | ||
`, name) | ||
} | ||
|
||
func dnsAuthorizationResourceConfigUpdated(name string) string { | ||
return fmt.Sprintf(` | ||
provider "mynewprovider" {} | ||
resource "google_certificate_manager_dns_authorization" "default" { | ||
provider = mynewprovider | ||
name = "%s" | ||
description = "The migrated default dns" | ||
domain = "domain.hashicorptest.com" | ||
} | ||
`, name) | ||
} |