diff --git a/docs/data-sources/notifier.md b/docs/data-sources/notifier.md deleted file mode 100644 index 8f0451c1..00000000 --- a/docs/data-sources/notifier.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -page_title: "rancher2_notifier Data Source" ---- - -# rancher2\_notifier Data Source - -Use this data source to retrieve information about a Rancher v2 notifier. - -## Example Usage - -``` -data "rancher2_notifier" "foo" { - name = "foo" - cluster_id = "" -} -``` - -## Argument Reference - -* `name` - (Required) The name of the notifier (string) -* `cluster_id` - (Required) The cluster id where create notifier (string) - -## Attributes Reference - -* `id` - (Computed) The ID of the resource (string) -* `description` - (Computed) The notifier description (string) -* `send_resolved` - (Computed) If the notifier sends resolved notifications (bool) -* `dingtalk_config` - (Computed) Dingtalk config for notifier (list maxitems:1) -* `msteams_config` - (Computed) MSTeams config for notifier (list maxitems:1) -* `pagerduty_config` - (Computed) Pagerduty config for notifier (list maxitems:1) -* `slack_config` - (Computed) Slack config for notifier (list maxitems:1) -* `smtp_config` - (Computed) SMTP config for notifier (list maxitems:1) -* `webhook_config` - (Computed) Webhook config for notifier (list maxitems:1) -* `wechat_config` - (Computed) Wechat config for notifier (list maxitems:1) -* `annotations` - (Computed) Annotations for notifier object (map) -* `labels` - (Computed) Labels for notifier object (map) diff --git a/docs/resources/notifier.md b/docs/resources/notifier.md deleted file mode 100644 index 5cb29ea4..00000000 --- a/docs/resources/notifier.md +++ /dev/null @@ -1,127 +0,0 @@ ---- -page_title: "rancher2_notifier Resource" ---- - -# rancher2\_notifier Resource - -Provides a Rancher v2 Notifier resource. This can be used to create notifiers for Rancher v2 environments and retrieve their information. - -## Example Usage - -```hcl -# Create a new rancher2 Notifier -resource "rancher2_notifier" "foo" { - name = "foo" - cluster_id = "" - description = "Terraform notifier acceptance test" - send_resolved = "true" - pagerduty_config { - service_key = "XXXXXXXX" - proxy_url = "http://proxy.test.io" - } -} -``` - -## Argument Reference - -The following arguments are supported: - -* `name` - (Required) The name of the notifier (string) -* `cluster_id` - (Required/ForceNew) The cluster id where create notifier (string) -* `description` - (Optional) The notifier description (string) -* `send_resolved` = (Optional) Enable the notifier to send resolved notifications. Default `false` (bool) -* `dingtalk_config` - (Optional) Dingtalk config for notifier (list maxitems:1) -* `msteams_config` - (Optional) MSTeams config for notifier (list maxitems:1) -* `pagerduty_config` - (Optional) Pagerduty config for notifier (list maxitems:1) -* `slack_config` - (Optional) Slack config for notifier (list maxitems:1) -* `smtp_config` - (Optional) SMTP config for notifier (list maxitems:1) -* `webhook_config` - (Optional) Webhook config for notifier (list maxitems:1) -* `wechat_config` - (Optional) Wechat config for notifier (list maxitems:1) -* `annotations` - (Optional/Computed) Annotations for notifier object (map) -* `labels` - (Optional/Computed) Labels for notifier object (map) - -## Attributes Reference - -The following attributes are exported: - -* `id` - (Computed) The ID of the resource (string) - -## Nested blocks - -### `dingtalk_config` - -#### Arguments - -* `url` - (Required) Dingtalk url (string) -* `proxy_url` - (Optional) Dingtalk proxy url (string) -* `secret` - (Optional) Secret for url sign enable (string) - -### `msteams_config` - -#### Arguments - -* `url` - (Required) MSTeams url (string) -* `proxy_url` - (Optional) MSTeams proxy url (string) - -### `pagerduty_config` - -#### Arguments - -* `service_key` - (Required) Pagerduty service key (string) -* `proxy_url` - (Optional) Pagerduty proxy url (string) - -### `slack_config` - -#### Arguments - -* `default_recipient` - (Required) Slack default recipient (string) -* `url` - (Required) Slack url (string) -* `proxy_url` - (Optional) Slack proxy url (string) - -### `smtp_config` - -* `default_recipient` - (Required) SMTP default recipient (string) -* `host` - (Required) SMTP host (string) -* `port` - (Required) SMTP port (int) -* `sender` - (Required) SMTP sender (string) -* `password` - (Optional/Sensitive) SMTP password (string) -* `tls` - (Optional/Sensitive) SMTP tls. Default `true` (bool) -* `username` - (Optional/Sensitive) SMTP username (string) - -#### Arguments - -### `webhook_config` - -* `url` - (Required) Webhook url (string) -* `proxy_url` - (Optional) Webhook proxy url (string) - -#### Arguments - -### `wechat_config` - -#### Arguments - -* `agent` - (Required) Wechat agent ID (string) -* `corp` - (Required) Wechat corporation ID (string) -* `default_recipient` - (Required) Wechat default recipient (string) -* `secret` - (Required/Sensitive) Wechat agent ID (string) -* `proxy_url` - (Optional) Wechat proxy url (string) -* `recipient_type` - (Optional) Wechat recipient type. Allowed values: `party` | `tag` | `user` (string) - -## Timeouts - -`rancher2_notifier` provides the following -[Timeouts](https://www.terraform.io/docs/configuration/resources.html#operation-timeouts) configuration options: - -- `create` - (Default `10 minutes`) Used for creating notifiers. -- `update` - (Default `10 minutes`) Used for notifier modifications. -- `delete` - (Default `10 minutes`) Used for deleting notifiers. - -## Import - -Notifiers can be imported using the Rancher nNtifier ID - -``` -$ terraform import rancher2_notifier.foo <notifier_id> -``` - diff --git a/rancher2/0_provider_upgrade_test.go b/rancher2/0_provider_upgrade_test.go index d979749b..1781f27a 100644 --- a/rancher2/0_provider_upgrade_test.go +++ b/rancher2/0_provider_upgrade_test.go @@ -128,11 +128,6 @@ provider "rancher2" { ` + testAccRancher2NodeTemplateOpennebulaConfig + ` ` + testAccRancher2NodeTemplateOpenstack + ` ` + testAccRancher2NodeTemplateVsphere + ` -` + testAccRancher2NotifierPagerduty + ` -` + testAccRancher2NotifierSlack + ` -` + testAccRancher2NotifierSMTP + ` -` + testAccRancher2NotifierWebhook + ` -` + testAccRancher2NotifierWechat + ` ` + testAccCheckRancher2PodSecurityPolicyTemplate + ` ` + testAccRancher2ProjectRoleTemplateBinding + ` ` + testAccRancher2Project + ` @@ -175,13 +170,6 @@ provider "rancher2" { ` + testAccRancher2NodeTemplateOpennebulaConfig + ` ` + testAccRancher2NodeTemplateOpenstack + ` ` + testAccRancher2NodeTemplateVsphere + ` -` + testAccRancher2NotifierDingtalk + ` -` + testAccRancher2NotifierMSTeams + ` -` + testAccRancher2NotifierPagerduty + ` -` + testAccRancher2NotifierSlack + ` -` + testAccRancher2NotifierSMTP + ` -` + testAccRancher2NotifierWebhook + ` -` + testAccRancher2NotifierWechat + ` ` + testAccCheckRancher2PodSecurityPolicyTemplate + ` ` + testAccRancher2ProjectRoleTemplateBinding + ` ` + testAccRancher2Project + ` @@ -228,13 +216,6 @@ provider "rancher2" { ` + testAccRancher2NodeTemplateOpennebulaConfig + ` ` + testAccRancher2NodeTemplateOpenstack + ` ` + testAccRancher2NodeTemplateVsphere + ` -` + testAccRancher2NotifierDingtalk + ` -` + testAccRancher2NotifierMSTeams + ` -` + testAccRancher2NotifierPagerduty + ` -` + testAccRancher2NotifierSlack + ` -` + testAccRancher2NotifierSMTP + ` -` + testAccRancher2NotifierWebhook + ` -` + testAccRancher2NotifierWechat + ` ` + testAccCheckRancher2PodSecurityPolicyTemplate + ` ` + testAccRancher2ProjectRoleTemplateBinding + ` ` + testAccRancher2Project + ` @@ -285,13 +266,6 @@ provider "rancher2" { ` + testAccRancher2NodeTemplateOpennebulaConfig + ` ` + testAccRancher2NodeTemplateOpenstack + ` ` + testAccRancher2NodeTemplateVsphere + ` -` + testAccRancher2NotifierDingtalk + ` -` + testAccRancher2NotifierMSTeams + ` -` + testAccRancher2NotifierPagerduty + ` -` + testAccRancher2NotifierSlack + ` -` + testAccRancher2NotifierSMTP + ` -` + testAccRancher2NotifierWebhook + ` -` + testAccRancher2NotifierWechat + ` ` + testAccCheckRancher2PodSecurityPolicyTemplate + ` ` + testAccRancher2ProjectRoleTemplateBinding + ` ` + testAccRancher2Project + ` diff --git a/rancher2/config.go b/rancher2/config.go index 1f1d8140..247ae8a6 100644 --- a/rancher2/config.go +++ b/rancher2/config.go @@ -1831,45 +1831,3 @@ func (c *Config) DeleteCertificate(cert interface{}) error { return fmt.Errorf("[ERROR] Certificate type %s isn't supported", t) } } - -func (c *Config) GetRecipientByNotifier(id string) (*managementClient.Recipient, error) { - if len(id) == 0 { - return nil, fmt.Errorf("[ERROR] Notifier ID can't be nil") - } - - client, err := c.ManagementClient() - if err != nil { - return nil, err - } - - notifier, err := client.Notifier.ByID(id) - if err != nil { - return nil, err - } - - out := &managementClient.Recipient{} - - out.NotifierID = notifier.ID - if notifier.DingtalkConfig != nil { - out.NotifierType = recipientTypeDingtalk - } else if notifier.MSTeamsConfig != nil { - out.NotifierType = recipientTypeMsTeams - } else if notifier.PagerdutyConfig != nil { - out.NotifierType = recipientTypePagerduty - out.Recipient = notifier.PagerdutyConfig.ServiceKey - } else if notifier.SlackConfig != nil { - out.NotifierType = recipientTypeSlack - out.Recipient = notifier.SlackConfig.DefaultRecipient - } else if notifier.SMTPConfig != nil { - out.NotifierType = recipientTypeSMTP - out.Recipient = notifier.SMTPConfig.DefaultRecipient - } else if notifier.WebhookConfig != nil { - out.NotifierType = recipientTypeWebhook - out.Recipient = notifier.WebhookConfig.URL - } else if notifier.WechatConfig != nil { - out.NotifierType = recipientTypeWechat - out.Recipient = notifier.WechatConfig.DefaultRecipient - } - - return out, nil -} diff --git a/rancher2/data_source_rancher2_notifier.go b/rancher2/data_source_rancher2_notifier.go deleted file mode 100644 index 7d49880a..00000000 --- a/rancher2/data_source_rancher2_notifier.go +++ /dev/null @@ -1,133 +0,0 @@ -package rancher2 - -import ( - "fmt" - - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func dataSourceRancher2Notifier() *schema.Resource { - return &schema.Resource{ - Read: dataSourceRancher2NotifierRead, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - Description: "Notifier name", - }, - "cluster_id": { - Type: schema.TypeString, - Required: true, - Description: "Notifier cluster ID", - }, - "description": { - Type: schema.TypeString, - Computed: true, - Description: "Notifier description", - }, - "dingtalk_config": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - ConflictsWith: []string{"msteams_config", "pagerduty_config", "smtp_config", "slack_config", "webhook_config", "wechat_config"}, - Elem: &schema.Resource{ - Schema: notifierDingtalkConfigFields(), - }, - }, - "msteams_config": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - ConflictsWith: []string{"dingtalk_config", "pagerduty_config", "smtp_config", "slack_config", "webhook_config", "wechat_config"}, - Elem: &schema.Resource{ - Schema: notifierMSTeamsConfigFields(), - }, - }, - "pagerduty_config": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - ConflictsWith: []string{"dingtalk_config", "msteams_config", "smtp_config", "slack_config", "webhook_config", "wechat_config"}, - Elem: &schema.Resource{ - Schema: notifierPagerdutyConfigFields(), - }, - }, - "slack_config": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - ConflictsWith: []string{"dingtalk_config", "msteams_config", "pagerduty_config", "smtp_config", "webhook_config", "wechat_config"}, - Elem: &schema.Resource{ - Schema: notifierSlackConfigFields(), - }, - }, - "smtp_config": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - ConflictsWith: []string{"dingtalk_config", "msteams_config", "pagerduty_config", "slack_config", "webhook_config", "wechat_config"}, - Elem: &schema.Resource{ - Schema: notifierSMTPConfigFields(), - }, - }, - "webhook_config": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - ConflictsWith: []string{"dingtalk_config", "msteams_config", "pagerduty_config", "smtp_config", "slack_config", "wechat_config"}, - Elem: &schema.Resource{ - Schema: notifierWebhookConfigFields(), - }, - }, - "wechat_config": { - Type: schema.TypeList, - MaxItems: 1, - Computed: true, - ConflictsWith: []string{"dingtalk_config", "msteams_config", "pagerduty_config", "smtp_config", "slack_config", "webhook_config"}, - Elem: &schema.Resource{ - Schema: notifierWechatConfigFields(), - }, - }, - "annotations": { - Type: schema.TypeMap, - Computed: true, - }, - "labels": { - Type: schema.TypeMap, - Computed: true, - }, - }, - } -} - -func dataSourceRancher2NotifierRead(d *schema.ResourceData, meta interface{}) error { - client, err := meta.(*Config).ManagementClient() - if err != nil { - return err - } - - name := d.Get("name").(string) - clusterID := d.Get("cluster_id").(string) - - filters := map[string]interface{}{ - "name": name, - "clusterId": clusterID, - } - listOpts := NewListOpts(filters) - - notifiers, err := client.Notifier.List(listOpts) - if err != nil { - return err - } - - count := len(notifiers.Data) - if count <= 0 { - return fmt.Errorf("[ERROR] notifier with name \"%s\" and cluster ID \"%s\" not found", name, clusterID) - } - if count > 1 { - return fmt.Errorf("[ERROR] found %d notifier with name \"%s\" and cluster ID \"%s\"", count, name, clusterID) - } - - return flattenNotifier(d, ¬ifiers.Data[0]) -} diff --git a/rancher2/data_source_rancher2_notifier_test.go b/rancher2/data_source_rancher2_notifier_test.go deleted file mode 100644 index 60079df9..00000000 --- a/rancher2/data_source_rancher2_notifier_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package rancher2 - -import ( - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" -) - -func TestAccRancher2NotifierDataSource(t *testing.T) { - testAccCheckRancher2NotifierDataSourceConfig := testAccRancher2NotifierPagerdutyConfig + ` -data "` + testAccRancher2NotifierType + `" "foo" { - name = rancher2_notifier.foo-pagerduty.name - cluster_id = rancher2_notifier.foo-pagerduty.cluster_id -} -` - name := "data." + testAccRancher2NotifierType + ".foo" - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccCheckRancher2NotifierDataSourceConfig, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(name, "name", "foo-pagerduty"), - resource.TestCheckResourceAttr(name, "description", "Terraform notifier acceptance test"), - resource.TestCheckResourceAttr(name, "pagerduty_config.0.service_key", "XXXXXXXX"), - ), - }, - }, - }) -} diff --git a/rancher2/import_rancher2_notifier.go b/rancher2/import_rancher2_notifier.go deleted file mode 100644 index ec6bedff..00000000 --- a/rancher2/import_rancher2_notifier.go +++ /dev/null @@ -1,14 +0,0 @@ -package rancher2 - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -func resourceRancher2NotifierImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - err := resourceRancher2NotifierRead(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 42021ddb..eb3e3cde 100644 --- a/rancher2/provider.go +++ b/rancher2/provider.go @@ -143,7 +143,6 @@ func Provider() terraform.ResourceProvider { "rancher2_node_driver": resourceRancher2NodeDriver(), "rancher2_node_pool": resourceRancher2NodePool(), "rancher2_node_template": resourceRancher2NodeTemplate(), - "rancher2_notifier": resourceRancher2Notifier(), "rancher2_pod_security_admission_configuration_template": resourceRancher2PodSecurityAdmissionConfigurationTemplate(), "rancher2_pod_security_policy_template": resourceRancher2PodSecurityPolicyTemplate(), "rancher2_project": resourceRancher2Project(), @@ -179,7 +178,6 @@ func Provider() terraform.ResourceProvider { "rancher2_node_driver": dataSourceRancher2NodeDriver(), "rancher2_node_pool": dataSourceRancher2NodePool(), "rancher2_node_template": dataSourceRancher2NodeTemplate(), - "rancher2_notifier": dataSourceRancher2Notifier(), "rancher2_pod_security_admission_configuration_template": dataSourceRancher2PodSecurityAdmissionConfigurationTemplate(), "rancher2_pod_security_policy_template": dataSourceRancher2PodSecurityPolicyTemplate(), "rancher2_principal": dataSourceRancher2Principal(), diff --git a/rancher2/resource_rancher2_notifier.go b/rancher2/resource_rancher2_notifier.go deleted file mode 100644 index d24d94f0..00000000 --- a/rancher2/resource_rancher2_notifier.go +++ /dev/null @@ -1,191 +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 resourceRancher2Notifier() *schema.Resource { - return &schema.Resource{ - Create: resourceRancher2NotifierCreate, - Read: resourceRancher2NotifierRead, - Update: resourceRancher2NotifierUpdate, - Delete: resourceRancher2NotifierDelete, - Importer: &schema.ResourceImporter{ - State: resourceRancher2NotifierImport, - }, - - Schema: notifierFields(), - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(10 * time.Minute), - Update: schema.DefaultTimeout(10 * time.Minute), - Delete: schema.DefaultTimeout(10 * time.Minute), - }, - } -} - -func resourceRancher2NotifierCreate(d *schema.ResourceData, meta interface{}) error { - notifier, err := expandNotifier(d) - if err != nil { - return err - } - - log.Printf("[INFO] Creating Notifier %s", notifier.Name) - - client, err := meta.(*Config).ManagementClient() - if err != nil { - return err - } - - newNotifier, err := client.Notifier.Create(notifier) - if err != nil { - return err - } - - d.SetId(newNotifier.ID) - - stateConf := &resource.StateChangeConf{ - Pending: []string{}, - Target: []string{"active"}, - Refresh: notifierStateRefreshFunc(client, newNotifier.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 notifier (%s) to be created: %s", newNotifier.ID, waitErr) - } - - return resourceRancher2NotifierRead(d, meta) -} - -func resourceRancher2NotifierRead(d *schema.ResourceData, meta interface{}) error { - log.Printf("[INFO] Refreshing Notifier ID %s", d.Id()) - client, err := meta.(*Config).ManagementClient() - if err != nil { - return err - } - - return resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError { - notifier, err := client.Notifier.ByID(d.Id()) - if err != nil { - if IsNotFound(err) || IsForbidden(err) { - log.Printf("[INFO] Notifier ID %s not found.", d.Id()) - d.SetId("") - return nil - } - return resource.NonRetryableError(err) - } - - if err = flattenNotifier(d, notifier); err != nil { - return resource.NonRetryableError(err) - } - - return nil - }) -} - -func resourceRancher2NotifierUpdate(d *schema.ResourceData, meta interface{}) error { - log.Printf("[INFO] Updating Notifier ID %s", d.Id()) - client, err := meta.(*Config).ManagementClient() - if err != nil { - return err - } - - notifier, err := client.Notifier.ByID(d.Id()) - if err != nil { - return err - } - - newNotifier, err := expandNotifier(d) - if err != nil { - return err - } - newNotifier.Links = notifier.Links - newNotifier, err = client.Notifier.Replace(newNotifier) - if err != nil { - return err - } - - stateConf := &resource.StateChangeConf{ - Pending: []string{"active"}, - Target: []string{"active"}, - Refresh: notifierStateRefreshFunc(client, newNotifier.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 notifier (%s) to be updated: %s", newNotifier.ID, waitErr) - } - - return resourceRancher2NotifierRead(d, meta) -} - -func resourceRancher2NotifierDelete(d *schema.ResourceData, meta interface{}) error { - log.Printf("[INFO] Deleting Notifier ID %s", d.Id()) - id := d.Id() - client, err := meta.(*Config).ManagementClient() - if err != nil { - return err - } - - notifier, err := client.Notifier.ByID(id) - if err != nil { - if IsNotFound(err) || IsForbidden(err) { - log.Printf("[INFO] Notifier ID %s not found.", d.Id()) - d.SetId("") - return nil - } - return err - } - - err = client.Notifier.Delete(notifier) - if err != nil { - return fmt.Errorf("Error removing Notifier: %s", err) - } - - log.Printf("[DEBUG] Waiting for notifier (%s) to be removed", id) - - stateConf := &resource.StateChangeConf{ - Pending: []string{"removing"}, - Target: []string{"removed"}, - Refresh: notifierStateRefreshFunc(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 notifier (%s) to be removed: %s", id, waitErr) - } - - d.SetId("") - return nil -} - -// notifierStateRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher Notifier. -func notifierStateRefreshFunc(client *managementClient.Client, notifierID string) resource.StateRefreshFunc { - return func() (interface{}, string, error) { - obj, err := client.Notifier.ByID(notifierID) - if err != nil { - if IsNotFound(err) || IsForbidden(err) { - return obj, "removed", nil - } - return nil, "", err - } - - return obj, obj.State, nil - } -} diff --git a/rancher2/resource_rancher2_notifier_test.go b/rancher2/resource_rancher2_notifier_test.go deleted file mode 100644 index 66c66ee2..00000000 --- a/rancher2/resource_rancher2_notifier_test.go +++ /dev/null @@ -1,799 +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 ( - testAccRancher2NotifierType = "rancher2_notifier" -) - -var ( - testAccRancher2NotifierDingtalk string - testAccRancher2NotifierDingtalkUpdate string - testAccRancher2NotifierDingtalkConfig string - testAccRancher2NotifierDingtalkUpdateConfig string - testAccRancher2NotifierMSTeams string - testAccRancher2NotifierMSTeamsUpdate string - testAccRancher2NotifierMSTeamsConfig string - testAccRancher2NotifierMSTeamsUpdateConfig string - testAccRancher2NotifierPagerduty string - testAccRancher2NotifierPagerdutyUpdate string - testAccRancher2NotifierPagerdutyConfig string - testAccRancher2NotifierPagerdutyUpdateConfig string - testAccRancher2NotifierSlack string - testAccRancher2NotifierSlackUpdate string - testAccRancher2NotifierSlackConfig string - testAccRancher2NotifierSlackUpdateConfig string - testAccRancher2NotifierSMTP string - testAccRancher2NotifierSMTPUpdate string - testAccRancher2NotifierSMTPConfig string - testAccRancher2NotifierSMTPUpdateConfig string - testAccRancher2NotifierWebhook string - testAccRancher2NotifierWebhookUpdate string - testAccRancher2NotifierWebhookConfig string - testAccRancher2NotifierWebhookUpdateConfig string - testAccRancher2NotifierWechat string - testAccRancher2NotifierWechatUpdate string - testAccRancher2NotifierWechatConfig string - testAccRancher2NotifierWechatUpdateConfig string -) - -func init() { - testAccRancher2NotifierDingtalk = ` -resource "` + testAccRancher2NotifierType + `" "foo-dingtalk" { - name = "foo-dingtalk" - cluster_id = rancher2_cluster_sync.testacc.cluster_id - send_resolved = "true" - description = "Terraform notifier acceptance test" - dingtalk_config { - url = "http://url.test.io" - proxy_url = "http://proxy.test.io" - } -} -` - testAccRancher2NotifierDingtalkUpdate = ` -resource "` + testAccRancher2NotifierType + `" "foo-dingtalk" { - name = "foo-dingtalk" - cluster_id = rancher2_cluster_sync.testacc.cluster_id - send_resolved = "false" - description = "Terraform notifier acceptance test - updated" - dingtalk_config { - url = "http://url2.test.io" - proxy_url = "http://proxy2.test.io" - } -} -` - testAccRancher2NotifierDingtalkConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2NotifierDingtalk - testAccRancher2NotifierDingtalkUpdateConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2NotifierDingtalkUpdate - testAccRancher2NotifierMSTeams = ` -resource "` + testAccRancher2NotifierType + `" "foo-msteams" { - name = "foo-msteams" - cluster_id = rancher2_cluster_sync.testacc.cluster_id - send_resolved = "true" - description = "Terraform notifier acceptance test" - msteams_config { - url = "http://url.test.io" - proxy_url = "http://proxy.test.io" - } -} -` - testAccRancher2NotifierMSTeamsUpdate = ` -resource "` + testAccRancher2NotifierType + `" "foo-msteams" { - name = "foo-msteams" - cluster_id = rancher2_cluster_sync.testacc.cluster_id - send_resolved = "false" - description = "Terraform notifier acceptance test - updated" - msteams_config { - url = "http://url2.test.io" - proxy_url = "http://proxy2.test.io" - } -} -` - testAccRancher2NotifierMSTeamsConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2NotifierMSTeams - testAccRancher2NotifierMSTeamsUpdateConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2NotifierMSTeamsUpdate - testAccRancher2NotifierPagerduty = ` -resource "` + testAccRancher2NotifierType + `" "foo-pagerduty" { - name = "foo-pagerduty" - cluster_id = rancher2_cluster_sync.testacc.cluster_id - send_resolved = "true" - description = "Terraform notifier acceptance test" - pagerduty_config { - service_key = "XXXXXXXX" - proxy_url = "http://proxy.test.io" - } -} -` - testAccRancher2NotifierPagerdutyUpdate = ` -resource "` + testAccRancher2NotifierType + `" "foo-pagerduty" { - name = "foo-pagerduty" - cluster_id = rancher2_cluster_sync.testacc.cluster_id - send_resolved = "false" - description = "Terraform notifier acceptance test - updated" - pagerduty_config { - service_key = "YYYYYYYY" - proxy_url = "http://proxy2.test.io" - } -} -` - testAccRancher2NotifierPagerdutyConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2NotifierPagerduty - testAccRancher2NotifierPagerdutyUpdateConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2NotifierPagerdutyUpdate - testAccRancher2NotifierSlack = ` -resource "` + testAccRancher2NotifierType + `" "foo-slack" { - name = "foo-slack" - cluster_id = rancher2_cluster_sync.testacc.cluster_id - send_resolved = "true" - description = "Terraform notifier acceptance test" - slack_config { - default_recipient = "XXXXXXXX" - url = "http://url.test.io" - proxy_url = "http://proxy.test.io" - } -} -` - testAccRancher2NotifierSlackUpdate = ` -resource "` + testAccRancher2NotifierType + `" "foo-slack" { - name = "foo-slack" - cluster_id = rancher2_cluster_sync.testacc.cluster_id - send_resolved = "false" - description = "Terraform notifier acceptance test - updated" - slack_config { - default_recipient = "YYYYYYYY" - url = "http://url2.test.io" - proxy_url = "http://proxy2.test.io" - } -} -` - testAccRancher2NotifierSlackConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2NotifierSlack - testAccRancher2NotifierSlackUpdateConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2NotifierSlackUpdate - testAccRancher2NotifierSMTP = ` -resource "` + testAccRancher2NotifierType + `" "foo-smtp" { - name = "foo-smtp" - cluster_id = rancher2_cluster_sync.testacc.cluster_id - send_resolved = "true" - description = "Terraform notifier acceptance test" - smtp_config { - default_recipient = "XXXXXXXX" - host = "host.test.io" - port = 25 - sender = "sender@test.io" - tls = "true" - } -} -` - testAccRancher2NotifierSMTPUpdate = ` -resource "` + testAccRancher2NotifierType + `" "foo-smtp" { - name = "foo-smtp" - cluster_id = rancher2_cluster_sync.testacc.cluster_id - send_resolved = "false" - description = "Terraform notifier acceptance test - updated" - smtp_config { - default_recipient = "YYYYYYYY" - host = "host2.test.io" - port = 25 - sender = "sender2@test.io" - tls = "true" - } -} -` - testAccRancher2NotifierSMTPConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2NotifierSMTP - testAccRancher2NotifierSMTPUpdateConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2NotifierSMTPUpdate - testAccRancher2NotifierWebhook = ` -resource "` + testAccRancher2NotifierType + `" "foo-webhook" { - name = "foo-webhook" - cluster_id = rancher2_cluster_sync.testacc.cluster_id - send_resolved = "true" - description = "Terraform notifier acceptance test" - webhook_config { - url = "http://url.test.io" - proxy_url = "http://proxy.test.io" - } -} -` - testAccRancher2NotifierWebhookUpdate = ` -resource "` + testAccRancher2NotifierType + `" "foo-webhook" { - name = "foo-webhook" - cluster_id = rancher2_cluster_sync.testacc.cluster_id - send_resolved = "false" - description = "Terraform notifier acceptance test - updated" - webhook_config { - url = "http://url2.test.io" - proxy_url = "http://proxy2.test.io" - } -} -` - testAccRancher2NotifierWebhookConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2NotifierWebhook - testAccRancher2NotifierWebhookUpdateConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2NotifierWebhookUpdate - testAccRancher2NotifierWechat = ` -resource "` + testAccRancher2NotifierType + `" "foo-wechat" { - name = "foo-wechat" - cluster_id = rancher2_cluster_sync.testacc.cluster_id - send_resolved = "true" - description = "Terraform notifier acceptance test" - wechat_config { - agent = "agent_id" - corp = "corp_id" - default_recipient = "XXXXXXXX" - secret = "XXXXXXXX" - proxy_url = "http://proxy.test.io" - } -} -` - testAccRancher2NotifierWechatUpdate = ` -resource "` + testAccRancher2NotifierType + `" "foo-wechat" { - name = "foo-wechat" - cluster_id = rancher2_cluster_sync.testacc.cluster_id - send_resolved = "false" - description = "Terraform notifier acceptance test - updated" - wechat_config { - agent = "agent_id" - corp = "corp_id" - default_recipient = "YYYYYYYY" - secret = "YYYYYYYY" - proxy_url = "http://proxy2.test.io" - } -} -` - testAccRancher2NotifierWechatConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2NotifierWechat - testAccRancher2NotifierWechatUpdateConfig = testAccCheckRancher2ClusterSyncTestacc + testAccRancher2NotifierWechatUpdate -} - -func TestAccRancher2Notifier_basic_Dingtalk(t *testing.T) { - var notifier *managementClient.Notifier - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2NotifierDingtalkConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-dingtalk", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-dingtalk", "name", "foo-dingtalk"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-dingtalk", "description", "Terraform notifier acceptance test"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-dingtalk", "send_resolved", "true"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-dingtalk", "dingtalk_config.0.url", "http://url.test.io"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-dingtalk", "dingtalk_config.0.proxy_url", "http://proxy.test.io"), - ), - }, - { - Config: testAccRancher2NotifierDingtalkUpdateConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-dingtalk", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-dingtalk", "name", "foo-dingtalk"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-dingtalk", "description", "Terraform notifier acceptance test - updated"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-dingtalk", "send_resolved", "false"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-dingtalk", "dingtalk_config.0.url", "http://url2.test.io"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-dingtalk", "dingtalk_config.0.proxy_url", "http://proxy2.test.io"), - ), - }, - { - Config: testAccRancher2NotifierDingtalkConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-dingtalk", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-dingtalk", "name", "foo-dingtalk"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-dingtalk", "description", "Terraform notifier acceptance test"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-dingtalk", "send_resolved", "true"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-dingtalk", "dingtalk_config.0.url", "http://url.test.io"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-dingtalk", "dingtalk_config.0.proxy_url", "http://proxy.test.io"), - ), - }, - }, - }) -} - -func TestAccRancher2Notifier_disappears_Dingtalk(t *testing.T) { - var notifier *managementClient.Notifier - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2NotifierDingtalkConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-dingtalk", notifier), - testAccRancher2NotifierDisappears(notifier), - ), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func TestAccRancher2Notifier_basic_MSTeams(t *testing.T) { - var notifier *managementClient.Notifier - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2NotifierMSTeamsConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-msteams", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-msteams", "name", "foo-msteams"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-msteams", "description", "Terraform notifier acceptance test"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-msteams", "send_resolved", "true"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-msteams", "msteams_config.0.url", "http://url.test.io"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-msteams", "msteams_config.0.proxy_url", "http://proxy.test.io"), - ), - }, - { - Config: testAccRancher2NotifierMSTeamsUpdateConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-msteams", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-msteams", "name", "foo-msteams"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-msteams", "description", "Terraform notifier acceptance test - updated"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-msteams", "send_resolved", "false"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-msteams", "msteams_config.0.url", "http://url2.test.io"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-msteams", "msteams_config.0.proxy_url", "http://proxy2.test.io"), - ), - }, - { - Config: testAccRancher2NotifierMSTeamsConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-msteams", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-msteams", "name", "foo-msteams"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-msteams", "description", "Terraform notifier acceptance test"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-msteams", "send_resolved", "true"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-msteams", "msteams_config.0.url", "http://url.test.io"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-msteams", "msteams_config.0.proxy_url", "http://proxy.test.io"), - ), - }, - }, - }) -} - -func TestAccRancher2Notifier_disappears_MSTeams(t *testing.T) { - var notifier *managementClient.Notifier - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2NotifierMSTeamsConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-msteams", notifier), - testAccRancher2NotifierDisappears(notifier), - ), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func TestAccRancher2Notifier_basic_Pagerduty(t *testing.T) { - var notifier *managementClient.Notifier - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2NotifierPagerdutyConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-pagerduty", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-pagerduty", "name", "foo-pagerduty"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-pagerduty", "description", "Terraform notifier acceptance test"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-pagerduty", "send_resolved", "true"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-pagerduty", "pagerduty_config.0.service_key", "XXXXXXXX"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-pagerduty", "pagerduty_config.0.proxy_url", "http://proxy.test.io"), - ), - }, - { - Config: testAccRancher2NotifierPagerdutyUpdateConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-pagerduty", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-pagerduty", "name", "foo-pagerduty"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-pagerduty", "description", "Terraform notifier acceptance test - updated"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-pagerduty", "send_resolved", "false"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-pagerduty", "pagerduty_config.0.proxy_url", "http://proxy2.test.io"), - ), - }, - { - Config: testAccRancher2NotifierPagerdutyConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-pagerduty", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-pagerduty", "name", "foo-pagerduty"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-pagerduty", "description", "Terraform notifier acceptance test"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-pagerduty", "send_resolved", "true"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-pagerduty", "pagerduty_config.0.service_key", "XXXXXXXX"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-pagerduty", "pagerduty_config.0.proxy_url", "http://proxy.test.io"), - ), - }, - }, - }) -} - -func TestAccRancher2Notifier_disappears_Pagerduty(t *testing.T) { - var notifier *managementClient.Notifier - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2NotifierPagerdutyConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-pagerduty", notifier), - testAccRancher2NotifierDisappears(notifier), - ), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func TestAccRancher2Notifier_basic_Slack(t *testing.T) { - var notifier *managementClient.Notifier - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2NotifierSlackConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-slack", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-slack", "name", "foo-slack"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-slack", "description", "Terraform notifier acceptance test"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-slack", "send_resolved", "true"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-slack", "slack_config.0.default_recipient", "XXXXXXXX"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-slack", "slack_config.0.url", "http://url.test.io"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-slack", "slack_config.0.proxy_url", "http://proxy.test.io"), - ), - }, - { - Config: testAccRancher2NotifierSlackUpdateConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-slack", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-slack", "name", "foo-slack"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-slack", "slack_config.0.default_recipient", "YYYYYYYY"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-slack", "slack_config.0.url", "http://url2.test.io"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-slack", "slack_config.0.proxy_url", "http://proxy2.test.io"), - ), - }, - { - Config: testAccRancher2NotifierSlackConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-slack", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-slack", "name", "foo-slack"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-slack", "description", "Terraform notifier acceptance test"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-slack", "send_resolved", "true"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-slack", "slack_config.0.default_recipient", "XXXXXXXX"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-slack", "slack_config.0.url", "http://url.test.io"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-slack", "slack_config.0.proxy_url", "http://proxy.test.io"), - ), - }, - }, - }) -} - -func TestAccRancher2Notifier_disappears_Slack(t *testing.T) { - var notifier *managementClient.Notifier - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2NotifierSlackConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-slack", notifier), - testAccRancher2NotifierDisappears(notifier), - ), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func TestAccRancher2Notifier_basic_SMTP(t *testing.T) { - var notifier *managementClient.Notifier - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2NotifierSMTPConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-smtp", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-smtp", "name", "foo-smtp"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-smtp", "description", "Terraform notifier acceptance test"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-smtp", "send_resolved", "true"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-smtp", "smtp_config.0.default_recipient", "XXXXXXXX"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-smtp", "smtp_config.0.host", "host.test.io"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-smtp", "smtp_config.0.sender", "sender@test.io"), - ), - }, - { - Config: testAccRancher2NotifierSMTPUpdateConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-smtp", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-smtp", "name", "foo-smtp"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-smtp", "smtp_config.0.default_recipient", "YYYYYYYY"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-smtp", "smtp_config.0.host", "host2.test.io"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-smtp", "smtp_config.0.sender", "sender2@test.io"), - ), - }, - { - Config: testAccRancher2NotifierSMTPConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-smtp", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-smtp", "name", "foo-smtp"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-smtp", "description", "Terraform notifier acceptance test"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-smtp", "send_resolved", "true"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-smtp", "smtp_config.0.default_recipient", "XXXXXXXX"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-smtp", "smtp_config.0.host", "host.test.io"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-smtp", "smtp_config.0.sender", "sender@test.io"), - ), - }, - }, - }) -} - -func TestAccRancher2Notifier_disappears_SMTP(t *testing.T) { - var notifier *managementClient.Notifier - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2NotifierSMTPConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-smtp", notifier), - testAccRancher2NotifierDisappears(notifier), - ), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func TestAccRancher2Notifier_basic_Webhook(t *testing.T) { - var notifier *managementClient.Notifier - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2NotifierWebhookConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-webhook", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-webhook", "name", "foo-webhook"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-webhook", "description", "Terraform notifier acceptance test"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-webhook", "send_resolved", "true"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-webhook", "webhook_config.0.url", "http://url.test.io"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-webhook", "webhook_config.0.proxy_url", "http://proxy.test.io"), - ), - }, - { - Config: testAccRancher2NotifierWebhookUpdateConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-webhook", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-webhook", "name", "foo-webhook"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-webhook", "webhook_config.0.url", "http://url2.test.io"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-webhook", "webhook_config.0.proxy_url", "http://proxy2.test.io"), - ), - }, - { - Config: testAccRancher2NotifierWebhookConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-webhook", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-webhook", "name", "foo-webhook"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-webhook", "description", "Terraform notifier acceptance test"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-webhook", "send_resolved", "true"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-webhook", "webhook_config.0.url", "http://url.test.io"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-webhook", "webhook_config.0.proxy_url", "http://proxy.test.io"), - ), - }, - }, - }) -} - -func TestAccRancher2Notifier_disappears_Webhook(t *testing.T) { - var notifier *managementClient.Notifier - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2NotifierWebhookConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-webhook", notifier), - testAccRancher2NotifierDisappears(notifier), - ), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func TestAccRancher2Notifier_basic_Wechat(t *testing.T) { - var notifier *managementClient.Notifier - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2NotifierWechatConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-wechat", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-wechat", "name", "foo-wechat"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-wechat", "description", "Terraform notifier acceptance test"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-wechat", "send_resolved", "true"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-wechat", "wechat_config.0.default_recipient", "XXXXXXXX"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-wechat", "wechat_config.0.secret", "XXXXXXXX"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-wechat", "wechat_config.0.proxy_url", "http://proxy.test.io"), - ), - }, - { - Config: testAccRancher2NotifierWechatUpdateConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-wechat", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-wechat", "name", "foo-wechat"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-wechat", "wechat_config.0.default_recipient", "YYYYYYYY"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-wechat", "wechat_config.0.secret", "YYYYYYYY"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-wechat", "wechat_config.0.proxy_url", "http://proxy2.test.io"), - ), - }, - { - Config: testAccRancher2NotifierWechatConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-wechat", notifier), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-wechat", "name", "foo-wechat"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-wechat", "description", "Terraform notifier acceptance test"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-wechat", "send_resolved", "true"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-wechat", "wechat_config.0.default_recipient", "XXXXXXXX"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-wechat", "wechat_config.0.secret", "XXXXXXXX"), - resource.TestCheckResourceAttr(testAccRancher2NotifierType+".foo-wechat", "wechat_config.0.proxy_url", "http://proxy.test.io"), - ), - }, - }, - }) -} - -func TestAccRancher2Notifier_disappears_Wechat(t *testing.T) { - var notifier *managementClient.Notifier - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckRancher2NotifierDestroy, - Steps: []resource.TestStep{ - { - Config: testAccRancher2NotifierWechatConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckRancher2NotifierExists(testAccRancher2NotifierType+".foo-wechat", notifier), - testAccRancher2NotifierDisappears(notifier), - ), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func testAccRancher2NotifierDisappears(notifier *managementClient.Notifier) resource.TestCheckFunc { - return func(s *terraform.State) error { - for _, rs := range s.RootModule().Resources { - if rs.Type != testAccRancher2NotifierType { - continue - } - - client, err := testAccProvider.Meta().(*Config).ManagementClient() - if err != nil { - return err - } - - notifier, err = client.Notifier.ByID(rs.Primary.ID) - if err != nil { - if IsNotFound(err) { - return nil - } - return err - } - - err = client.Notifier.Delete(notifier) - if err != nil { - return fmt.Errorf("Error removing Notifier: %s", err) - } - - stateConf := &resource.StateChangeConf{ - Pending: []string{"active"}, - Target: []string{"removed"}, - Refresh: notifierStateRefreshFunc(client, rs.Primary.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 notifier (%s) to be removed: %s", rs.Primary.ID, waitErr) - } - } - return nil - - } -} - -func testAccCheckRancher2NotifierExists(n string, notifier *managementClient.Notifier) 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 notifier ID is set") - } - - client, err := testAccProvider.Meta().(*Config).ManagementClient() - if err != nil { - return err - } - - foundNot, err := client.Notifier.ByID(rs.Primary.ID) - if err != nil { - if IsNotFound(err) { - return fmt.Errorf("Notifier not found") - } - return err - } - - notifier = foundNot - - return nil - } -} - -func testAccCheckRancher2NotifierDestroy(s *terraform.State) error { - for _, rs := range s.RootModule().Resources { - if rs.Type != testAccRancher2NotifierType { - continue - } - client, err := testAccProvider.Meta().(*Config).ManagementClient() - if err != nil { - return err - } - - _, err = client.Notifier.ByID(rs.Primary.ID) - if err != nil { - if IsNotFound(err) { - return nil - } - return err - } - - return fmt.Errorf("Notifier still exists") - } - return nil -} diff --git a/rancher2/schema_notifier.go b/rancher2/schema_notifier.go deleted file mode 100644 index 9a5746aa..00000000 --- a/rancher2/schema_notifier.go +++ /dev/null @@ -1,103 +0,0 @@ -package rancher2 - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -// Schemas - -func notifierFields() map[string]*schema.Schema { - s := map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - Description: "Notifier name", - }, - "cluster_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - Description: "Notifier cluster ID", - }, - "description": { - Type: schema.TypeString, - Optional: true, - Description: "Notifier description", - }, - "send_resolved": { - Type: schema.TypeBool, - Optional: true, - Description: "Notifier send resolved", - Default: false, - }, - "dingtalk_config": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - ConflictsWith: []string{"msteams_config", "pagerduty_config", "smtp_config", "slack_config", "webhook_config", "wechat_config"}, - Elem: &schema.Resource{ - Schema: notifierDingtalkConfigFields(), - }, - }, - "msteams_config": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - ConflictsWith: []string{"dingtalk_config", "pagerduty_config", "smtp_config", "slack_config", "webhook_config", "wechat_config"}, - Elem: &schema.Resource{ - Schema: notifierMSTeamsConfigFields(), - }, - }, - "pagerduty_config": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - ConflictsWith: []string{"dingtalk_config", "msteams_config", "smtp_config", "slack_config", "webhook_config", "wechat_config"}, - Elem: &schema.Resource{ - Schema: notifierPagerdutyConfigFields(), - }, - }, - "slack_config": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - ConflictsWith: []string{"dingtalk_config", "msteams_config", "pagerduty_config", "smtp_config", "webhook_config", "wechat_config"}, - Elem: &schema.Resource{ - Schema: notifierSlackConfigFields(), - }, - }, - "smtp_config": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - ConflictsWith: []string{"dingtalk_config", "msteams_config", "pagerduty_config", "slack_config", "webhook_config", "wechat_config"}, - Elem: &schema.Resource{ - Schema: notifierSMTPConfigFields(), - }, - }, - "webhook_config": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - ConflictsWith: []string{"dingtalk_config", "msteams_config", "pagerduty_config", "smtp_config", "slack_config", "wechat_config"}, - Elem: &schema.Resource{ - Schema: notifierWebhookConfigFields(), - }, - }, - "wechat_config": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - ConflictsWith: []string{"dingtalk_config", "msteams_config", "pagerduty_config", "smtp_config", "slack_config", "webhook_config"}, - Elem: &schema.Resource{ - Schema: notifierWechatConfigFields(), - }, - }, - } - - for k, v := range commonAnnotationLabelFields() { - s[k] = v - } - - return s -} diff --git a/rancher2/schema_notifier_dingtalk_config.go b/rancher2/schema_notifier_dingtalk_config.go deleted file mode 100644 index 81efe0dc..00000000 --- a/rancher2/schema_notifier_dingtalk_config.go +++ /dev/null @@ -1,30 +0,0 @@ -package rancher2 - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -// Schemas - -func notifierDingtalkConfigFields() map[string]*schema.Schema { - s := map[string]*schema.Schema{ - "url": { - Type: schema.TypeString, - Required: true, - Description: "Webhook URL", - }, - "proxy_url": { - Type: schema.TypeString, - Optional: true, - Description: "Dingtalk proxy URL", - }, - "secret": { - Type: schema.TypeString, - Optional: true, - Sensitive: true, - Description: "Required for webhook with sign enabled", - }, - } - - return s -} diff --git a/rancher2/schema_notifier_msteams_config.go b/rancher2/schema_notifier_msteams_config.go deleted file mode 100644 index 1816c08a..00000000 --- a/rancher2/schema_notifier_msteams_config.go +++ /dev/null @@ -1,24 +0,0 @@ -package rancher2 - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -// Schemas - -func notifierMSTeamsConfigFields() map[string]*schema.Schema { - s := map[string]*schema.Schema{ - "url": { - Type: schema.TypeString, - Required: true, - Description: "Webhook URL", - }, - "proxy_url": { - Type: schema.TypeString, - Optional: true, - Description: "MS teams proxy URL", - }, - } - - return s -} diff --git a/rancher2/schema_notifier_pagerduty_config.go b/rancher2/schema_notifier_pagerduty_config.go deleted file mode 100644 index 17e07bfa..00000000 --- a/rancher2/schema_notifier_pagerduty_config.go +++ /dev/null @@ -1,24 +0,0 @@ -package rancher2 - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -// Schemas - -func notifierPagerdutyConfigFields() map[string]*schema.Schema { - s := map[string]*schema.Schema{ - "service_key": { - Type: schema.TypeString, - Required: true, - Description: "Pagerduty service key", - }, - "proxy_url": { - Type: schema.TypeString, - Optional: true, - Description: "Pagerduty proxy URL", - }, - } - - return s -} diff --git a/rancher2/schema_notifier_slack_config.go b/rancher2/schema_notifier_slack_config.go deleted file mode 100644 index 59eed8d6..00000000 --- a/rancher2/schema_notifier_slack_config.go +++ /dev/null @@ -1,29 +0,0 @@ -package rancher2 - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -// Schemas - -func notifierSlackConfigFields() map[string]*schema.Schema { - s := map[string]*schema.Schema{ - "default_recipient": { - Type: schema.TypeString, - Required: true, - Description: "Slack default channel", - }, - "url": { - Type: schema.TypeString, - Required: true, - Description: "Slack URL", - }, - "proxy_url": { - Type: schema.TypeString, - Optional: true, - Description: "Slack proxy URL", - }, - } - - return s -} diff --git a/rancher2/schema_notifier_smtp_config.go b/rancher2/schema_notifier_smtp_config.go deleted file mode 100644 index 6e29112d..00000000 --- a/rancher2/schema_notifier_smtp_config.go +++ /dev/null @@ -1,51 +0,0 @@ -package rancher2 - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -// Schemas - -func notifierSMTPConfigFields() map[string]*schema.Schema { - s := map[string]*schema.Schema{ - "default_recipient": { - Type: schema.TypeString, - Required: true, - Description: "SMTP default recipient address", - }, - "host": { - Type: schema.TypeString, - Required: true, - Description: "SMTP host", - }, - "port": { - Type: schema.TypeInt, - Required: true, - Description: "SMTP port", - }, - "sender": { - Type: schema.TypeString, - Required: true, - Description: "SMTP sender", - }, - "password": { - Type: schema.TypeString, - Optional: true, - Sensitive: true, - Description: "SMTP password", - }, - "tls": { - Type: schema.TypeBool, - Optional: true, - Default: true, - Description: "SMTP TLS", - }, - "username": { - Type: schema.TypeString, - Optional: true, - Description: "SMTP username", - }, - } - - return s -} diff --git a/rancher2/schema_notifier_webhook_config.go b/rancher2/schema_notifier_webhook_config.go deleted file mode 100644 index 532f3878..00000000 --- a/rancher2/schema_notifier_webhook_config.go +++ /dev/null @@ -1,24 +0,0 @@ -package rancher2 - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -// Schemas - -func notifierWebhookConfigFields() map[string]*schema.Schema { - s := map[string]*schema.Schema{ - "url": { - Type: schema.TypeString, - Required: true, - Description: "Webhook URL", - }, - "proxy_url": { - Type: schema.TypeString, - Optional: true, - Description: "Webhook proxy URL", - }, - } - - return s -} diff --git a/rancher2/schema_notifier_wechat_config.go b/rancher2/schema_notifier_wechat_config.go deleted file mode 100644 index 14dededf..00000000 --- a/rancher2/schema_notifier_wechat_config.go +++ /dev/null @@ -1,58 +0,0 @@ -package rancher2 - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" -) - -const ( - notifierWechatRecipientTypeParty = "party" - notifierWechatRecipientTypeTag = "tag" - notifierWechatRecipientTypeUser = "user" -) - -var ( - notifierWechatRecipientTypes = []string{notifierWechatRecipientTypeParty, notifierWechatRecipientTypeTag, notifierWechatRecipientTypeUser} -) - -// Schemas - -func notifierWechatConfigFields() map[string]*schema.Schema { - s := map[string]*schema.Schema{ - "agent": { - Type: schema.TypeString, - Required: true, - Description: "Wechat application agent ID", - }, - "corp": { - Type: schema.TypeString, - Required: true, - Description: "Wechat corporation ID", - }, - "default_recipient": { - Type: schema.TypeString, - Required: true, - Description: "Wechat default channel", - }, - "secret": { - Type: schema.TypeString, - Required: true, - Sensitive: true, - Description: "Wechat application secret", - }, - "proxy_url": { - Type: schema.TypeString, - Optional: true, - Description: "Wechat proxy URL", - }, - "recipient_type": { - Type: schema.TypeString, - Optional: true, - Default: notifierWechatRecipientTypeParty, - Description: "Wechat recipient type", - ValidateFunc: validation.StringInSlice(notifierWechatRecipientTypes, true), - }, - } - - return s -} diff --git a/rancher2/schema_recipient.go b/rancher2/schema_recipient.go deleted file mode 100644 index 4a8839fa..00000000 --- a/rancher2/schema_recipient.go +++ /dev/null @@ -1,45 +0,0 @@ -package rancher2 - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -) - -const ( - recipientTypeDingtalk = "dingtalk" - recipientTypeMsTeams = "msteams" - recipientTypePagerduty = "pagerduty" - recipientTypeSlack = "slack" - recipientTypeSMTP = "email" - recipientTypeWebhook = "webhook" - recipientTypeWechat = "wechat" -) - -//Schemas - -func recipientFields() map[string]*schema.Schema { - s := map[string]*schema.Schema{ - "notifier_id": { - Type: schema.TypeString, - Required: true, - Description: "Recipient notifier ID", - }, - "notifier_type": { - Type: schema.TypeString, - Computed: true, - Description: "Recipient notifier type", - }, - "recipient": { - Type: schema.TypeString, - Optional: true, - Computed: true, - Description: "Recipient", - }, - "default_recipient": { - Type: schema.TypeBool, - Optional: true, - Default: false, - Description: "Use notifier default recipient", - }, - } - return s -} diff --git a/rancher2/structure_notifier.go b/rancher2/structure_notifier.go deleted file mode 100644 index 3d8ce77e..00000000 --- a/rancher2/structure_notifier.go +++ /dev/null @@ -1,164 +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 flattenNotifier(d *schema.ResourceData, in *managementClient.Notifier) error { - if in == nil { - return nil - } - - d.SetId(in.ID) - d.Set("cluster_id", in.ClusterID) - d.Set("name", in.Name) - - if len(in.Description) > 0 { - d.Set("description", in.Description) - } - - d.Set("send_resolved", in.SendResolved) - - if in.DingtalkConfig != nil { - v, ok := d.Get("dingtalk_config").([]interface{}) - if !ok { - v = []interface{}{} - } - - d.Set("dingtalk_config", flattenNotifierDingtalkConfig(in.DingtalkConfig, v)) - } - - if in.MSTeamsConfig != nil { - v, ok := d.Get("msteams_config").([]interface{}) - if !ok { - v = []interface{}{} - } - - d.Set("msteams_config", flattenNotifierMSTeamsConfig(in.MSTeamsConfig, v)) - } - - if in.PagerdutyConfig != nil { - v, ok := d.Get("pagerduty_config").([]interface{}) - if !ok { - v = []interface{}{} - } - - d.Set("pagerduty_config", flattenNotifierPagerdutyConfig(in.PagerdutyConfig, v)) - } - - if in.SlackConfig != nil { - v, ok := d.Get("slack_config").([]interface{}) - if !ok { - v = []interface{}{} - } - - d.Set("slack_config", flattenNotifierSlackConfig(in.SlackConfig, v)) - } - - if in.SMTPConfig != nil { - v, ok := d.Get("smtp_config").([]interface{}) - if !ok { - v = []interface{}{} - } - - d.Set("smtp_config", flattenNotifierSMTPConfig(in.SMTPConfig, v)) - } - - if in.WebhookConfig != nil { - v, ok := d.Get("webhook_config").([]interface{}) - if !ok { - v = []interface{}{} - } - - d.Set("webhook_config", flattenNotifierWebhookConfig(in.WebhookConfig, v)) - } - - if in.WechatConfig != nil { - v, ok := d.Get("wechat_config").([]interface{}) - if !ok { - v = []interface{}{} - } - - d.Set("wechat_config", flattenNotifierWechatConfig(in.WechatConfig, v)) - } - - 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 expandNotifier(in *schema.ResourceData) (*managementClient.Notifier, error) { - obj := &managementClient.Notifier{} - if in == nil { - return nil, fmt.Errorf("[ERROR] Expanding notifier: Schema Resource data is nil") - } - - if v := in.Id(); len(v) > 0 { - obj.ID = v - } - - obj.ClusterID = in.Get("cluster_id").(string) - obj.Name = in.Get("name").(string) - - if v, ok := in.Get("description").(string); ok && len(v) > 0 { - obj.Description = v - } - - if v, ok := in.Get("send_resolved").(bool); ok { - obj.SendResolved = v - } - - if v, ok := in.Get("dingtalk_config").([]interface{}); ok && len(v) > 0 { - obj.DingtalkConfig = expandNotifierDingtalkConfig(v) - } - - if v, ok := in.Get("msteams_config").([]interface{}); ok && len(v) > 0 { - obj.MSTeamsConfig = expandNotifierMSTeamsConfig(v) - } - - if v, ok := in.Get("pagerduty_config").([]interface{}); ok && len(v) > 0 { - obj.PagerdutyConfig = expandNotifierPagerdutyConfig(v) - } - - if v, ok := in.Get("slack_config").([]interface{}); ok && len(v) > 0 { - obj.SlackConfig = expandNotifierSlackConfig(v) - } - - if v, ok := in.Get("smtp_config").([]interface{}); ok && len(v) > 0 { - obj.SMTPConfig = expandNotifierSMTPConfig(v) - } - - if v, ok := in.Get("webhook_config").([]interface{}); ok && len(v) > 0 { - obj.WebhookConfig = expandNotifierWebhookConfig(v) - } - - if v, ok := in.Get("wechat_config").([]interface{}); ok && len(v) > 0 { - obj.WechatConfig = expandNotifierWechatConfig(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_notifier_dingtalk_config.go b/rancher2/structure_notifier_dingtalk_config.go deleted file mode 100644 index 673b2e4d..00000000 --- a/rancher2/structure_notifier_dingtalk_config.go +++ /dev/null @@ -1,56 +0,0 @@ -package rancher2 - -import ( - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" -) - -// Flatteners - -func flattenNotifierDingtalkConfig(in *managementClient.DingtalkConfig, 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{}{} - } - - obj["url"] = in.URL - - if len(in.ProxyURL) > 0 { - obj["proxy_url"] = in.ProxyURL - } - - if len(in.Secret) > 0 { - obj["secret"] = in.Secret - } - - return []interface{}{obj} - -} - -// Expanders - -func expandNotifierDingtalkConfig(p []interface{}) *managementClient.DingtalkConfig { - obj := &managementClient.DingtalkConfig{} - - if len(p) == 0 || p[0] == nil { - return obj - } - in := p[0].(map[string]interface{}) - - obj.URL = in["url"].(string) - - if v, ok := in["proxy_url"].(string); ok && len(v) > 0 { - obj.ProxyURL = v - } - - if v, ok := in["secret"].(string); ok && len(v) > 0 { - obj.Secret = v - } - - return obj -} diff --git a/rancher2/structure_notifier_dingtalk_config_test.go b/rancher2/structure_notifier_dingtalk_config_test.go deleted file mode 100644 index 11a5c8b2..00000000 --- a/rancher2/structure_notifier_dingtalk_config_test.go +++ /dev/null @@ -1,63 +0,0 @@ -package rancher2 - -import ( - "testing" - - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" - "github.com/stretchr/testify/assert" -) - -var ( - testNotifierDingtalkConfigConf *managementClient.DingtalkConfig - testNotifierDingtalkConfigInterface []interface{} -) - -func init() { - testNotifierDingtalkConfigConf = &managementClient.DingtalkConfig{ - URL: "url", - ProxyURL: "proxy_url", - Secret: "secret", - } - testNotifierDingtalkConfigInterface = []interface{}{ - map[string]interface{}{ - "url": "url", - "proxy_url": "proxy_url", - "secret": "secret", - }, - } -} - -func TestFlattenNotifierDingtalkConfig(t *testing.T) { - - cases := []struct { - Input *managementClient.DingtalkConfig - ExpectedOutput []interface{} - }{ - { - testNotifierDingtalkConfigConf, - testNotifierDingtalkConfigInterface, - }, - } - for _, tc := range cases { - output := flattenNotifierDingtalkConfig(tc.Input, tc.ExpectedOutput) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from flattener.") - } -} - -func TestExpandNotifierDingtalkConfig(t *testing.T) { - - cases := []struct { - Input []interface{} - ExpectedOutput *managementClient.DingtalkConfig - }{ - { - testNotifierDingtalkConfigInterface, - testNotifierDingtalkConfigConf, - }, - } - - for _, tc := range cases { - output := expandNotifierDingtalkConfig(tc.Input) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from expander.") - } -} diff --git a/rancher2/structure_notifier_msteams_config.go b/rancher2/structure_notifier_msteams_config.go deleted file mode 100644 index 97b2a6c7..00000000 --- a/rancher2/structure_notifier_msteams_config.go +++ /dev/null @@ -1,48 +0,0 @@ -package rancher2 - -import ( - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" -) - -// Flatteners - -func flattenNotifierMSTeamsConfig(in *managementClient.MSTeamsConfig, 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{}{} - } - - obj["url"] = in.URL - - if len(in.ProxyURL) > 0 { - obj["proxy_url"] = in.ProxyURL - } - - return []interface{}{obj} - -} - -// Expanders - -func expandNotifierMSTeamsConfig(p []interface{}) *managementClient.MSTeamsConfig { - obj := &managementClient.MSTeamsConfig{} - - if len(p) == 0 || p[0] == nil { - return obj - } - in := p[0].(map[string]interface{}) - - obj.URL = in["url"].(string) - - if v, ok := in["proxy_url"].(string); ok && len(v) > 0 { - obj.ProxyURL = v - } - - return obj -} diff --git a/rancher2/structure_notifier_msteams_config_test.go b/rancher2/structure_notifier_msteams_config_test.go deleted file mode 100644 index 9f6d6e9f..00000000 --- a/rancher2/structure_notifier_msteams_config_test.go +++ /dev/null @@ -1,62 +0,0 @@ -package rancher2 - -import ( - "testing" - - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" - "github.com/stretchr/testify/assert" -) - -var ( - testNotifierMSTeamsConfigConf *managementClient.MSTeamsConfig - testNotifierMSTeamsConfigInterface []interface{} -) - -func init() { - testNotifierMSTeamsConfigConf = &managementClient.MSTeamsConfig{ - URL: "url", - ProxyURL: "proxy_url", - } - testNotifierMSTeamsConfigInterface = []interface{}{ - map[string]interface{}{ - "url": "url", - "proxy_url": "proxy_url", - }, - } -} - -func TestFlattenNotifierMSTeamsConfig(t *testing.T) { - - cases := []struct { - Input *managementClient.MSTeamsConfig - ExpectedOutput []interface{} - }{ - { - testNotifierMSTeamsConfigConf, - testNotifierMSTeamsConfigInterface, - }, - } - - for _, tc := range cases { - output := flattenNotifierMSTeamsConfig(tc.Input, tc.ExpectedOutput) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from flattener.") - } -} - -func TestExpandNotifierMSTeamsConfig(t *testing.T) { - - cases := []struct { - Input []interface{} - ExpectedOutput *managementClient.MSTeamsConfig - }{ - { - testNotifierMSTeamsConfigInterface, - testNotifierMSTeamsConfigConf, - }, - } - - for _, tc := range cases { - output := expandNotifierMSTeamsConfig(tc.Input) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from expander.") - } -} diff --git a/rancher2/structure_notifier_pagerduty_config.go b/rancher2/structure_notifier_pagerduty_config.go deleted file mode 100644 index 78a62622..00000000 --- a/rancher2/structure_notifier_pagerduty_config.go +++ /dev/null @@ -1,48 +0,0 @@ -package rancher2 - -import ( - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" -) - -// Flatteners - -func flattenNotifierPagerdutyConfig(in *managementClient.PagerdutyConfig, 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{}{} - } - - obj["service_key"] = in.ServiceKey - - if len(in.ProxyURL) > 0 { - obj["proxy_url"] = in.ProxyURL - } - - return []interface{}{obj} - -} - -// Expanders - -func expandNotifierPagerdutyConfig(p []interface{}) *managementClient.PagerdutyConfig { - obj := &managementClient.PagerdutyConfig{} - - if len(p) == 0 || p[0] == nil { - return obj - } - in := p[0].(map[string]interface{}) - - obj.ServiceKey = in["service_key"].(string) - - if v, ok := in["proxy_url"].(string); ok && len(v) > 0 { - obj.ProxyURL = v - } - - return obj -} diff --git a/rancher2/structure_notifier_pagerduty_config_test.go b/rancher2/structure_notifier_pagerduty_config_test.go deleted file mode 100644 index 98f1289a..00000000 --- a/rancher2/structure_notifier_pagerduty_config_test.go +++ /dev/null @@ -1,62 +0,0 @@ -package rancher2 - -import ( - "testing" - - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" - "github.com/stretchr/testify/assert" -) - -var ( - testNotifierPagerdutyConfigConf *managementClient.PagerdutyConfig - testNotifierPagerdutyConfigInterface []interface{} -) - -func init() { - testNotifierPagerdutyConfigConf = &managementClient.PagerdutyConfig{ - ServiceKey: "service_key", - ProxyURL: "proxy_url", - } - testNotifierPagerdutyConfigInterface = []interface{}{ - map[string]interface{}{ - "service_key": "service_key", - "proxy_url": "proxy_url", - }, - } -} - -func TestFlattenNotifierPagerdutyConfig(t *testing.T) { - - cases := []struct { - Input *managementClient.PagerdutyConfig - ExpectedOutput []interface{} - }{ - { - testNotifierPagerdutyConfigConf, - testNotifierPagerdutyConfigInterface, - }, - } - - for _, tc := range cases { - output := flattenNotifierPagerdutyConfig(tc.Input, testNotifierPagerdutyConfigInterface) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from flattener.") - } -} - -func TestExpandNotifierPagerdutyConfig(t *testing.T) { - - cases := []struct { - Input []interface{} - ExpectedOutput *managementClient.PagerdutyConfig - }{ - { - testNotifierPagerdutyConfigInterface, - testNotifierPagerdutyConfigConf, - }, - } - - for _, tc := range cases { - output := expandNotifierPagerdutyConfig(tc.Input) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from expander.") - } -} diff --git a/rancher2/structure_notifier_slack_config.go b/rancher2/structure_notifier_slack_config.go deleted file mode 100644 index 261d46b7..00000000 --- a/rancher2/structure_notifier_slack_config.go +++ /dev/null @@ -1,50 +0,0 @@ -package rancher2 - -import ( - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" -) - -// Flatteners - -func flattenNotifierSlackConfig(in *managementClient.SlackConfig, 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{}{} - } - - obj["default_recipient"] = in.DefaultRecipient - obj["url"] = in.URL - - if len(in.ProxyURL) > 0 { - obj["proxy_url"] = in.ProxyURL - } - - return []interface{}{obj} - -} - -// Expanders - -func expandNotifierSlackConfig(p []interface{}) *managementClient.SlackConfig { - obj := &managementClient.SlackConfig{} - - if len(p) == 0 || p[0] == nil { - return obj - } - in := p[0].(map[string]interface{}) - - obj.DefaultRecipient = in["default_recipient"].(string) - obj.URL = in["url"].(string) - - if v, ok := in["proxy_url"].(string); ok && len(v) > 0 { - obj.ProxyURL = v - } - - return obj -} diff --git a/rancher2/structure_notifier_slack_config_test.go b/rancher2/structure_notifier_slack_config_test.go deleted file mode 100644 index 26e173a2..00000000 --- a/rancher2/structure_notifier_slack_config_test.go +++ /dev/null @@ -1,64 +0,0 @@ -package rancher2 - -import ( - "testing" - - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" - "github.com/stretchr/testify/assert" -) - -var ( - testNotifierSlackConfigConf *managementClient.SlackConfig - testNotifierSlackConfigInterface []interface{} -) - -func init() { - testNotifierSlackConfigConf = &managementClient.SlackConfig{ - DefaultRecipient: "default_recipient", - URL: "url", - ProxyURL: "proxy_url", - } - testNotifierSlackConfigInterface = []interface{}{ - map[string]interface{}{ - "default_recipient": "default_recipient", - "url": "url", - "proxy_url": "proxy_url", - }, - } -} - -func TestFlattenNotifierSlackConfig(t *testing.T) { - - cases := []struct { - Input *managementClient.SlackConfig - ExpectedOutput []interface{} - }{ - { - testNotifierSlackConfigConf, - testNotifierSlackConfigInterface, - }, - } - - for _, tc := range cases { - output := flattenNotifierSlackConfig(tc.Input, testNotifierSlackConfigInterface) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from flattener.") - } -} - -func TestExpandNotifierSlackConfig(t *testing.T) { - - cases := []struct { - Input []interface{} - ExpectedOutput *managementClient.SlackConfig - }{ - { - testNotifierSlackConfigInterface, - testNotifierSlackConfigConf, - }, - } - - for _, tc := range cases { - output := expandNotifierSlackConfig(tc.Input) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from expander.") - } -} diff --git a/rancher2/structure_notifier_smtp_config.go b/rancher2/structure_notifier_smtp_config.go deleted file mode 100644 index 049ed6f2..00000000 --- a/rancher2/structure_notifier_smtp_config.go +++ /dev/null @@ -1,68 +0,0 @@ -package rancher2 - -import ( - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" -) - -// Flatteners - -func flattenNotifierSMTPConfig(in *managementClient.SMTPConfig, 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{}{} - } - - obj["default_recipient"] = in.DefaultRecipient - obj["host"] = in.Host - obj["port"] = int(in.Port) - obj["sender"] = in.Sender - - if len(in.Password) > 0 { - obj["password"] = in.Password - } - - obj["tls"] = *in.TLS - - if len(in.Username) > 0 { - obj["username"] = in.Username - } - - return []interface{}{obj} - -} - -// Expanders - -func expandNotifierSMTPConfig(p []interface{}) *managementClient.SMTPConfig { - obj := &managementClient.SMTPConfig{} - - if len(p) == 0 || p[0] == nil { - return obj - } - in := p[0].(map[string]interface{}) - - obj.DefaultRecipient = in["default_recipient"].(string) - obj.Host = in["host"].(string) - obj.Port = int64(in["port"].(int)) - obj.Sender = in["sender"].(string) - - if v, ok := in["password"].(string); ok && len(v) > 0 { - obj.Password = v - } - - if v, ok := in["tls"].(bool); ok { - obj.TLS = &v - } - - if v, ok := in["username"].(string); ok && len(v) > 0 { - obj.Username = v - } - - return obj -} diff --git a/rancher2/structure_notifier_smtp_config_test.go b/rancher2/structure_notifier_smtp_config_test.go deleted file mode 100644 index f5367b2c..00000000 --- a/rancher2/structure_notifier_smtp_config_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package rancher2 - -import ( - "testing" - - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" - "github.com/stretchr/testify/assert" -) - -var ( - testNotifierSMTPConfigConf *managementClient.SMTPConfig - testNotifierSMTPConfigInterface []interface{} -) - -func init() { - testNotifierSMTPConfigConf = &managementClient.SMTPConfig{ - DefaultRecipient: "default_recipient", - Host: "url", - Port: int64(25), - Sender: "sender", - Password: "password", - TLS: newTrue(), - Username: "username", - } - testNotifierSMTPConfigInterface = []interface{}{ - map[string]interface{}{ - "default_recipient": "default_recipient", - "host": "host", - "port": 25, - "sender": "sender", - "password": "password", - "tls": newTrue(), - "username": "username", - }, - } -} - -func TestFlattenNotifierSMTPConfig(t *testing.T) { - - cases := []struct { - Input *managementClient.SMTPConfig - ExpectedOutput []interface{} - }{ - { - testNotifierSMTPConfigConf, - testNotifierSMTPConfigInterface, - }, - } - - for _, tc := range cases { - output := flattenNotifierSMTPConfig(tc.Input, testNotifierSMTPConfigInterface) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from flattener.") - } -} - -func TestExpandNotifierSMTPConfig(t *testing.T) { - - cases := []struct { - Input []interface{} - ExpectedOutput *managementClient.SMTPConfig - }{ - { - testNotifierSMTPConfigInterface, - testNotifierSMTPConfigConf, - }, - } - - for _, tc := range cases { - output := expandNotifierSMTPConfig(tc.Input) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from expander.") - } -} diff --git a/rancher2/structure_notifier_webhook_config.go b/rancher2/structure_notifier_webhook_config.go deleted file mode 100644 index caa65a25..00000000 --- a/rancher2/structure_notifier_webhook_config.go +++ /dev/null @@ -1,48 +0,0 @@ -package rancher2 - -import ( - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" -) - -// Flatteners - -func flattenNotifierWebhookConfig(in *managementClient.WebhookConfig, 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{}{} - } - - obj["url"] = in.URL - - if len(in.ProxyURL) > 0 { - obj["proxy_url"] = in.ProxyURL - } - - return []interface{}{obj} - -} - -// Expanders - -func expandNotifierWebhookConfig(p []interface{}) *managementClient.WebhookConfig { - obj := &managementClient.WebhookConfig{} - - if len(p) == 0 || p[0] == nil { - return obj - } - in := p[0].(map[string]interface{}) - - obj.URL = in["url"].(string) - - if v, ok := in["proxy_url"].(string); ok && len(v) > 0 { - obj.ProxyURL = v - } - - return obj -} diff --git a/rancher2/structure_notifier_webhook_config_test.go b/rancher2/structure_notifier_webhook_config_test.go deleted file mode 100644 index c79282cf..00000000 --- a/rancher2/structure_notifier_webhook_config_test.go +++ /dev/null @@ -1,62 +0,0 @@ -package rancher2 - -import ( - "testing" - - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" - "github.com/stretchr/testify/assert" -) - -var ( - testNotifierWebhookConfigConf *managementClient.WebhookConfig - testNotifierWebhookConfigInterface []interface{} -) - -func init() { - testNotifierWebhookConfigConf = &managementClient.WebhookConfig{ - URL: "url", - ProxyURL: "proxy_url", - } - testNotifierWebhookConfigInterface = []interface{}{ - map[string]interface{}{ - "url": "url", - "proxy_url": "proxy_url", - }, - } -} - -func TestFlattenNotifierWebhookConfig(t *testing.T) { - - cases := []struct { - Input *managementClient.WebhookConfig - ExpectedOutput []interface{} - }{ - { - testNotifierWebhookConfigConf, - testNotifierWebhookConfigInterface, - }, - } - - for _, tc := range cases { - output := flattenNotifierWebhookConfig(tc.Input, testNotifierWebhookConfigInterface) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from flattener.") - } -} - -func TestExpandNotifierWebhookConfig(t *testing.T) { - - cases := []struct { - Input []interface{} - ExpectedOutput *managementClient.WebhookConfig - }{ - { - testNotifierWebhookConfigInterface, - testNotifierWebhookConfigConf, - }, - } - - for _, tc := range cases { - output := expandNotifierWebhookConfig(tc.Input) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from expander.") - } -} diff --git a/rancher2/structure_notifier_wechat_config.go b/rancher2/structure_notifier_wechat_config.go deleted file mode 100644 index 129dd172..00000000 --- a/rancher2/structure_notifier_wechat_config.go +++ /dev/null @@ -1,61 +0,0 @@ -package rancher2 - -import ( - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" -) - -// Flatteners - -func flattenNotifierWechatConfig(in *managementClient.WechatConfig, 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{}{} - } - - obj["agent"] = in.Agent - obj["corp"] = in.Corp - obj["default_recipient"] = in.DefaultRecipient - - if len(in.Secret) > 0 { - obj["secret"] = in.Secret - } - - if len(in.ProxyURL) > 0 { - obj["proxy_url"] = in.ProxyURL - } - - obj["recipient_type"] = in.RecipientType - - return []interface{}{obj} - -} - -// Expanders - -func expandNotifierWechatConfig(p []interface{}) *managementClient.WechatConfig { - obj := &managementClient.WechatConfig{} - - if len(p) == 0 || p[0] == nil { - return obj - } - in := p[0].(map[string]interface{}) - - obj.Agent = in["agent"].(string) - obj.Corp = in["corp"].(string) - obj.DefaultRecipient = in["default_recipient"].(string) - obj.Secret = in["secret"].(string) - - if v, ok := in["proxy_url"].(string); ok && len(v) > 0 { - obj.ProxyURL = v - } - - obj.RecipientType = in["recipient_type"].(string) - - return obj -} diff --git a/rancher2/structure_notifier_wechat_config_test.go b/rancher2/structure_notifier_wechat_config_test.go deleted file mode 100644 index 89d180c6..00000000 --- a/rancher2/structure_notifier_wechat_config_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package rancher2 - -import ( - "testing" - - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" - "github.com/stretchr/testify/assert" -) - -var ( - testNotifierWechatConfigConf *managementClient.WechatConfig - testNotifierWechatConfigInterface []interface{} -) - -func init() { - testNotifierWechatConfigConf = &managementClient.WechatConfig{ - Agent: "agent", - Corp: "corp", - DefaultRecipient: "default_recipient", - Secret: "secret", - ProxyURL: "proxy_url", - RecipientType: "recipient_type", - } - testNotifierWechatConfigInterface = []interface{}{ - map[string]interface{}{ - "agent": "agent", - "corp": "corp", - "default_recipient": "default_recipient", - "secret": "secret", - "proxy_url": "proxy_url", - "recipient_type": "recipient_type", - }, - } -} - -func TestFlattenNotifierWechatConfig(t *testing.T) { - - cases := []struct { - Input *managementClient.WechatConfig - ExpectedOutput []interface{} - }{ - { - testNotifierWechatConfigConf, - testNotifierWechatConfigInterface, - }, - } - - for _, tc := range cases { - output := flattenNotifierWechatConfig(tc.Input, testNotifierWechatConfigInterface) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from flattener.") - } -} - -func TestExpandNotifierWechatConfig(t *testing.T) { - - cases := []struct { - Input []interface{} - ExpectedOutput *managementClient.WechatConfig - }{ - { - testNotifierWechatConfigInterface, - testNotifierWechatConfigConf, - }, - } - - for _, tc := range cases { - output := expandNotifierWechatConfig(tc.Input) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from expander.") - } -} diff --git a/rancher2/structure_notifier_z_test.go b/rancher2/structure_notifier_z_test.go deleted file mode 100644 index e86e6ee4..00000000 --- a/rancher2/structure_notifier_z_test.go +++ /dev/null @@ -1,213 +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 ( - testNotifierDingtalkConf *managementClient.Notifier - testNotifierDingtalkInterface map[string]interface{} - testNotifierMSTeamsConf *managementClient.Notifier - testNotifierMSTeamsInterface map[string]interface{} - testNotifierPagerdutyConf *managementClient.Notifier - testNotifierPagerdutyInterface map[string]interface{} - testNotifierSlackConf *managementClient.Notifier - testNotifierSlackInterface map[string]interface{} - testNotifierSMTPConf *managementClient.Notifier - testNotifierSMTPInterface map[string]interface{} - testNotifierWebhookConf *managementClient.Notifier - testNotifierWebhookInterface map[string]interface{} - testNotifierWechatConf *managementClient.Notifier - testNotifierWechatInterface map[string]interface{} -) - -func init() { - testNotifierDingtalkConf = &managementClient.Notifier{ - Name: "name", - ClusterID: "cluster_id", - Description: "description", - DingtalkConfig: testNotifierDingtalkConfigConf, - } - testNotifierDingtalkInterface = map[string]interface{}{ - "name": "name", - "cluster_id": "cluster_id", - "description": "description", - "dingtalk_config": testNotifierDingtalkConfigInterface, - } - testNotifierMSTeamsConf = &managementClient.Notifier{ - Name: "name", - ClusterID: "cluster_id", - Description: "description", - MSTeamsConfig: testNotifierMSTeamsConfigConf, - } - testNotifierMSTeamsInterface = map[string]interface{}{ - "name": "name", - "cluster_id": "cluster_id", - "description": "description", - "msteams_config": testNotifierMSTeamsConfigInterface, - } - testNotifierPagerdutyConf = &managementClient.Notifier{ - Name: "name", - ClusterID: "cluster_id", - Description: "description", - PagerdutyConfig: testNotifierPagerdutyConfigConf, - } - testNotifierPagerdutyInterface = map[string]interface{}{ - "name": "name", - "cluster_id": "cluster_id", - "description": "description", - "pagerduty_config": testNotifierPagerdutyConfigInterface, - } - testNotifierSlackConf = &managementClient.Notifier{ - Name: "name", - ClusterID: "cluster_id", - Description: "description", - SlackConfig: testNotifierSlackConfigConf, - } - testNotifierSlackInterface = map[string]interface{}{ - "name": "name", - "cluster_id": "cluster_id", - "description": "description", - "slack_config": testNotifierSlackConfigInterface, - } - testNotifierSMTPConf = &managementClient.Notifier{ - Name: "name", - ClusterID: "cluster_id", - Description: "description", - SMTPConfig: testNotifierSMTPConfigConf, - } - testNotifierSMTPInterface = map[string]interface{}{ - "name": "name", - "cluster_id": "cluster_id", - "description": "description", - "smtp_config": testNotifierSMTPConfigInterface, - } - testNotifierWebhookConf = &managementClient.Notifier{ - Name: "name", - ClusterID: "cluster_id", - Description: "description", - WebhookConfig: testNotifierWebhookConfigConf, - } - testNotifierWebhookInterface = map[string]interface{}{ - "name": "name", - "cluster_id": "cluster_id", - "description": "description", - "webhook_config": testNotifierWebhookConfigInterface, - } - testNotifierWechatConf = &managementClient.Notifier{ - Name: "name", - ClusterID: "cluster_id", - Description: "description", - WechatConfig: testNotifierWechatConfigConf, - } - testNotifierWechatInterface = map[string]interface{}{ - "name": "name", - "cluster_id": "cluster_id", - "description": "description", - "wechat_config": testNotifierWechatConfigInterface, - } -} - -func TestFlattenNotifier(t *testing.T) { - - cases := []struct { - Input *managementClient.Notifier - ExpectedOutput map[string]interface{} - }{ - { - testNotifierDingtalkConf, - testNotifierDingtalkInterface, - }, - { - testNotifierMSTeamsConf, - testNotifierMSTeamsInterface, - }, - { - testNotifierPagerdutyConf, - testNotifierPagerdutyInterface, - }, - { - testNotifierSlackConf, - testNotifierSlackInterface, - }, - { - testNotifierSMTPConf, - testNotifierSMTPInterface, - }, - { - testNotifierWebhookConf, - testNotifierWebhookInterface, - }, - { - testNotifierWechatConf, - testNotifierWechatInterface, - }, - } - - for _, tc := range cases { - output := schema.TestResourceDataRaw(t, notifierFields(), map[string]interface{}{}) - err := flattenNotifier(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", - tc.ExpectedOutput, expectedOutput) - } - } -} - -func TestExpandNotifier(t *testing.T) { - - cases := []struct { - Input map[string]interface{} - ExpectedOutput *managementClient.Notifier - }{ - { - testNotifierDingtalkInterface, - testNotifierDingtalkConf, - }, - { - testNotifierMSTeamsInterface, - testNotifierMSTeamsConf, - }, - { - testNotifierPagerdutyInterface, - testNotifierPagerdutyConf, - }, - { - testNotifierSlackInterface, - testNotifierSlackConf, - }, - { - testNotifierSMTPInterface, - testNotifierSMTPConf, - }, - { - testNotifierWebhookInterface, - testNotifierWebhookConf, - }, - { - testNotifierWechatInterface, - testNotifierWechatConf, - }, - } - - for _, tc := range cases { - inputResourceData := schema.TestResourceDataRaw(t, notifierFields(), tc.Input) - output, err := expandNotifier(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/rancher2/structure_recipient.go b/rancher2/structure_recipient.go deleted file mode 100644 index 18f577b5..00000000 --- a/rancher2/structure_recipient.go +++ /dev/null @@ -1,52 +0,0 @@ -package rancher2 - -import ( - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" -) - -// Flatteners - -func flattenRecipients(p []managementClient.Recipient) []interface{} { - if len(p) == 0 { - return []interface{}{} - } - - out := make([]interface{}, len(p)) - for i, in := range p { - obj := make(map[string]interface{}) - - obj["notifier_id"] = in.NotifierID - - if len(in.NotifierType) > 0 { - obj["notifier_type"] = in.NotifierType - } - - if len(in.Recipient) > 0 { - obj["recipient"] = in.Recipient - } - - out[i] = obj - } - - return out -} - -// Expanders - -func expandRecipients(p []interface{}) []managementClient.Recipient { - if len(p) == 0 || p[0] == nil { - return []managementClient.Recipient{} - } - - obj := make([]managementClient.Recipient, len(p)) - - for i := range p { - in := p[i].(map[string]interface{}) - - obj[i].NotifierID = in["notifier_id"].(string) - obj[i].NotifierType = in["notifier_type"].(string) - obj[i].Recipient = in["recipient"].(string) - } - - return obj -} diff --git a/rancher2/structure_recipient_test.go b/rancher2/structure_recipient_test.go deleted file mode 100644 index b6a21309..00000000 --- a/rancher2/structure_recipient_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package rancher2 - -import ( - "testing" - - managementClient "github.com/rancher/rancher/pkg/client/generated/management/v3" - "github.com/stretchr/testify/assert" -) - -var ( - testRecipientsConf []managementClient.Recipient - testRecipientsInterface []interface{} -) - -func init() { - testRecipientsConf = []managementClient.Recipient{ - { - NotifierID: "notifier_id", - NotifierType: "webhook", - Recipient: "recipient", - }, - } - testRecipientsInterface = []interface{}{ - map[string]interface{}{ - "notifier_id": "notifier_id", - "notifier_type": "webhook", - "recipient": "recipient", - }, - } -} - -func TestFlattenRecipients(t *testing.T) { - - cases := []struct { - Input []managementClient.Recipient - ExpectedOutput []interface{} - }{ - { - testRecipientsConf, - testRecipientsInterface, - }, - } - - for _, tc := range cases { - output := flattenRecipients(tc.Input) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from flattener.") - } -} - -func TestExpandRecipients(t *testing.T) { - - cases := []struct { - Input []interface{} - ExpectedOutput []managementClient.Recipient - }{ - { - testRecipientsInterface, - testRecipientsConf, - }, - } - - for _, tc := range cases { - output := expandRecipients(tc.Input) - assert.Equal(t, tc.ExpectedOutput, output, "Unexpected output from expander.") - } -} diff --git a/website/rancher2.erb b/website/rancher2.erb index 298bbcc5..2f7544fe 100644 --- a/website/rancher2.erb +++ b/website/rancher2.erb @@ -67,9 +67,6 @@ > rancher2_node_template - > - rancher2_notifier - > rancher2_project @@ -187,9 +184,6 @@ > rancher2_node_template - > - rancher2_notifier - > rancher2_project