From 397c56a1148fda2216870a73ab414fd3fc35bad7 Mon Sep 17 00:00:00 2001 From: Sakala Venkata Krishna Rohit Date: Wed, 23 Oct 2024 09:34:15 -0700 Subject: [PATCH] Remove global dns from rancher terraform (#1428) --- docs/data-sources/global_dns_provider.md | 30 -- docs/resources/global_dns.md | 92 ----- docs/resources/global_dns_provider.md | 115 ------ rancher2/0_provider_upgrade_test.go | 16 - ...ata_source_rancher2_global_dns_provider.go | 93 ----- ...ource_rancher2_global_dns_provider_test.go | 35 -- rancher2/import_rancher2_global_dns.go | 14 - .../import_rancher2_global_dns_provider.go | 14 - rancher2/provider.go | 3 - rancher2/resource_rancher2_global_dns.go | 256 ------------ .../resource_rancher2_global_dns_provider.go | 195 --------- ...ource_rancher2_global_dns_provider_test.go | 371 ------------------ rancher2/resource_rancher2_global_dns_test.go | 211 ---------- rancher2/schema_global_dns.go | 47 --- rancher2/schema_global_dns_provider.go | 142 ------- rancher2/structure_global_dns.go | 82 ---- rancher2/structure_global_dns_provider.go | 229 ----------- .../structure_global_dns_provider_test.go | 204 ---------- rancher2/structure_global_dns_test.go | 85 ---- website/rancher2.erb | 9 - 20 files changed, 2243 deletions(-) delete mode 100644 docs/data-sources/global_dns_provider.md delete mode 100644 docs/resources/global_dns.md delete mode 100644 docs/resources/global_dns_provider.md delete mode 100644 rancher2/data_source_rancher2_global_dns_provider.go delete mode 100644 rancher2/data_source_rancher2_global_dns_provider_test.go delete mode 100644 rancher2/import_rancher2_global_dns.go delete mode 100644 rancher2/import_rancher2_global_dns_provider.go delete mode 100644 rancher2/resource_rancher2_global_dns.go delete mode 100644 rancher2/resource_rancher2_global_dns_provider.go delete mode 100644 rancher2/resource_rancher2_global_dns_provider_test.go delete mode 100644 rancher2/resource_rancher2_global_dns_test.go delete mode 100644 rancher2/schema_global_dns.go delete mode 100644 rancher2/schema_global_dns_provider.go delete mode 100644 rancher2/structure_global_dns.go delete mode 100644 rancher2/structure_global_dns_provider.go delete mode 100644 rancher2/structure_global_dns_provider_test.go delete mode 100644 rancher2/structure_global_dns_test.go diff --git a/docs/data-sources/global_dns_provider.md b/docs/data-sources/global_dns_provider.md deleted file mode 100644 index 01ed36a0..00000000 --- a/docs/data-sources/global_dns_provider.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -layout: "rancher2" -page_title: "Rancher2: rancher2_global_dns_provider" -sidebar_current: "docs-rancher2-datasource-global_dns_provider" -description: |- - Provides a Rancher V2 Global DNS Provider data source. Use this data source to retrieve information about a Rancher v2 global DNS provider ---- - -# rancher2\_global\_dns\_provider - -Provides a Rancher V2 Global DNS Provider data source. Use this data source to retrieve information about a Rancher v2 global DNS provider - -## Example Usage - -```hcl -data "rancher2_global_dns_provider" "foo" { - name = "foo" -} -``` - -## Argument Reference - -* `name` - (Required) The name of the global DNS provider (string) - -## Attributes Reference - -* `id` - (Computed) The ID of the resource (string) -* `name` - (Computed) The name of the global DNS provider (string) -* `annotations` - (Computed) Annotations of the resource (map) -* `labels` - (Computed) Labels of the resource (map) \ No newline at end of file diff --git a/docs/resources/global_dns.md b/docs/resources/global_dns.md deleted file mode 100644 index cdd0eba0..00000000 --- a/docs/resources/global_dns.md +++ /dev/null @@ -1,92 +0,0 @@ ---- -layout: "rancher2" -page_title: "Rancher2: rancher2_global_dns" -sidebar_current: "docs-rancher2-resource-global_dns" -description: |- - Provides a Rancher V2 Global DNS resource. This can be used to create Global DNS records for Rancher V2. ---- - -# rancher2\_global\_dns - -Provides a Rancher V2 Global DNS resource. This can be used to create Global DNS records for Rancher V2. - -## Example Usage - -```hcl -# Create a new rancher2 Global DNS Provider -resource "rancher2_global_dns_provider" "foo" { - name = "foo" - root_domain = "example.com" - route53_config { - access_key = "YYYYYYYYYYYYYYYYYYYY" - secret_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - zone_type = "private" - region = "us-east-1" - } -} -# Create a new rancher2 Global DNS using project IDs -resource "rancher2_global_dns" "foo" { - name = "foo" - fqdn = "foo.example.com" - provider_id = rancher2_global_dns_provider.foo.id - project_ids = ["project1", "project2"] -} -``` - -```hcl -# Create a new rancher2 Global DNS Provider -resource "rancher2_global_dns_provider" "foo" { - name = "foo" - root_domain = "example.com" - route53_config { - access_key = "YYYYYYYYYYYYYYYYYYYY" - secret_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - zone_type = "private" - region = "us-east-1" - } -} -# Create a new rancher2 Global DNS using MultiClusterApp ID -resource "rancher2_global_dns" "foo" { - name = "foo" - fqdn = "foo.example.com" - provider_id = rancher2_global_dns_provider.foo.id - multi_cluster_app_id = "" -} -``` - -## Argument Reference - -The following arguments are supported: - -* `fqdn` - (Required) The Global DNS record (string) -* `provider_id` - (Required) The Global DNS provider ID to use (string) -* `multi_cluster_app_id` - (Optional) The MultiCluster App ID to assign to the Global DNS. Conflicts with `project_ids` (string) -* `name` - (Optional/Computed/ForceNew) The name of the Global DNS (string) -* `project_ids` - (Optional) A list of project_ids to assign to the Global DNS. Conflicts with `multi_cluster_app_id` (list(string)) -* `ttl` - (Optional) TTL in seconds for DNS record. Default: `300` (int) -* `annotations` - (Optional/Computed) Annotations for Global DNS (map) -* `labels` - (Optional/Computed) Labels for Global DNS (map) - - -## Attributes Reference - -The following attributes are exported: - -* `id` - (Computed) The ID of the resource (string) - -## Timeouts - -`rancher2_global_dns_entry` provides the following -[Timeouts](https://www.terraform.io/docs/configuration/resources.html#operation-timeouts) configuration options: - -- `create` - (Default `5 minutes`) Used for creating Global DNS -- `update` - (Default `5 minutes`) Used for Global DNS modifications -- `delete` - (Default `5 minutes`) Used for deleting Global DNS - -## Import - -Global DNS Entry can be imported using the Rancher Global DNS ID - -``` -$ terraform import rancher2_global_dns_entry.foo -``` diff --git a/docs/resources/global_dns_provider.md b/docs/resources/global_dns_provider.md deleted file mode 100644 index bcd5da42..00000000 --- a/docs/resources/global_dns_provider.md +++ /dev/null @@ -1,115 +0,0 @@ ---- -layout: "rancher2" -page_title: "Rancher2: rancher2_global_dns_provider" -sidebar_current: "docs-rancher2-resource-global_dns_provider" -description: |- - Provides a Rancher V2 Global DNS Provider resource. This can be used to create Global DNS Providers for Rancher V2. ---- - -# rancher2\_global\_dns\_provider - -Provides a Rancher V2 Global DNS Provider resource. This can be used to create Global DNS Providers for Rancher V2. Supported Global DNS Providers: `alidns, cloudflare, route53` - -## Example Usage - -```hcl -# Create a new rancher2 Global DNS Provider - alidns -resource "rancher2_global_dns_provider" "foo" { - name = "foo" - root_domain = "example.com" - alidns_config { - access_key = "YYYYYYYYYYYYYYYYYYYY" - secret_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - } -} -``` - -```hcl -# Create a new rancher2 Global DNS Provider - cloudflare -resource "rancher2_global_dns_provider" "foo" { - name = "foo" - root_domain = "example.com" - cloudflare_config { - api_email = "test@test.local" - api_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - proxy_setting = true - } -} -``` - -```hcl -# Create a new rancher2 Global DNS Provider - route53 -resource "rancher2_global_dns_provider" "foo" { - name = "foo" - root_domain = "example.com" - route53_config { - access_key = "YYYYYYYYYYYYYYYYYYYY" - secret_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - zone_type = "private" - region = "us-east-1" - } -} -``` - -## Argument Reference - -The following arguments are supported: - -* `name` - (Optional/Computed/ForceNew) The name of the Global DNS Provider (string) -* `root_domain` - (Required) The user ID to assign Global DNS Provider (string) -* `alidns_domain` - (Optional) The AliDNS provider config (list maxitems:1) -* `cloudflare_domain` - (Optional) The ClodFlare provider config (list maxitems:1) -* `route53_domain` - (Optional) The Route53 provider config (list maxitems:1) -* `annotations` - (Optional/Computed) Annotations for Global DNS Provider (map) -* `labels` - (Optional/Computed) Labels for Global DNS Provider (map) - -## Nested blocks - -### `alidns_config` - -#### Arguments -* `access_key` - (Required) The AliDNS Access key (string) -* `secret_key` - (Required) The AliDNS Secret key (string) - -### `cloudflare_config` - -#### Arguments -* `api_email` - (Required) The CloudFlare API Email (string) -* `api_key` - (Required) The CloudFlare API Key (string) -* `proxy_setting` - (Optional) CloudFlare Proxy Setting. Default: `false` (bool) - -### `route_53` - -#### Arguments - -* `access_key` - (Required) The AWS Access key (string) -* `secret_key` - (Required) The AWS Secret key (string) -* `credentials_path` - (Optional) The AWS credentials path. Default: `"/.aws"` (string) -* `region` - (Optional) The AWS Region. Default: `"us-west-2"` (string) -* `role_arn` - (Optional) The AWS Role ARN (string) -* `zone_type` - (Optional) The Route53 zone type `public, private`. Default: `"public"` (string) - -## Attributes Reference - -The following attributes are exported: - -* `id` - (Computed) The ID of the resource (string) -* `dns_provider` - (Computed) The Global DNS Provider `alidns, cloudflare, route53` (string) - -## Timeouts - -`rancher2_global_dns_provider` provides the following -[Timeouts](https://www.terraform.io/docs/configuration/resources.html#operation-timeouts) configuration options: - -- `create` - (Default `5 minutes`) Used for creating Global DNS Providers. -- `update` - (Default `5 minutes`) Used for Global DNS Provider modifications. -- `delete` - (Default `5 minutes`) Used for deleting Global DNS Providers. - -## Import - -Global DNS Providers can be imported using the Rancher Global DNS Provider ID - -``` -$ terraform import rancher2_global_dns_provider.foo -``` - diff --git a/rancher2/0_provider_upgrade_test.go b/rancher2/0_provider_upgrade_test.go index 10aa6f62..c04d8e25 100644 --- a/rancher2/0_provider_upgrade_test.go +++ b/rancher2/0_provider_upgrade_test.go @@ -113,10 +113,6 @@ provider "rancher2" { ` + testAccRancher2ClusterRoleTemplateBinding + ` ` + testAccRancher2ClusterTemplateConfig + ` ` + testAccRancher2EtcdBackup + ` -` + testAccRancher2GlobalDNS + ` -` + testAccRancher2GlobalDNSProviderAlidnsConfig + ` -` + testAccRancher2GlobalDNSProviderCloudflareConfig + ` -` + testAccRancher2GlobalDNSProviderRoute53Config + ` ` + testAccRancher2GlobalRoleBinding + ` ` + testAccRancher2MultiClusterApp + ` ` + testAccRancher2Namespace + ` @@ -154,10 +150,6 @@ provider "rancher2" { ` + testAccRancher2ClusterRoleTemplateBinding + ` ` + testAccRancher2ClusterTemplateConfig + ` ` + testAccRancher2EtcdBackup + ` -` + testAccRancher2GlobalDNS + ` -` + testAccRancher2GlobalDNSProviderAlidnsConfig + ` -` + testAccRancher2GlobalDNSProviderCloudflareConfig + ` -` + testAccRancher2GlobalDNSProviderRoute53Config + ` ` + testAccRancher2GlobalRoleBinding + ` ` + testAccRancher2MultiClusterApp + ` ` + testAccRancher2Namespace + ` @@ -199,10 +191,6 @@ provider "rancher2" { ` + testAccRancher2ClusterTemplateConfig + ` ` + testAccRancher2EtcdBackup + ` ` + testAccRancher2FeatureConfig + ` -` + testAccRancher2GlobalDNS + ` -` + testAccRancher2GlobalDNSProviderAlidnsConfig + ` -` + testAccRancher2GlobalDNSProviderCloudflareConfig + ` -` + testAccRancher2GlobalDNSProviderRoute53Config + ` ` + testAccRancher2GlobalRoleBinding + ` ` + testAccRancher2MultiClusterApp + ` ` + testAccRancher2Namespace + ` @@ -248,10 +236,6 @@ provider "rancher2" { ` + testAccRancher2ClusterTemplateConfig + ` ` + testAccRancher2EtcdBackup + ` ` + testAccRancher2FeatureConfig + ` -` + testAccRancher2GlobalDNS + ` -` + testAccRancher2GlobalDNSProviderAlidnsConfig + ` -` + testAccRancher2GlobalDNSProviderCloudflareConfig + ` -` + testAccRancher2GlobalDNSProviderRoute53Config + ` ` + testAccRancher2GlobalRoleBinding + ` ` + testAccRancher2MultiClusterApp + ` ` + testAccRancher2Namespace + ` diff --git a/rancher2/data_source_rancher2_global_dns_provider.go b/rancher2/data_source_rancher2_global_dns_provider.go deleted file mode 100644 index 4e96fe96..00000000 --- a/rancher2/data_source_rancher2_global_dns_provider.go +++ /dev/null @@ -1,93 +0,0 @@ -package rancher2 - -import ( - "fmt" - - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func dataSourceRancher2GlobalDNSProvider() *schema.Resource { - return &schema.Resource{ - Read: dataSourceRancher2GlobalDNSProviderRead, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - }, - "annotations": { - Type: schema.TypeMap, - Computed: true, - }, - "labels": { - Type: schema.TypeMap, - Computed: true, - }, - "root_domain": { - Type: schema.TypeString, - Computed: true, - }, - "dns_provider": { - Type: schema.TypeString, - Computed: true, - }, - "alidns_config": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - Elem: &schema.Resource{ - Schema: globalDNSProviderAliConfigSchema(), - }, - }, - "cloudflare_config": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - Elem: &schema.Resource{ - Schema: globalDNSProviderCloudFareConfigSchema(), - }, - }, - "route53_config": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - Elem: &schema.Resource{ - Schema: globalDNSProviderRoute53ConfigSchema(), - }, - }, - }, - } -} - -func dataSourceRancher2GlobalDNSProviderRead(d *schema.ResourceData, meta interface{}) error { - client, err := meta.(*Config).ManagementClient() - if err != nil { - return err - } - name := d.Get("name").(string) - - filters := map[string]interface{}{ - "name": name, - } - - listOpts := NewListOpts(filters) - - globalDNSProvider, err := client.GlobalDnsProvider.List(listOpts) - if err != nil { - return err - } - - count := len(globalDNSProvider.Data) - if count <= 0 { - return fmt.Errorf("[ERROR] global dns provider with name \"%s\" not found", name) - } - if count > 1 { - return fmt.Errorf("[ERROR] found %d global dns provider with name \"%s\"", count, name) - } - - flattenGlobalDNSProvider(d, &globalDNSProvider.Data[0]) - - //return fmt.Errorf("[ERROR] %#v\n%#v", d.Get("route53_config"), globalDNSProvider.Data[0].Route53ProviderConfig) - - return flattenGlobalDNSProvider(d, &globalDNSProvider.Data[0]) -} diff --git a/rancher2/data_source_rancher2_global_dns_provider_test.go b/rancher2/data_source_rancher2_global_dns_provider_test.go deleted file mode 100644 index 72635ee8..00000000 --- a/rancher2/data_source_rancher2_global_dns_provider_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package rancher2 - -import ( - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" -) - -const ( - testAccRancher2GlobalDNSProviderDataSourceType = "rancher2_global_dns_provider" -) - -func TestAccRancher2GlobalDNSProviderDataSource(t *testing.T) { - testAccCheckRancher2GlobalDNSProviderDataSourceConfig := testAccRancher2GlobalDNSProviderRoute53Config + ` -data "` + testAccRancher2GlobalDNSProviderDataSourceType + `" "foo" { - name = rancher2_global_dns_provider.foo-route53.name -} -` - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckRancher2GlobalDNSProviderDataSourceConfig, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data."+testAccRancher2GlobalDNSProviderDataSourceType+".foo", "name", "foo-route53"), - resource.TestCheckResourceAttr("data."+testAccRancher2GlobalDNSProviderDataSourceType+".foo", "dns_provider", globalDNSProviderRoute53Kind), - resource.TestCheckResourceAttr("data."+testAccRancher2GlobalDNSProviderDataSourceType+".foo", "root_domain", "example.com"), - resource.TestCheckResourceAttr("data."+testAccRancher2GlobalDNSProviderDataSourceType+".foo", "route53_config.0.access_key", "YYYYYYYYYYYYYYYYYYYY"), - resource.TestCheckResourceAttr("data."+testAccRancher2GlobalDNSProviderDataSourceType+".foo", "route53_config.0.zone_type", "private"), - ), - }, - }, - }) -} diff --git a/rancher2/import_rancher2_global_dns.go b/rancher2/import_rancher2_global_dns.go deleted file mode 100644 index d89ed73e..00000000 --- a/rancher2/import_rancher2_global_dns.go +++ /dev/null @@ -1,14 +0,0 @@ -package rancher2 - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func resourceRancher2GlobalDNSImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2GlobalDNSRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err - } - - return []*schema.ResourceData{d}, nil -} diff --git a/rancher2/import_rancher2_global_dns_provider.go b/rancher2/import_rancher2_global_dns_provider.go deleted file mode 100644 index 44238441..00000000 --- a/rancher2/import_rancher2_global_dns_provider.go +++ /dev/null @@ -1,14 +0,0 @@ -package rancher2 - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func resourceRancher2GlobalDNSProviderImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2GlobalDNSProviderRead(d, meta) - if err != nil { - return []*schema.ResourceData{}, err - } - - return []*schema.ResourceData{d}, nil -} diff --git a/rancher2/provider.go b/rancher2/provider.go index 6e3f19b6..4d06711b 100644 --- a/rancher2/provider.go +++ b/rancher2/provider.go @@ -133,8 +133,6 @@ func Provider() terraform.ResourceProvider { "rancher2_custom_user_token": resourceRancher2CustomUserToken(), "rancher2_etcd_backup": resourceRancher2EtcdBackup(), "rancher2_feature": resourceRancher2Feature(), - "rancher2_global_dns": resourceRancher2GlobalDNS(), - "rancher2_global_dns_provider": resourceRancher2GlobalDNSProvider(), "rancher2_global_role": resourceRancher2GlobalRole(), "rancher2_global_role_binding": resourceRancher2GlobalRoleBinding(), "rancher2_machine_config_v2": resourceRancher2MachineConfigV2(), @@ -169,7 +167,6 @@ func Provider() terraform.ResourceProvider { "rancher2_cluster_template": dataSourceRancher2ClusterTemplate(), "rancher2_config_map_v2": dataSourceRancher2ConfigMapV2(), "rancher2_etcd_backup": dataSourceRancher2EtcdBackup(), - "rancher2_global_dns_provider": dataSourceRancher2GlobalDNSProvider(), "rancher2_global_role": dataSourceRancher2GlobalRole(), "rancher2_global_role_binding": dataSourceRancher2GlobalRoleBinding(), "rancher2_multi_cluster_app": dataSourceRancher2MultiClusterApp(), diff --git a/rancher2/resource_rancher2_global_dns.go b/rancher2/resource_rancher2_global_dns.go deleted file mode 100644 index d0194c92..00000000 --- a/rancher2/resource_rancher2_global_dns.go +++ /dev/null @@ -1,256 +0,0 @@ -package rancher2 - -import ( - "fmt" - "log" - "time" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" -) - -func resourceRancher2GlobalDNS() *schema.Resource { - return &schema.Resource{ - Create: resourceRancher2GlobalDNSCreate, - Read: resourceRancher2GlobalDNSRead, - Update: resourceRancher2GlobalDNSUpdate, - Delete: resourceRancher2GlobalDNSDelete, - Importer: &schema.ResourceImporter{ - State: resourceRancher2GlobalDNSImport, - }, - - Schema: GlobalDNSFields(), - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), - }, - } -} - -func resourceRancher2GlobalDNSCreate(d *schema.ResourceData, meta interface{}) error { - globalDNS, err := expandGlobalDNS(d) - if err != nil { - return err - } - - client, err := meta.(*Config).ManagementClient() - if err != nil { - return err - } - - log.Printf("[INFO] Creating Global DNS registry %s", globalDNS.FQDN) - - newglobalDNS, err := client.GlobalDns.Create(globalDNS) - if err != nil { - return err - } - - stateConf := &resource.StateChangeConf{ - Pending: []string{"active"}, - Target: []string{"active"}, - Refresh: globalDNSStateRefreshFunc(client, newglobalDNS.ID), - Timeout: d.Timeout(schema.TimeoutCreate), - Delay: 1 * time.Second, - MinTimeout: 3 * time.Second, - } - _, waitErr := stateConf.WaitForState() - if waitErr != nil { - return fmt.Errorf( - "[ERROR] waiting for global DNS (%s) to be created: %s", newglobalDNS.ID, waitErr) - } - - err = flattenGlobalDNS(d, newglobalDNS) - if err != nil { - return err - } - - return resourceRancher2GlobalDNSRead(d, meta) -} - -func resourceRancher2GlobalDNSRead(d *schema.ResourceData, meta interface{}) error { - log.Printf("[INFO] Refreshing Global DNS ID %s", d.Id()) - client, err := meta.(*Config).ManagementClient() - if err != nil { - return err - } - - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { - globalDNS, err := client.GlobalDns.ByID(d.Id()) - if err != nil { - if IsNotFound(err) { - log.Printf("[INFO] Global DNS ID %s not found.", d.Id()) - d.SetId("") - return nil - } - return resource.NonRetryableError(err) - } - - if err = flattenGlobalDNS(d, globalDNS); err != nil { - return resource.NonRetryableError(err) - } - - return nil - }) -} - -func resourceRancher2GlobalDNSUpdate(d *schema.ResourceData, meta interface{}) error { - log.Printf("[INFO] Updating Global DNS ID %s", d.Id()) - client, err := meta.(*Config).ManagementClient() - if err != nil { - return err - } - - globalDNS, err := client.GlobalDns.ByID(d.Id()) - if err != nil { - return err - } - - update := map[string]interface{}{ - "providerId": d.Get("provider_id").(string), - "annotations": toMapString(d.Get("annotations").(map[string]interface{})), - "labels": toMapString(d.Get("labels").(map[string]interface{})), - } - - if d.HasChange("multi_cluster_app_id") { - if v, ok := d.Get("multi_cluster_app_id").(string); ok && len(v) > 0 { - update["multiClusterAppId"] = v - } - } - - newglobalDNS, err := client.GlobalDns.Update(globalDNS, update) - if err != nil { - return err - } - - stateConf := &resource.StateChangeConf{ - Pending: []string{"active"}, - Target: []string{"active"}, - Refresh: globalDNSStateRefreshFunc(client, newglobalDNS.ID), - Timeout: d.Timeout(schema.TimeoutUpdate), - Delay: 1 * time.Second, - MinTimeout: 3 * time.Second, - } - _, waitErr := stateConf.WaitForState() - if waitErr != nil { - return fmt.Errorf( - "[ERROR] waiting for global DNS (%s) to be updated: %s", newglobalDNS.ID, waitErr) - } - - if d.HasChange("project_ids") { - if v, ok := d.Get("project_ids").([]interface{}); ok { - projectsIDS := toArrayString(v) - projectsToAdd := []string{} - projectsToRemove := []string{} - for i := range projectsIDS { - found := false - for j := range newglobalDNS.ProjectIDs { - if projectsIDS[i] == newglobalDNS.ProjectIDs[j] { - found = true - break - } - } - if !found { - projectsToAdd = append(projectsToAdd, projectsIDS[i]) - } - } - for i := range newglobalDNS.ProjectIDs { - found := false - for j := range projectsIDS { - if projectsIDS[j] == newglobalDNS.ProjectIDs[i] { - found = true - break - } - } - if !found { - projectsToRemove = append(projectsToRemove, newglobalDNS.ProjectIDs[i]) - } - } - if len(newglobalDNS.Actions["addProjects"]) > 0 && len(projectsToAdd) > 0 { - projectAdd := &managementClient.UpdateGlobalDNSTargetsInput{ - ProjectIDs: projectsToAdd, - } - err = client.GlobalDns.ActionAddProjects(newglobalDNS, projectAdd) - if err != nil { - return err - } - - } - if len(newglobalDNS.Actions["removeProjects"]) > 0 && len(projectsToRemove) > 0 { - projectRemove := &managementClient.UpdateGlobalDNSTargetsInput{ - ProjectIDs: projectsToRemove, - } - err = client.GlobalDns.ActionRemoveProjects(newglobalDNS, projectRemove) - if err != nil { - return err - } - } - } - } - - return resourceRancher2GlobalDNSRead(d, meta) -} - -func resourceRancher2GlobalDNSDelete(d *schema.ResourceData, meta interface{}) error { - log.Printf("[INFO] Deleting Global DNS ID %s", d.Id()) - id := d.Id() - client, err := meta.(*Config).ManagementClient() - if err != nil { - return err - } - - globalDNS, err := client.GlobalDns.ByID(id) - if err != nil { - if IsNotFound(err) { - log.Printf("[INFO] Global DNS ID %s not found.", d.Id()) - d.SetId("") - return nil - } - return err - } - - err = client.GlobalDns.Delete(globalDNS) - if err != nil { - return fmt.Errorf("Error removing Global DNS: %s", err) - } - - log.Printf("[DEBUG] Waiting for global DNS (%s) to be removed", id) - - stateConf := &resource.StateChangeConf{ - Pending: []string{"active"}, - Target: []string{"removed"}, - Refresh: globalDNSStateRefreshFunc(client, id), - Timeout: d.Timeout(schema.TimeoutDelete), - Delay: 1 * time.Second, - MinTimeout: 3 * time.Second, - } - - _, waitErr := stateConf.WaitForState() - if waitErr != nil { - return fmt.Errorf( - "[ERROR] waiting for global DNS (%s) to be removed: %s", id, waitErr) - } - - d.SetId("") - return nil -} - -// globalDNSStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Global Role Binding. -func globalDNSStateRefreshFunc(client *managementClient.Client, globalDNSID string) resource.StateRefreshFunc { - return func() (interface{}, string, error) { - obj, err := client.GlobalDns.ByID(globalDNSID) - if err != nil { - if IsNotFound(err) { - return obj, "removed", nil - } - return nil, "", err - } - - if obj.Removed != "" { - return obj, "removed", nil - } - - return obj, "active", nil - } -} diff --git a/rancher2/resource_rancher2_global_dns_provider.go b/rancher2/resource_rancher2_global_dns_provider.go deleted file mode 100644 index 99928317..00000000 --- a/rancher2/resource_rancher2_global_dns_provider.go +++ /dev/null @@ -1,195 +0,0 @@ -package rancher2 - -import ( - "fmt" - "log" - "time" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" -) - -func resourceRancher2GlobalDNSProvider() *schema.Resource { - return &schema.Resource{ - Create: resourceRancher2GlobalDNSProviderCreate, - Read: resourceRancher2GlobalDNSProviderRead, - Update: resourceRancher2GlobalDNSProviderUpdate, - Delete: resourceRancher2GlobalDNSProviderDelete, - Importer: &schema.ResourceImporter{ - State: resourceRancher2GlobalDNSProviderImport, - }, - - Schema: globalDNSProviderFields(), - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(5 * time.Minute), - Delete: schema.DefaultTimeout(5 * time.Minute), - }, - } -} - -func resourceRancher2GlobalDNSProviderCreate(d *schema.ResourceData, meta interface{}) error { - globalDNSProvider := expandGlobalDNSProvider(d) - - client, err := meta.(*Config).ManagementClient() - if err != nil { - return err - } - - log.Printf("[INFO] Creating Global DNS Provider %s", globalDNSProvider.Name) - - newGlobalDNSProvider, err := client.GlobalDnsProvider.Create(globalDNSProvider) - if err != nil { - return err - } - - stateConf := &resource.StateChangeConf{ - Pending: []string{"active"}, - Target: []string{"active"}, - Refresh: globalDNSProviderStateRefreshFunc(client, newGlobalDNSProvider.ID), - Timeout: d.Timeout(schema.TimeoutCreate), - Delay: 1 * time.Second, - MinTimeout: 3 * time.Second, - } - _, waitErr := stateConf.WaitForState() - if waitErr != nil { - return fmt.Errorf( - "[ERROR] waiting for global dns provider (%s) to be created: %s", newGlobalDNSProvider.ID, waitErr) - } - - err = flattenGlobalDNSProvider(d, newGlobalDNSProvider) - if err != nil { - return err - } - - return resourceRancher2GlobalDNSProviderRead(d, meta) -} - -func resourceRancher2GlobalDNSProviderRead(d *schema.ResourceData, meta interface{}) error { - log.Printf("[INFO] Refreshing Global DNS Provider ID %s", d.Id()) - client, err := meta.(*Config).ManagementClient() - if err != nil { - return err - } - - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { - globalDNSProvider, err := client.GlobalDnsProvider.ByID(d.Id()) - if err != nil { - if IsNotFound(err) { - log.Printf("[INFO] Global DNS Provider ID %s not found.", d.Id()) - d.SetId("") - return nil - } - return resource.NonRetryableError(err) - } - - if err = flattenGlobalDNSProvider(d, globalDNSProvider); err != nil { - return resource.NonRetryableError(err) - } - - return nil - }) -} - -func resourceRancher2GlobalDNSProviderUpdate(d *schema.ResourceData, meta interface{}) error { - log.Printf("[INFO] Updating Global DNS Provider ID %s", d.Id()) - client, err := meta.(*Config).ManagementClient() - if err != nil { - return err - } - - globalDNSProvider, err := client.GlobalDnsProvider.ByID(d.Id()) - if err != nil { - return err - } - - update := map[string]interface{}{ - "annotations": toMapString(d.Get("annotations").(map[string]interface{})), - "labels": toMapString(d.Get("labels").(map[string]interface{})), - } - - newGlobalDNSProvider, err := client.GlobalDnsProvider.Update(globalDNSProvider, update) - if err != nil { - return err - } - - stateConf := &resource.StateChangeConf{ - Pending: []string{"active"}, - Target: []string{"active"}, - Refresh: globalDNSProviderStateRefreshFunc(client, newGlobalDNSProvider.ID), - Timeout: d.Timeout(schema.TimeoutUpdate), - Delay: 1 * time.Second, - MinTimeout: 3 * time.Second, - } - _, waitErr := stateConf.WaitForState() - if waitErr != nil { - return fmt.Errorf( - "[ERROR] waiting for global dns provider (%s) to be updated: %s", newGlobalDNSProvider.ID, waitErr) - } - - return resourceRancher2GlobalDNSProviderRead(d, meta) -} - -func resourceRancher2GlobalDNSProviderDelete(d *schema.ResourceData, meta interface{}) error { - log.Printf("[INFO] Deleting Global DNS Provider ID %s", d.Id()) - id := d.Id() - client, err := meta.(*Config).ManagementClient() - if err != nil { - return err - } - - globalDNSProvider, err := client.GlobalDnsProvider.ByID(id) - if err != nil { - if IsNotFound(err) { - log.Printf("[INFO] Global DNS Provider ID %s not found.", d.Id()) - d.SetId("") - return nil - } - return err - } - - err = client.GlobalDnsProvider.Delete(globalDNSProvider) - if err != nil { - return fmt.Errorf("Error removing Global DNS Provider: %s", err) - } - - log.Printf("[DEBUG] Waiting for global dns provider (%s) to be removed", id) - - stateConf := &resource.StateChangeConf{ - Pending: []string{"active"}, - Target: []string{"removed"}, - Refresh: globalDNSProviderStateRefreshFunc(client, id), - Timeout: d.Timeout(schema.TimeoutDelete), - Delay: 1 * time.Second, - MinTimeout: 3 * time.Second, - } - - _, waitErr := stateConf.WaitForState() - if waitErr != nil { - return fmt.Errorf( - "[ERROR] waiting for global dns provider (%s) to be removed: %s", id, waitErr) - } - - d.SetId("") - return nil -} - -// globalDNSProviderStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Global DNS Provider. -func globalDNSProviderStateRefreshFunc(client *managementClient.Client, globalDNSProviderID string) resource.StateRefreshFunc { - return func() (interface{}, string, error) { - obj, err := client.GlobalDnsProvider.ByID(globalDNSProviderID) - if err != nil { - if IsNotFound(err) { - return obj, "removed", nil - } - return nil, "", err - } - - if obj.Removed != "" { - return obj, "removed", nil - } - - return obj, "active", nil - } -} diff --git a/rancher2/resource_rancher2_global_dns_provider_test.go b/rancher2/resource_rancher2_global_dns_provider_test.go deleted file mode 100644 index 278425dd..00000000 --- a/rancher2/resource_rancher2_global_dns_provider_test.go +++ /dev/null @@ -1,371 +0,0 @@ -package rancher2 - -import ( - "fmt" - "testing" - "time" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" -) - -const ( - testAccRancher2GlobalDNSProviderType = "rancher2_global_dns_provider" -) - -var ( - testAccRancher2GlobalDNSProviderAlidnsConfig string - testAccRancher2GlobalDNSProviderAlidnsUpdateConfig string - testAccRancher2GlobalDNSProviderCloudflareConfig string - testAccRancher2GlobalDNSProviderCloudflareUpdateConfig string - testAccRancher2GlobalDNSProviderRoute53Config string - testAccRancher2GlobalDNSProviderRoute53UpdateConfig string -) - -func init() { - testAccRancher2GlobalDNSProviderAlidnsConfig = ` -resource "` + testAccRancher2GlobalDNSProviderType + `" "foo-alidns" { - name = "foo-alidns" - root_domain = "example.com" - alidns_config { - access_key = "YYYYYYYYYYYYYYYYYYYY" - secret_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - } -} -` - testAccRancher2GlobalDNSProviderAlidnsUpdateConfig = ` -resource "` + testAccRancher2GlobalDNSProviderType + `" "foo-alidns" { - name = "foo-alidns-update" - root_domain = "update.example.com" - alidns_config { - access_key = "XXXXXXXXXXXXXXXXXXXX" - secret_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - } -} - ` - testAccRancher2GlobalDNSProviderCloudflareConfig = ` -resource "` + testAccRancher2GlobalDNSProviderType + `" "foo-cloudflare" { - name = "foo-cloudflare" - root_domain = "example.com" - cloudflare_config { - api_email = "test@test.local" - api_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - } -} -` - testAccRancher2GlobalDNSProviderCloudflareUpdateConfig = ` -resource "` + testAccRancher2GlobalDNSProviderType + `" "foo-cloudflare" { - name = "foo-cloudflare-update" - root_domain = "update.example.com" - cloudflare_config { - api_email = "test-update@test.local" - api_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - } -} - ` - testAccRancher2GlobalDNSProviderRoute53Config = ` -resource "` + testAccRancher2GlobalDNSProviderType + `" "foo-route53" { - name = "foo-route53" - root_domain = "example.com" - route53_config { - access_key = "YYYYYYYYYYYYYYYYYYYY" - secret_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - zone_type = "private" - region = "us-east-1" - } -} -` - testAccRancher2GlobalDNSProviderRoute53UpdateConfig = ` -resource "` + testAccRancher2GlobalDNSProviderType + `" "foo-route53" { - name = "foo-route53-update" - root_domain = "update.example.com" - route53_config { - access_key = "XXXXXXXXXXXXXXXXXXXX" - secret_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" - zone_type = "public" - region = "us-east-1" - } -} - ` -} - -func TestAccRancher2GlobalDNSProviderAlidns_basic(t *testing.T) { - var globalDNSProvider *managementClient.GlobalDnsProvider - - resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2GlobalDNSProviderAlidnsConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2GlobalDNSProviderExists(testAccRancher2GlobalDNSProviderType+".foo-alidns", globalDNSProvider), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-alidns", "name", "foo-alidns"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-alidns", "dns_provider", globalDNSProviderAlidnsKind), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-alidns", "root_domain", "example.com"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-alidns", "alidns_config.0.access_key", "YYYYYYYYYYYYYYYYYYYY"), - ), - }, - { - Config: testAccRancher2GlobalDNSProviderAlidnsUpdateConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2GlobalDNSProviderExists(testAccRancher2GlobalDNSProviderType+".foo-alidns", globalDNSProvider), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-alidns", "name", "foo-alidns-update"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-alidns", "dns_provider", globalDNSProviderAlidnsKind), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-alidns", "root_domain", "update.example.com"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-alidns", "alidns_config.0.access_key", "XXXXXXXXXXXXXXXXXXXX"), - ), - }, - { - Config: testAccRancher2GlobalDNSProviderAlidnsConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2GlobalDNSProviderExists(testAccRancher2GlobalDNSProviderType+".foo-alidns", globalDNSProvider), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-alidns", "name", "foo-alidns"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-alidns", "dns_provider", globalDNSProviderAlidnsKind), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-alidns", "root_domain", "example.com"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-alidns", "alidns_config.0.access_key", "YYYYYYYYYYYYYYYYYYYY"), - ), - }, - }, - }) -} - -func TestAccRancher2GlobalDNSProviderAlidns_disappears(t *testing.T) { - var globalDNSProvider *managementClient.GlobalDnsProvider - - resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2GlobalDNSProviderAlidnsConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2GlobalDNSProviderExists(testAccRancher2GlobalDNSProviderType+".foo-alidns", globalDNSProvider), - testAccRancher2GlobalDNSProviderDisappears(globalDNSProvider), - ), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func TestAccRancher2GlobalDNSProviderCloudflare_basic(t *testing.T) { - var globalDNSProvider *managementClient.GlobalDnsProvider - - resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2GlobalDNSProviderCloudflareConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2GlobalDNSProviderExists(testAccRancher2GlobalDNSProviderType+".foo-cloudflare", globalDNSProvider), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-cloudflare", "name", "foo-cloudflare"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-cloudflare", "dns_provider", globalDNSProviderCloudflareKind), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-cloudflare", "root_domain", "example.com"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-cloudflare", "cloudflare_config.0.api_email", "test@test.local"), - ), - }, - { - Config: testAccRancher2GlobalDNSProviderCloudflareUpdateConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2GlobalDNSProviderExists(testAccRancher2GlobalDNSProviderType+".foo-cloudflare", globalDNSProvider), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-cloudflare", "name", "foo-cloudflare-update"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-cloudflare", "dns_provider", globalDNSProviderCloudflareKind), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-cloudflare", "root_domain", "update.example.com"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-cloudflare", "cloudflare_config.0.api_email", "test-update@test.local"), - ), - }, - { - Config: testAccRancher2GlobalDNSProviderCloudflareConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2GlobalDNSProviderExists(testAccRancher2GlobalDNSProviderType+".foo-cloudflare", globalDNSProvider), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-cloudflare", "name", "foo-cloudflare"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-cloudflare", "dns_provider", globalDNSProviderCloudflareKind), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-cloudflare", "root_domain", "example.com"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-cloudflare", "cloudflare_config.0.api_email", "test@test.local"), - ), - }, - }, - }) -} - -func TestAccRancher2GlobalDNSProviderCloudflare_disappears(t *testing.T) { - var globalDNSProvider *managementClient.GlobalDnsProvider - - resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2GlobalDNSProviderCloudflareConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2GlobalDNSProviderExists(testAccRancher2GlobalDNSProviderType+".foo-cloudflare", globalDNSProvider), - testAccRancher2GlobalDNSProviderDisappears(globalDNSProvider), - ), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func TestAccRancher2GlobalDNSProviderRoute53_basic(t *testing.T) { - var globalDNSProvider *managementClient.GlobalDnsProvider - - resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2GlobalDNSProviderRoute53Config, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2GlobalDNSProviderExists(testAccRancher2GlobalDNSProviderType+".foo-route53", globalDNSProvider), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-route53", "name", "foo-route53"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-route53", "dns_provider", globalDNSProviderRoute53Kind), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-route53", "root_domain", "example.com"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-route53", "route53_config.0.access_key", "YYYYYYYYYYYYYYYYYYYY"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-route53", "route53_config.0.zone_type", "private"), - ), - }, - { - Config: testAccRancher2GlobalDNSProviderRoute53UpdateConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2GlobalDNSProviderExists(testAccRancher2GlobalDNSProviderType+".foo-route53", globalDNSProvider), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-route53", "name", "foo-route53-update"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-route53", "dns_provider", globalDNSProviderRoute53Kind), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-route53", "root_domain", "update.example.com"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-route53", "route53_config.0.access_key", "XXXXXXXXXXXXXXXXXXXX"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-route53", "route53_config.0.zone_type", "public"), - ), - }, - { - Config: testAccRancher2GlobalDNSProviderRoute53Config, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2GlobalDNSProviderExists(testAccRancher2GlobalDNSProviderType+".foo-route53", globalDNSProvider), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-route53", "name", "foo-route53"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-route53", "dns_provider", globalDNSProviderRoute53Kind), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-route53", "root_domain", "example.com"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-route53", "route53_config.0.access_key", "YYYYYYYYYYYYYYYYYYYY"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSProviderType+".foo-route53", "route53_config.0.zone_type", "private"), - ), - }, - }, - }) -} - -func TestAccRancher2GlobalDNSProviderRoute53_disappears(t *testing.T) { - var globalDNSProvider *managementClient.GlobalDnsProvider - - resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2GlobalDNSProviderRoute53Config, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2GlobalDNSProviderExists(testAccRancher2GlobalDNSProviderType+".foo-route53", globalDNSProvider), - testAccRancher2GlobalDNSProviderDisappears(globalDNSProvider), - ), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func testAccRancher2GlobalDNSProviderDisappears(pro *managementClient.GlobalDnsProvider) resource.TestCheckFunc { - return func(s *terraform.State) error { - for _, rs := range s.RootModule().Resources { - if rs.Type != testAccRancher2GlobalDNSProviderType { - continue - } - client, err := testAccProvider.Meta().(*Config).ManagementClient() - if err != nil { - return err - } - - pro, err = client.GlobalDnsProvider.ByID(rs.Primary.ID) - if err != nil { - if IsNotFound(err) { - return nil - } - return err - } - - err = client.GlobalDnsProvider.Delete(pro) - if err != nil { - return fmt.Errorf("Error removing Global DNS Provider: %s", err) - } - - stateConf := &resource.StateChangeConf{ - Pending: []string{"active"}, - Target: []string{"removed"}, - Refresh: globalDNSProviderStateRefreshFunc(client, pro.ID), - Timeout: 10 * time.Minute, - Delay: 1 * time.Second, - MinTimeout: 3 * time.Second, - } - - _, waitErr := stateConf.WaitForState() - if waitErr != nil { - return fmt.Errorf( - "[ERROR] waiting for Global DNS Provider (%s) to be removed: %s", pro.ID, waitErr) - } - } - return nil - - } -} - -func testAccCheckRancher2GlobalDNSProviderExists(n string, pro *managementClient.GlobalDnsProvider) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Global DNS Provider ID is set") - } - - client, err := testAccProvider.Meta().(*Config).ManagementClient() - if err != nil { - return err - } - - foundPro, err := client.GlobalDnsProvider.ByID(rs.Primary.ID) - if err != nil { - if IsNotFound(err) { - return fmt.Errorf("Global DNS Provider not found") - } - return err - } - - pro = foundPro - - return nil - } -} - -func testAccCheckRancher2GlobalDNSProviderDestroy(s *terraform.State) error { - for _, rs := range s.RootModule().Resources { - if rs.Type != testAccRancher2GlobalDNSProviderType { - continue - } - client, err := testAccProvider.Meta().(*Config).ManagementClient() - if err != nil { - return err - } - - _, err = client.GlobalDnsProvider.ByID(rs.Primary.ID) - if err != nil { - if IsNotFound(err) { - return nil - } - return err - } - return fmt.Errorf("Global DNS Provider still exists") - } - return nil -} diff --git a/rancher2/resource_rancher2_global_dns_test.go b/rancher2/resource_rancher2_global_dns_test.go deleted file mode 100644 index 75ba241b..00000000 --- a/rancher2/resource_rancher2_global_dns_test.go +++ /dev/null @@ -1,211 +0,0 @@ -package rancher2 - -import ( - "fmt" - "testing" - "time" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" -) - -const ( - testAccRancher2GlobalDNSType = "rancher2_global_dns" -) - -var ( - testAccRancher2GlobalDNS string - testAccRancher2GlobalDNSUpdate string - testAccRancher2GlobalDNSConfig string - testAccRancher2GlobalDNSUpdateConfig string -) - -func init() { - testAccRancher2GlobalDNS = `data "rancher2_project" "default" { - cluster_id = "` + testAccRancher2ClusterID + `" - name = "Default" -} -resource "` + testAccRancher2GlobalDNSType + `" "foo" { - name = "foo" - fqdn = "foo.example.com" - provider_id = rancher2_global_dns_provider.foo-route53.id - project_ids = [data.rancher2_project.default.id] - ttl = 500 -} -` - - testAccRancher2GlobalDNSUpdate = `data "rancher2_project" "default" { - cluster_id = "` + testAccRancher2ClusterID + `" - name = "Default" -} -data "rancher2_project" "system" { - cluster_id = "` + testAccRancher2ClusterID + `" - name = "System" -} -resource "` + testAccRancher2GlobalDNSType + `" "foo" { - name = "foo-update" - fqdn = "foo-update.example.com" - provider_id = rancher2_global_dns_provider.foo-route53.id - project_ids = [data.rancher2_project.default.id,data.rancher2_project.system.id] - ttl = 600 -} -` - - testAccRancher2GlobalDNSConfig = testAccRancher2GlobalDNSProviderRoute53Config + testAccRancher2GlobalDNS - testAccRancher2GlobalDNSUpdateConfig = testAccRancher2GlobalDNSProviderRoute53Config + testAccRancher2GlobalDNSUpdate -} - -func TestAccRancher2GlobalDNS_basic(t *testing.T) { - var globalDNS *managementClient.GlobalDns - - resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalDNSDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2GlobalDNSConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2GlobalDNSExists(testAccRancher2GlobalDNSType+".foo", globalDNS), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSType+".foo", "name", "foo"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSType+".foo", "fqdn", "foo.example.com"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSType+".foo", "ttl", "500"), - ), - }, - { - Config: testAccRancher2GlobalDNSUpdateConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2GlobalDNSExists(testAccRancher2GlobalDNSType+".foo", globalDNS), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSType+".foo", "name", "foo-update"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSType+".foo", "fqdn", "foo-update.example.com"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSType+".foo", "ttl", "600"), - ), - }, - { - Config: testAccRancher2GlobalDNSConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2GlobalDNSExists(testAccRancher2GlobalDNSType+".foo", globalDNS), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSType+".foo", "name", "foo"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSType+".foo", "fqdn", "foo.example.com"), - resource.TestCheckResourceAttr(testAccRancher2GlobalDNSType+".foo", "ttl", "500"), - ), - }, - }, - }) -} - -func TestAccRancher2GlobalDNS_disappears(t *testing.T) { - var globalDNS *managementClient.GlobalDns - - resource.Test(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2GlobalDNSProviderDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2GlobalDNSConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2GlobalDNSExists(testAccRancher2GlobalDNSType+".foo", globalDNS), - testAccRancher2GlobalDNSDisappears(globalDNS), - ), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func testAccRancher2GlobalDNSDisappears(pro *managementClient.GlobalDns) resource.TestCheckFunc { - return func(s *terraform.State) error { - for _, rs := range s.RootModule().Resources { - if rs.Type != testAccRancher2GlobalDNSType { - continue - } - client, err := testAccProvider.Meta().(*Config).ManagementClient() - if err != nil { - return err - } - - pro, err = client.GlobalDns.ByID(rs.Primary.ID) - if err != nil { - if IsNotFound(err) { - return nil - } - return err - } - - err = client.GlobalDns.Delete(pro) - if err != nil { - return fmt.Errorf("Error removing Global DNS registry: %s", err) - } - - stateConf := &resource.StateChangeConf{ - Pending: []string{"active"}, - Target: []string{"removed"}, - Refresh: globalDNSStateRefreshFunc(client, pro.ID), - Timeout: 10 * time.Minute, - Delay: 1 * time.Second, - MinTimeout: 3 * time.Second, - } - - _, waitErr := stateConf.WaitForState() - if waitErr != nil { - return fmt.Errorf( - "[ERROR] waiting for Global DNS registry (%s) to be removed: %s", pro.ID, waitErr) - } - } - return nil - - } -} - -func testAccCheckRancher2GlobalDNSExists(n string, pro *managementClient.GlobalDns) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No Global DNS registry ID is set") - } - - client, err := testAccProvider.Meta().(*Config).ManagementClient() - if err != nil { - return err - } - - foundPro, err := client.GlobalDns.ByID(rs.Primary.ID) - if err != nil { - if IsNotFound(err) { - return fmt.Errorf("Global DNS registry not found") - } - return err - } - - pro = foundPro - - return nil - } -} - -func testAccCheckRancher2GlobalDNSDestroy(s *terraform.State) error { - for _, rs := range s.RootModule().Resources { - if rs.Type != testAccRancher2GlobalDNSType { - continue - } - client, err := testAccProvider.Meta().(*Config).ManagementClient() - if err != nil { - return err - } - - _, err = client.GlobalDns.ByID(rs.Primary.ID) - if err != nil { - if IsNotFound(err) { - return nil - } - return err - } - return fmt.Errorf("Global DNS registry still exists") - } - return nil -} diff --git a/rancher2/schema_global_dns.go b/rancher2/schema_global_dns.go deleted file mode 100644 index 66dd20c9..00000000 --- a/rancher2/schema_global_dns.go +++ /dev/null @@ -1,47 +0,0 @@ -package rancher2 - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -// Schemas - -func GlobalDNSFields() map[string]*schema.Schema { - s := map[string]*schema.Schema{ - "fqdn": { - Type: schema.TypeString, - Required: true, - }, - "provider_id": { - Type: schema.TypeString, - Required: true, - }, - "name": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - }, - "multi_cluster_app_id": { - Type: schema.TypeString, - Optional: true, - ConflictsWith: []string{"project_ids"}, - }, - "project_ids": { - Type: schema.TypeList, - Optional: true, - ConflictsWith: []string{"multi_cluster_app_id"}, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "ttl": { - Type: schema.TypeInt, - Optional: true, - Default: 300, - }, - } - for k, v := range commonAnnotationLabelFields() { - s[k] = v - } - - return s -} diff --git a/rancher2/schema_global_dns_provider.go b/rancher2/schema_global_dns_provider.go deleted file mode 100644 index ccbf526e..00000000 --- a/rancher2/schema_global_dns_provider.go +++ /dev/null @@ -1,142 +0,0 @@ -package rancher2 - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" -) - -const ( - globalDNSProviderAlidnsKind = "alidns" - globalDNSProviderCloudflareKind = "cloudflare" - globalDNSProviderRoute53Kind = "route53" - globalDNSProviderRoute53Private = "private" - globalDNSProviderRoute53Public = "public" -) - -var ( - globalDNSProviderKinds = []string{globalDNSProviderAlidnsKind, globalDNSProviderCloudflareKind, globalDNSProviderRoute53Kind} - globalDNSProviderRoute53Zones = []string{globalDNSProviderRoute53Private, globalDNSProviderRoute53Public} -) - -// Schemas - -func globalDNSProviderAliConfigSchema() map[string]*schema.Schema { - s := map[string]*schema.Schema{ - "access_key": { - Type: schema.TypeString, - Required: true, - }, - "secret_key": { - Type: schema.TypeString, - Required: true, - }, - } - - return s -} - -func globalDNSProviderCloudFareConfigSchema() map[string]*schema.Schema { - s := map[string]*schema.Schema{ - "api_email": { - Type: schema.TypeString, - Required: true, - }, - "api_key": { - Type: schema.TypeString, - Required: true, - }, - "proxy_setting": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - } - - return s -} - -func globalDNSProviderRoute53ConfigSchema() map[string]*schema.Schema { - s := map[string]*schema.Schema{ - "access_key": { - Type: schema.TypeString, - Required: true, - }, - "secret_key": { - Type: schema.TypeString, - Required: true, - }, - "credentials_path": { - Type: schema.TypeString, - Optional: true, - Default: "/.aws", - }, - "region": { - Type: schema.TypeString, - Optional: true, - Default: "us-west-2", - }, - "role_arn": { - Type: schema.TypeString, - Optional: true, - }, - "zone_type": { - Type: schema.TypeString, - Optional: true, - Default: globalDNSProviderRoute53Public, - ValidateFunc: validation.StringInSlice(globalDNSProviderRoute53Zones, true), - }, - } - - return s -} - -func globalDNSProviderFields() map[string]*schema.Schema { - s := map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "root_domain": { - Type: schema.TypeString, - Required: true, - }, - "dns_provider": { - Type: schema.TypeString, - Computed: true, - }, - "alidns_config": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - ConflictsWith: []string{"cloudflare_config", "route53_config"}, - Elem: &schema.Resource{ - Schema: globalDNSProviderAliConfigSchema(), - }, - }, - "cloudflare_config": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - ConflictsWith: []string{"alidns_config", "route53_config"}, - Elem: &schema.Resource{ - Schema: globalDNSProviderCloudFareConfigSchema(), - }, - }, - "route53_config": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - ConflictsWith: []string{"alidns_config", "cloudflare_config"}, - Elem: &schema.Resource{ - Schema: globalDNSProviderRoute53ConfigSchema(), - }, - }, - } - - for k, v := range commonAnnotationLabelFields() { - s[k] = v - } - - return s -} diff --git a/rancher2/structure_global_dns.go b/rancher2/structure_global_dns.go deleted file mode 100644 index ccf81178..00000000 --- a/rancher2/structure_global_dns.go +++ /dev/null @@ -1,82 +0,0 @@ -package rancher2 - -import ( - "fmt" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" -) - -// Flatteners -func flattenGlobalDNS(d *schema.ResourceData, in *managementClient.GlobalDns) error { - if in == nil { - return nil - } - - d.SetId(in.ID) - d.Set("fqdn", in.FQDN) - d.Set("provider_id", in.ProviderID) - - if len(in.Name) > 0 { - d.Set("name", in.Name) - } - if len(in.MultiClusterAppID) > 0 { - d.Set("multi_cluster_app_id", in.MultiClusterAppID) - } - if in.ProjectIDs != nil && len(in.ProjectIDs) > 0 { - d.Set("project_ids", toArrayInterface(in.ProjectIDs)) - } - if in.TTL > 0 { - d.Set("ttl", int(in.TTL)) - } - - err := d.Set("annotations", toMapInterface(in.Annotations)) - if err != nil { - return err - } - - err = d.Set("labels", toMapInterface(in.Labels)) - if err != nil { - return err - } - - return nil - -} - -// Expanders -func expandGlobalDNS(in *schema.ResourceData) (*managementClient.GlobalDns, error) { - obj := &managementClient.GlobalDns{} - if in == nil { - return nil, fmt.Errorf("resource rancher2_global_dns_provider data cannot be nil") - } - - if v := in.Id(); len(v) > 0 { - obj.ID = v - } - - obj.Name = in.Get("name").(string) - obj.FQDN = in.Get("fqdn").(string) - obj.ProviderID = in.Get("provider_id").(string) - - if v, ok := in.Get("project_ids").([]interface{}); ok && len(v) > 0 { - obj.ProjectIDs = toArrayString(v) - } - - if v, ok := in.Get("multi_cluster_app_id").(string); ok && len(v) > 0 { - obj.MultiClusterAppID = v - } - - if v, ok := in.Get("ttl").(int); ok && v > 0 { - obj.TTL = int64(v) - } - - if v, ok := in.Get("annotations").(map[string]interface{}); ok && len(v) > 0 { - obj.Annotations = toMapString(v) - } - - if v, ok := in.Get("labels").(map[string]interface{}); ok && len(v) > 0 { - obj.Labels = toMapString(v) - } - - return obj, nil -} diff --git a/rancher2/structure_global_dns_provider.go b/rancher2/structure_global_dns_provider.go deleted file mode 100644 index 547d90c2..00000000 --- a/rancher2/structure_global_dns_provider.go +++ /dev/null @@ -1,229 +0,0 @@ -package rancher2 - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" -) - -// Flatteners - -func flattenAliDNSProvider(in *managementClient.AlidnsProviderConfig, p []interface{}) []interface{} { - var obj map[string]interface{} - if len(p) == 0 || p[0] == nil { - obj = make(map[string]interface{}) - } else { - obj = p[0].(map[string]interface{}) - } - if in == nil { - return []interface{}{} - } - - if len(in.AccessKey) > 0 { - obj["access_key"] = in.AccessKey - } - - return []interface{}{obj} -} - -func flattenCloudFlareDNSProvider(in *managementClient.CloudflareProviderConfig, p []interface{}) []interface{} { - var obj map[string]interface{} - if len(p) == 0 || p[0] == nil { - obj = make(map[string]interface{}) - } else { - obj = p[0].(map[string]interface{}) - } - if in == nil { - return []interface{}{} - } - - if len(in.APIEmail) > 0 { - obj["api_email"] = in.APIEmail - } - - if in.ProxySetting != nil { - obj["proxy_setting"] = *in.ProxySetting - } - - return []interface{}{obj} -} - -func flattenRoute53DNSProvider(in *managementClient.Route53ProviderConfig, p []interface{}) []interface{} { - var obj map[string]interface{} - if len(p) == 0 || p[0] == nil { - obj = make(map[string]interface{}) - } else { - obj = p[0].(map[string]interface{}) - } - if in == nil { - return []interface{}{} - } - - if len(in.AccessKey) > 0 { - obj["access_key"] = in.AccessKey - } - if len(in.CredentialsPath) > 0 { - obj["credentials_path"] = in.CredentialsPath - } - if len(in.Region) > 0 { - obj["region"] = in.Region - } - if len(in.RoleArn) > 0 { - obj["role_arn"] = in.RoleArn - } - if len(in.ZoneType) > 0 { - obj["zone_type"] = in.ZoneType - } - - return []interface{}{obj} -} - -func flattenGlobalDNSProvider(d *schema.ResourceData, in *managementClient.GlobalDnsProvider) error { - if in == nil { - return nil - } - - d.SetId(in.ID) - d.Set("root_domain", in.RootDomain) - d.Set("name", in.Name) - - if in.AlidnsProviderConfig != nil { - err := d.Set("alidns_config", flattenAliDNSProvider(in.AlidnsProviderConfig, d.Get("alidns_config").([]interface{}))) - if err != nil { - return err - } - d.Set("dns_provider", globalDNSProviderAlidnsKind) - } - if in.CloudflareProviderConfig != nil { - err := d.Set("cloudflare_config", flattenCloudFlareDNSProvider(in.CloudflareProviderConfig, d.Get("cloudflare_config").([]interface{}))) - if err != nil { - return err - } - d.Set("dns_provider", globalDNSProviderCloudflareKind) - } - if in.Route53ProviderConfig != nil { - err := d.Set("route53_config", flattenRoute53DNSProvider(in.Route53ProviderConfig, d.Get("route53_config").([]interface{}))) - if err != nil { - return err - } - d.Set("dns_provider", globalDNSProviderRoute53Kind) - } - - err := d.Set("annotations", toMapInterface(in.Annotations)) - if err != nil { - return err - } - - err = d.Set("labels", toMapInterface(in.Labels)) - if err != nil { - return err - } - - return nil -} - -// Expanders - -func expandAliDNSConfig(p []interface{}) *managementClient.AlidnsProviderConfig { - obj := &managementClient.AlidnsProviderConfig{} - if len(p) == 0 || p[0] == nil { - return nil - } - in := p[0].(map[string]interface{}) - - if v, ok := in["access_key"].(string); ok && len(v) > 0 { - obj.AccessKey = v - } - - if v, ok := in["secret_key"].(string); ok && len(v) > 0 { - obj.SecretKey = v - } - - return obj -} - -func expandCloudFlareDNSConfig(p []interface{}) *managementClient.CloudflareProviderConfig { - obj := &managementClient.CloudflareProviderConfig{} - if len(p) == 0 || p[0] == nil { - return nil - } - in := p[0].(map[string]interface{}) - - obj.APIEmail = in["api_email"].(string) - obj.APIKey = in["api_key"].(string) - proxySetting := in["proxy_setting"].(bool) - obj.ProxySetting = &proxySetting - - return obj -} - -func expandRoute53DNSConfig(p []interface{}) *managementClient.Route53ProviderConfig { - obj := &managementClient.Route53ProviderConfig{} - if len(p) == 0 || p[0] == nil { - return nil - } - in := p[0].(map[string]interface{}) - - if v, ok := in["access_key"].(string); ok && len(v) > 0 { - obj.AccessKey = v - } - - if v, ok := in["secret_key"].(string); ok && len(v) > 0 { - obj.SecretKey = v - } - - if v, ok := in["credentials_path"].(string); ok && len(v) > 0 { - obj.CredentialsPath = v - } - - if v, ok := in["zone_type"].(string); ok { - obj.ZoneType = v - } - - if v, ok := in["role_arn"].(string); ok { - obj.RoleArn = v - } - - if v, ok := in["region"].(string); ok { - obj.Region = v - } - - return obj - -} - -func expandGlobalDNSProvider(in *schema.ResourceData) *managementClient.GlobalDnsProvider { - obj := &managementClient.GlobalDnsProvider{} - if in == nil { - return nil - } - - if v := in.Id(); len(v) > 0 { - obj.ID = v - } - - obj.Name = in.Get("name").(string) - obj.RootDomain = in.Get("root_domain").(string) - - if v, ok := in.Get("alidns_config").([]interface{}); ok && len(v) > 0 { - obj.AlidnsProviderConfig = expandAliDNSConfig(v) - in.Set("dns_provider", globalDNSProviderAlidnsKind) - } - if v, ok := in.Get("cloudflare_config").([]interface{}); ok && len(v) > 0 { - obj.CloudflareProviderConfig = expandCloudFlareDNSConfig(v) - in.Set("dns_provider", globalDNSProviderCloudflareKind) - } - if v, ok := in.Get("route53_config").([]interface{}); ok && len(v) > 0 { - obj.Route53ProviderConfig = expandRoute53DNSConfig(v) - in.Set("dns_provider", globalDNSProviderRoute53Kind) - } - - if v, ok := in.Get("annotations").(map[string]interface{}); ok && len(v) > 0 { - obj.Annotations = toMapString(v) - } - - if v, ok := in.Get("labels").(map[string]interface{}); ok && len(v) > 0 { - obj.Labels = toMapString(v) - } - - return obj -} diff --git a/rancher2/structure_global_dns_provider_test.go b/rancher2/structure_global_dns_provider_test.go deleted file mode 100644 index 4f6bc175..00000000 --- a/rancher2/structure_global_dns_provider_test.go +++ /dev/null @@ -1,204 +0,0 @@ -package rancher2 - -import ( - "reflect" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" - "github.com/stretchr/testify/assert" -) - -var ( - testAccRancher2GlobalDNSProviderAlidnsConf *managementClient.GlobalDnsProvider - testAccRancher2GlobalDNSProviderAlidnsInterface []interface{} - testAccRancher2GlobalDNSProviderCloudflareConf *managementClient.GlobalDnsProvider - testAccRancher2GlobalDNSProviderCloudflareInterface []interface{} - testAccRancher2GlobalDNSProviderRoute53Conf *managementClient.GlobalDnsProvider - testAccRancher2GlobalDNSProviderRoute53Interface []interface{} -) - -func init() { - testAccRancher2GlobalDNSProviderAlidnsConf = &managementClient.GlobalDnsProvider{ - Name: "name", - RootDomain: "root.domain", - AlidnsProviderConfig: &managementClient.AlidnsProviderConfig{ - AccessKey: "XXXXXXXXXX", - SecretKey: "YYYYYYYYYY", - }, - Annotations: map[string]string{ - "node_one": "one", - "node_two": "two", - }, - Labels: map[string]string{ - "option1": "value1", - "option2": "value2", - }, - } - testAccRancher2GlobalDNSProviderAlidnsInterface = []interface{}{ - map[string]interface{}{ - "name": "name", - "root_domain": "root.domain", - "alidns_config": []interface{}{ - map[string]interface{}{ - "access_key": "XXXXXXXXXX", - "secret_key": "YYYYYYYYYY", - }, - }, - "annotations": map[string]interface{}{ - "node_one": "one", - "node_two": "two", - }, - "labels": map[string]interface{}{ - "option1": "value1", - "option2": "value2", - }, - }, - } - testAccRancher2GlobalDNSProviderCloudflareConf = &managementClient.GlobalDnsProvider{ - Name: "name", - RootDomain: "root.domain", - CloudflareProviderConfig: &managementClient.CloudflareProviderConfig{ - APIEmail: "XXXXXXXXXX", - APIKey: "YYYYYYYYYY", - ProxySetting: newTrue(), - }, - Annotations: map[string]string{ - "node_one": "one", - "node_two": "two", - }, - Labels: map[string]string{ - "option1": "value1", - "option2": "value2", - }, - } - testAccRancher2GlobalDNSProviderCloudflareInterface = []interface{}{ - map[string]interface{}{ - "name": "name", - "root_domain": "root.domain", - "cloudflare_config": []interface{}{ - map[string]interface{}{ - "api_email": "XXXXXXXXXX", - "api_key": "YYYYYYYYYY", - "proxy_setting": true, - }, - }, - "annotations": map[string]interface{}{ - "node_one": "one", - "node_two": "two", - }, - "labels": map[string]interface{}{ - "option1": "value1", - "option2": "value2", - }, - }, - } - testAccRancher2GlobalDNSProviderRoute53Conf = &managementClient.GlobalDnsProvider{ - Name: "name", - RootDomain: "root.domain", - Route53ProviderConfig: &managementClient.Route53ProviderConfig{ - AccessKey: "XXXXXXXXXX", - SecretKey: "YYYYYYYYYY", - CredentialsPath: "credPath", - Region: "region", - RoleArn: "role", - ZoneType: "private", - }, - Annotations: map[string]string{ - "node_one": "one", - "node_two": "two", - }, - Labels: map[string]string{ - "option1": "value1", - "option2": "value2", - }, - } - testAccRancher2GlobalDNSProviderRoute53Interface = []interface{}{ - map[string]interface{}{ - "name": "name", - "root_domain": "root.domain", - "route53_config": []interface{}{ - map[string]interface{}{ - "access_key": "XXXXXXXXXX", - "secret_key": "YYYYYYYYYY", - "credentials_path": "credPath", - "region": "region", - "role_arn": "role", - "zone_type": "private", - }, - }, - "annotations": map[string]interface{}{ - "node_one": "one", - "node_two": "two", - }, - "labels": map[string]interface{}{ - "option1": "value1", - "option2": "value2", - }, - }, - } -} - -func TestFlattenGlobalDnsProvider(t *testing.T) { - - cases := []struct { - Input *managementClient.GlobalDnsProvider - ExpectedOutput []interface{} - }{ - { - testAccRancher2GlobalDNSProviderAlidnsConf, - testAccRancher2GlobalDNSProviderAlidnsInterface, - }, - { - testAccRancher2GlobalDNSProviderCloudflareConf, - testAccRancher2GlobalDNSProviderCloudflareInterface, - }, - { - testAccRancher2GlobalDNSProviderRoute53Conf, - testAccRancher2GlobalDNSProviderRoute53Interface, - }, - } - - for _, tc := range cases { - output := schema.TestResourceDataRaw(t, globalDNSProviderFields(), tc.ExpectedOutput[0].(map[string]interface{})) - err := flattenGlobalDNSProvider(output, tc.Input) - if err != nil { - assert.FailNow(t, "[ERROR] on flattener: %#v", err) - } - expectedOutput := map[string]interface{}{} - for k := range tc.ExpectedOutput[0].(map[string]interface{}) { - expectedOutput[k] = output.Get(k) - } - if !reflect.DeepEqual([]interface{}{expectedOutput}, tc.ExpectedOutput) { - assert.FailNow(t, "Unexpected output from flattener.\nExpected: %#v\nGiven: %#v", - tc.ExpectedOutput, []interface{}{expectedOutput}) - } - } -} - -func TestExpandGlobalDnsProvider(t *testing.T) { - - cases := []struct { - Input []interface{} - ExpectedOutput *managementClient.GlobalDnsProvider - }{ - { - testAccRancher2GlobalDNSProviderAlidnsInterface, - testAccRancher2GlobalDNSProviderAlidnsConf, - }, - { - testAccRancher2GlobalDNSProviderCloudflareInterface, - testAccRancher2GlobalDNSProviderCloudflareConf, - }, - { - testAccRancher2GlobalDNSProviderRoute53Interface, - testAccRancher2GlobalDNSProviderRoute53Conf, - }, - } - - for _, tc := range cases { - inputResourceData := schema.TestResourceDataRaw(t, globalDNSProviderFields(), tc.Input[0].(map[string]interface{})) - output := expandGlobalDNSProvider(inputResourceData) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from expander.") - } -} diff --git a/rancher2/structure_global_dns_test.go b/rancher2/structure_global_dns_test.go deleted file mode 100644 index 3695605d..00000000 --- a/rancher2/structure_global_dns_test.go +++ /dev/null @@ -1,85 +0,0 @@ -package rancher2 - -import ( - "reflect" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" - "github.com/stretchr/testify/assert" -) - -var ( - testGlobalGlobalDNSConf *managementClient.GlobalDns - testGlobalGlobalDNSInterface map[string]interface{} -) - -func init() { - testGlobalGlobalDNSConf = &managementClient.GlobalDns{ - FQDN: "test.non.example.com", - ProviderID: "cattle-global:foo-test2", - MultiClusterAppID: "mca", - Name: "test-entry", - ProjectIDs: []string{"proj1", "proj2"}, - TTL: int64(600), - } - testGlobalGlobalDNSInterface = map[string]interface{}{ - "fqdn": "test.non.example.com", - "provider_id": "cattle-global:foo-test2", - "multi_cluster_app_id": "mca", - "name": "test-entry", - "project_ids": []interface{}{"proj1", "proj2"}, - "ttl": 600, - } -} - -func TestFlattenGlobalDNS(t *testing.T) { - - cases := []struct { - Input *managementClient.GlobalDns - ExpectedOutput map[string]interface{} - }{ - { - testGlobalGlobalDNSConf, - testGlobalGlobalDNSInterface, - }, - } - - for _, tc := range cases { - output := schema.TestResourceDataRaw(t, GlobalDNSFields(), map[string]interface{}{}) - err := flattenGlobalDNS(output, tc.Input) - if err != nil { - assert.FailNow(t, "[ERROR] on flattener: %#v", err) - } - expectedOutput := map[string]interface{}{} - for k := range tc.ExpectedOutput { - expectedOutput[k] = output.Get(k) - } - if !reflect.DeepEqual(expectedOutput, tc.ExpectedOutput) { - assert.FailNow(t, "Unexpected output from flattener.\nExpected: %#v\nGiven: %#v", - expectedOutput, output) - } - } -} - -func TestExpandGlobalDNS(t *testing.T) { - - cases := []struct { - Input map[string]interface{} - ExpectedOutput *managementClient.GlobalDns - }{ - { - testGlobalGlobalDNSInterface, - testGlobalGlobalDNSConf, - }, - } - - for _, tc := range cases { - inputResourceData := schema.TestResourceDataRaw(t, GlobalDNSFields(), tc.Input) - output, err := expandGlobalDNS(inputResourceData) - if err != nil { - assert.FailNow(t, "[ERROR] on expander: %#v", err) - } - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from expander.") - } -} diff --git a/website/rancher2.erb b/website/rancher2.erb index 2f7544fe..7eccc6d0 100644 --- a/website/rancher2.erb +++ b/website/rancher2.erb @@ -49,9 +49,6 @@ > rancher2_global_role_binding - > - rancher2_global_dns_provider - > rancher2_multi_cluster_app @@ -160,12 +157,6 @@ > rancher2_etcd_backup - > - rancher2_global_dns_entry - - > - rancher2_global_dns_provider - > rancher2_global_role_binding