diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 54d802499..255a129d2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -96,5 +96,4 @@ jobs: NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY }} NEW_RELIC_REGION: ${{ secrets.NEW_RELIC_REGION }} NEW_RELIC_INSIGHTS_INSERT_KEY: ${{ secrets.NEW_RELIC_INSIGHTS_INSERT_KEY }} - NEW_RELIC_INSIGHTS_QUERY_KEY: ${{ secrets.NEW_RELIC_INSIGHTS_QUERY_KEY }} NR_ACC_TESTING: ${{ secrets.NR_ACC_TESTING }} diff --git a/newrelic/config.go b/newrelic/config.go index e3cf781cd..6b98ce8ba 100644 --- a/newrelic/config.go +++ b/newrelic/config.go @@ -130,35 +130,10 @@ func (c *Config) ClientInsightsInsert() (*insights.InsertClient, error) { return client, nil } -// ClientInsightsQuery returns a new Insights query client -func (c *Config) ClientInsightsQuery() (*insights.QueryClient, error) { - client := insights.NewQueryClient(c.InsightsQueryKey, c.InsightsAccountID) - - if c.InsightsQueryURL != "" { - insightsURL, err := url.Parse(c.InsightsQueryURL) - if err != nil { - return nil, fmt.Errorf("error parsing Insights URL: %q", err) - } - insightsURL.Path = fmt.Sprintf("%s/%s/query", insightsURL.Path, c.InsightsAccountID) - client.URL = insightsURL - } - - if len(c.InsightsQueryKey) > 1 { - if err := client.Validate(); err != nil { - return nil, err - } - } - - log.Printf("[INFO] New Relic Insights query client configured") - - return client, nil -} - // ProviderConfig for the custom provider type ProviderConfig struct { NewClient *nr.NewRelic InsightsInsertClient *insights.InsertClient - InsightsQueryClient *insights.QueryClient AccountID int PersonalAPIKey string } diff --git a/newrelic/provider.go b/newrelic/provider.go index 885ee188c..c940197bd 100644 --- a/newrelic/provider.go +++ b/newrelic/provider.go @@ -91,12 +91,6 @@ func Provider() terraform.ResourceProvider { Optional: true, DefaultFunc: schema.EnvDefaultFunc("NEW_RELIC_INSIGHTS_INSERT_URL", insightsInsertURL), }, - "insights_query_key": { - Type: schema.TypeString, - Optional: true, - DefaultFunc: schema.EnvDefaultFunc("NEW_RELIC_INSIGHTS_QUERY_KEY", nil), - Sensitive: true, - }, "insights_query_url": { Type: schema.TypeString, Optional: true, @@ -196,20 +190,9 @@ func providerConfigure(data *schema.ResourceData, terraformVersion string) (inte return nil, fmt.Errorf("error initializing New Relic Insights insert client: %w", err) } - insightsQueryConfig := Config{ - InsightsAccountID: strconv.Itoa(accountID), - InsightsQueryKey: data.Get("insights_query_key").(string), - InsightsQueryURL: data.Get("insights_query_url").(string), - } - clientInsightsQuery, err := insightsQueryConfig.ClientInsightsQuery() - if err != nil { - return nil, fmt.Errorf("error initializing New Relic Insights query client: %s", err) - } - providerConfig := ProviderConfig{ NewClient: client, InsightsInsertClient: clientInsightsInsert, - InsightsQueryClient: clientInsightsQuery, PersonalAPIKey: personalAPIKey, AccountID: accountID, } diff --git a/newrelic/resource_newrelic_insights_event_test.go b/newrelic/resource_newrelic_insights_event_test.go index d2c1e1290..db58ad4c3 100644 --- a/newrelic/resource_newrelic_insights_event_test.go +++ b/newrelic/resource_newrelic_insights_event_test.go @@ -1,7 +1,6 @@ package newrelic import ( - "errors" "fmt" "testing" "time" @@ -26,30 +25,6 @@ func TestAccNewRelicInsightsEvent_Basic(t *testing.T) { { Config: testAccCheckNewRelicInsightsEventConfig(eType, tNow), Check: resource.ComposeTestCheckFunc( - testAccCheckNewRelicInsightsEventExists( - "newrelic_insights_event.foo", - []string{ - fmt.Sprintf( - "SELECT * FROM tf_test_%s "+ - "WHERE event_test = 'checking floats' "+ - "AND a_float = 101.1 "+ - "AND timestamp = %d", - eType, tNow), - fmt.Sprintf( - "SELECT * FROM tf_test_%s "+ - "WHERE event_test = 'checking ints' "+ - "AND an_int = 42 "+ - "AND timestamp = %d", - eType, tNow), - fmt.Sprintf( - "SELECT * FROM tf_test_%s "+ - "WHERE event_test = 'checking strings' "+ - "AND a_string = 'a string' "+ - "AND another_string = 'another string' "+ - "AND timestamp = %d", - eType, tNow), - }, - ), resource.TestCheckResourceAttr("newrelic_insights_event.foo", "event.#", "3"), ), }, @@ -57,32 +32,6 @@ func TestAccNewRelicInsightsEvent_Basic(t *testing.T) { }) } -func testAccCheckNewRelicInsightsEventExists(n string, nrqls []string) 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 event ID is set") - } - - client := testAccProvider.Meta().(*ProviderConfig).InsightsQueryClient - - for _, nrql := range nrqls { - resp, err := client.QueryEvents(nrql) - if err != nil { - return err - } - if len(resp.Results) != 1 { - return errors.New("did not find Insights event") - } - } - - return nil - } -} - func testAccCheckNewRelicInsightsEventConfig(eType string, t int64) string { return fmt.Sprintf(` resource "newrelic_insights_event" "foo" {