diff --git a/CHANGELOG.md b/CHANGELOG.md index 648cb343..490c7e75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased] ### Added +- Rename and deprecate elasticsearch_{monitor,destination} to be under opendistro, elasticsearch_{monitor,destination} - Bump terraform plugin sdk to 1.12.0. - Add aws profile authentication option diff --git a/es/provider.go b/es/provider.go index bf5ab350..1851eeff 100644 --- a/es/provider.go +++ b/es/provider.go @@ -128,17 +128,19 @@ func Provider() terraform.ResourceProvider { }, ResourcesMap: map[string]*schema.Resource{ - "elasticsearch_destination": resourceElasticsearchDestination(), + "elasticsearch_destination": resourceElasticsearchDeprecatedDestination(), "elasticsearch_index": resourceElasticsearchIndex(), "elasticsearch_index_lifecycle_policy": resourceElasticsearchIndexLifecyclePolicy(), "elasticsearch_index_template": resourceElasticsearchIndexTemplate(), "elasticsearch_ingest_pipeline": resourceElasticsearchIngestPipeline(), "elasticsearch_kibana_object": resourceElasticsearchKibanaObject(), - "elasticsearch_monitor": resourceElasticsearchMonitor(), + "elasticsearch_monitor": resourceElasticsearchDeprecatedMonitor(), "elasticsearch_snapshot_repository": resourceElasticsearchSnapshotRepository(), "elasticsearch_watch": resourceElasticsearchDeprecatedWatch(), + "elasticsearch_opendistro_destination": resourceElasticsearchOpenDistroDestination(), "elasticsearch_opendistro_ism_policy": resourceElasticsearchOpenDistroISMPolicy(), "elasticsearch_opendistro_ism_policy_mapping": resourceElasticsearchOpenDistroISMPolicyMapping(), + "elasticsearch_opendistro_monitor": resourceElasticsearchOpenDistroMonitor(), "elasticsearch_opendistro_roles_mapping": resourceElasticsearchOpenDistroRolesMapping(), "elasticsearch_opendistro_role": resourceElasticsearchOpenDistroRole(), "elasticsearch_xpack_role": resourceElasticsearchXpackRole(), diff --git a/es/resource_elasticsearch_destination.go b/es/resource_elasticsearch_opendistro_destination.go similarity index 68% rename from es/resource_elasticsearch_destination.go rename to es/resource_elasticsearch_opendistro_destination.go index e3b8eebb..2d50e5da 100644 --- a/es/resource_elasticsearch_destination.go +++ b/es/resource_elasticsearch_opendistro_destination.go @@ -18,28 +18,44 @@ import ( const DESTINATION_TYPE = "_doc" const DESTINATION_INDEX = ".opendistro-alerting-config" -func resourceElasticsearchDestination() *schema.Resource { +var openDistroDestinationSchema = map[string]*schema.Schema{ + "body": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: diffSuppressDestination, + ValidateFunc: validation.StringIsJSON, + }, +} + +func resourceElasticsearchDeprecatedDestination() *schema.Resource { return &schema.Resource{ - Create: resourceElasticsearchDestinationCreate, - Read: resourceElasticsearchDestinationRead, - Update: resourceElasticsearchDestinationUpdate, - Delete: resourceElasticsearchDestinationDelete, - Schema: map[string]*schema.Schema{ - "body": { - Type: schema.TypeString, - Required: true, - DiffSuppressFunc: diffSuppressDestination, - ValidateFunc: validation.StringIsJSON, - }, + Create: resourceElasticsearchOpenDistroDestinationCreate, + Read: resourceElasticsearchOpenDistroDestinationRead, + Update: resourceElasticsearchOpenDistroDestinationUpdate, + Delete: resourceElasticsearchOpenDistroDestinationDelete, + Schema: openDistroDestinationSchema, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, }, + DeprecationMessage: "elasticsearch_destination is deprecated, please use elasticsearch_opendistro_destination resource instead.", + } +} + +func resourceElasticsearchOpenDistroDestination() *schema.Resource { + return &schema.Resource{ + Create: resourceElasticsearchOpenDistroDestinationCreate, + Read: resourceElasticsearchOpenDistroDestinationRead, + Update: resourceElasticsearchOpenDistroDestinationUpdate, + Delete: resourceElasticsearchOpenDistroDestinationDelete, + Schema: openDistroDestinationSchema, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, } } -func resourceElasticsearchDestinationCreate(d *schema.ResourceData, m interface{}) error { - res, err := resourceElasticsearchPostDestination(d, m) +func resourceElasticsearchOpenDistroDestinationCreate(d *schema.ResourceData, m interface{}) error { + res, err := resourceElasticsearchOpenDistroPostDestination(d, m) if err != nil { log.Printf("[INFO] Failed to put destination: %+v", err) @@ -56,8 +72,8 @@ func resourceElasticsearchDestinationCreate(d *schema.ResourceData, m interface{ return nil } -func resourceElasticsearchDestinationRead(d *schema.ResourceData, m interface{}) error { - res, err := resourceElasticsearchGetDestination(d.Id(), m) +func resourceElasticsearchOpenDistroDestinationRead(d *schema.ResourceData, m interface{}) error { + res, err := resourceElasticsearchOpenDistroGetDestination(d.Id(), m) if elastic6.IsNotFound(err) || elastic7.IsNotFound(err) { log.Printf("[WARN] Destination (%s) not found, removing from state", d.Id()) @@ -74,17 +90,17 @@ func resourceElasticsearchDestinationRead(d *schema.ResourceData, m interface{}) return nil } -func resourceElasticsearchDestinationUpdate(d *schema.ResourceData, m interface{}) error { - _, err := resourceElasticsearchPutDestination(d, m) +func resourceElasticsearchOpenDistroDestinationUpdate(d *schema.ResourceData, m interface{}) error { + _, err := resourceElasticsearchOpenDistroPutDestination(d, m) if err != nil { return err } - return resourceElasticsearchDestinationRead(d, m) + return resourceElasticsearchOpenDistroDestinationRead(d, m) } -func resourceElasticsearchDestinationDelete(d *schema.ResourceData, m interface{}) error { +func resourceElasticsearchOpenDistroDestinationDelete(d *schema.ResourceData, m interface{}) error { var err error path, err := uritemplates.Expand("/_opendistro/_alerting/destinations/{id}", map[string]string{ @@ -112,7 +128,7 @@ func resourceElasticsearchDestinationDelete(d *schema.ResourceData, m interface{ return err } -func resourceElasticsearchGetDestination(destinationID string, m interface{}) (string, error) { +func resourceElasticsearchOpenDistroGetDestination(destinationID string, m interface{}) (string, error) { var err error response := new(destinationResponse) @@ -143,7 +159,7 @@ func resourceElasticsearchGetDestination(destinationID string, m interface{}) (s return string(tj), err } -func resourceElasticsearchPostDestination(d *schema.ResourceData, m interface{}) (*destinationResponse, error) { +func resourceElasticsearchOpenDistroPostDestination(d *schema.ResourceData, m interface{}) (*destinationResponse, error) { destinationJSON := d.Get("body").(string) var err error @@ -184,7 +200,7 @@ func resourceElasticsearchPostDestination(d *schema.ResourceData, m interface{}) return response, nil } -func resourceElasticsearchPutDestination(d *schema.ResourceData, m interface{}) (*destinationResponse, error) { +func resourceElasticsearchOpenDistroPutDestination(d *schema.ResourceData, m interface{}) (*destinationResponse, error) { destinationJSON := d.Get("body").(string) var err error diff --git a/es/resource_elasticsearch_destination_test.go b/es/resource_elasticsearch_opendistro_destination_test.go similarity index 68% rename from es/resource_elasticsearch_destination_test.go rename to es/resource_elasticsearch_opendistro_destination_test.go index f7920ccd..9db2eef6 100644 --- a/es/resource_elasticsearch_destination_test.go +++ b/es/resource_elasticsearch_opendistro_destination_test.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccElasticsearchDestination(t *testing.T) { +func TestAccElasticsearchOpenDistroDestination(t *testing.T) { provider := Provider().(*schema.Provider) err := provider.Configure(&terraform.ResourceConfig{}) if err != nil { @@ -38,19 +38,19 @@ func TestAccElasticsearchDestination(t *testing.T) { } }, Providers: testAccOpendistroProviders, - CheckDestroy: testCheckElasticsearchDestinationDestroy, + CheckDestroy: testCheckElasticsearchOpenDistroDestinationDestroy, Steps: []resource.TestStep{ { - Config: testAccElasticsearchDestination, + Config: testAccElasticsearchOpenDistroDestination, Check: resource.ComposeTestCheckFunc( - testCheckElasticsearchDestinationExists("elasticsearch_destination.test_destination"), + testCheckElasticsearchOpenDistroDestinationExists("elasticsearch_opendistro_destination.test_destination"), ), }, }, }) } -func TestAccElasticsearchDestination_importBasic(t *testing.T) { +func TestAccElasticsearchOpenDistroDestination_importBasic(t *testing.T) { provider := Provider().(*schema.Provider) err := provider.Configure(&terraform.ResourceConfig{}) if err != nil { @@ -75,13 +75,13 @@ func TestAccElasticsearchDestination_importBasic(t *testing.T) { } }, Providers: testAccOpendistroProviders, - CheckDestroy: testCheckElasticsearchDestinationDestroy, + CheckDestroy: testCheckElasticsearchOpenDistroDestinationDestroy, Steps: []resource.TestStep{ { - Config: testAccElasticsearchDestination, + Config: testAccElasticsearchOpenDistroDestination, }, { - ResourceName: "elasticsearch_destination.test_destination", + ResourceName: "elasticsearch_opendistro_destination.test_destination", ImportState: true, ImportStateVerify: true, }, @@ -89,7 +89,7 @@ func TestAccElasticsearchDestination_importBasic(t *testing.T) { }) } -func testCheckElasticsearchDestinationExists(name string) resource.TestCheckFunc { +func testCheckElasticsearchOpenDistroDestinationExists(name string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -104,9 +104,9 @@ func testCheckElasticsearchDestinationExists(name string) resource.TestCheckFunc var err error switch client := meta.(type) { case *elastic7.Client: - _, err = resourceElasticsearchGetDestination(rs.Primary.ID, client) + _, err = resourceElasticsearchOpenDistroGetDestination(rs.Primary.ID, client) case *elastic6.Client: - _, err = resourceElasticsearchGetDestination(rs.Primary.ID, client) + _, err = resourceElasticsearchOpenDistroGetDestination(rs.Primary.ID, client) default: } @@ -118,9 +118,9 @@ func testCheckElasticsearchDestinationExists(name string) resource.TestCheckFunc } } -func testCheckElasticsearchDestinationDestroy(s *terraform.State) error { +func testCheckElasticsearchOpenDistroDestinationDestroy(s *terraform.State) error { for _, rs := range s.RootModule().Resources { - if rs.Type != "elasticsearch_destination" { + if rs.Type != "elasticsearch_opendistro_destination" { continue } @@ -129,9 +129,9 @@ func testCheckElasticsearchDestinationDestroy(s *terraform.State) error { var err error switch client := meta.(type) { case *elastic7.Client: - _, err = resourceElasticsearchGetDestination(rs.Primary.ID, client) + _, err = resourceElasticsearchOpenDistroGetDestination(rs.Primary.ID, client) case *elastic6.Client: - _, err = resourceElasticsearchGetDestination(rs.Primary.ID, client) + _, err = resourceElasticsearchOpenDistroGetDestination(rs.Primary.ID, client) default: } @@ -145,8 +145,8 @@ func testCheckElasticsearchDestinationDestroy(s *terraform.State) error { return nil } -var testAccElasticsearchDestination = ` -resource "elasticsearch_destination" "test_destination" { +var testAccElasticsearchOpenDistroDestination = ` +resource "elasticsearch_opendistro_destination" "test_destination" { body = <