From 357c0232d3dda3b9286996b90c3c28be34c134ec Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 4 May 2021 09:21:23 -0400 Subject: [PATCH] d/aws_cloudwatch_event_source: New data source moved into #19219. --- .changelog/19072.txt | 4 - ...data_source_aws_cloudwatch_event_source.go | 73 ------------------- ...source_aws_cloudwatch_event_source_test.go | 51 ------------- aws/provider.go | 1 - .../d/cloudwatch_event_source.html.markdown | 40 ---------- 5 files changed, 169 deletions(-) delete mode 100644 aws/data_source_aws_cloudwatch_event_source.go delete mode 100644 aws/data_source_aws_cloudwatch_event_source_test.go delete mode 100644 website/docs/d/cloudwatch_event_source.html.markdown diff --git a/.changelog/19072.txt b/.changelog/19072.txt index d9a398f0a9d..6e7ceeb7c25 100644 --- a/.changelog/19072.txt +++ b/.changelog/19072.txt @@ -1,7 +1,3 @@ ```release-note:enhancement resource/aws_cloudwatch_event_bus: Support partner event bus creation ``` - -```release-note:new-data-source -aws_cloudwatch_event_source -``` diff --git a/aws/data_source_aws_cloudwatch_event_source.go b/aws/data_source_aws_cloudwatch_event_source.go deleted file mode 100644 index 4facf88f9b1..00000000000 --- a/aws/data_source_aws_cloudwatch_event_source.go +++ /dev/null @@ -1,73 +0,0 @@ -package aws - -import ( - "fmt" - "log" - - "github.com/aws/aws-sdk-go/aws" - events "github.com/aws/aws-sdk-go/service/cloudwatchevents" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) - -func dataSourceAwsCloudWatchEventSource() *schema.Resource { - return &schema.Resource{ - Read: dataSourceAwsCloudWatchEventSourceRead, - - Schema: map[string]*schema.Schema{ - "arn": { - Type: schema.TypeString, - Computed: true, - }, - "name_prefix": { - Type: schema.TypeString, - Optional: true, - }, - "name": { - Type: schema.TypeString, - Computed: true, - }, - "created_by": { - Type: schema.TypeString, - Computed: true, - }, - "state": { - Type: schema.TypeString, - Computed: true, - }, - }, - } -} - -func dataSourceAwsCloudWatchEventSourceRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).cloudwatcheventsconn - - input := &events.ListEventSourcesInput{} - if v, ok := d.GetOk("name_prefix"); ok { - input.NamePrefix = aws.String(v.(string)) - } - - log.Printf("[DEBUG] Listing cloudwatch Event sources: %s", input) - - resp, err := conn.ListEventSources(input) - if err != nil { - return fmt.Errorf("error listing cloudwatch event sources: %w", err) - } - - if resp == nil || len(resp.EventSources) == 0 { - return fmt.Errorf("no matching partner event source") - } - if len(resp.EventSources) > 1 { - return fmt.Errorf("multiple event sources matched; use additional constraints to reduce matches to a single event source") - } - - es := resp.EventSources[0] - - d.SetId(aws.StringValue(es.Name)) - d.Set("arn", es.Arn) - d.Set("created_by", es.CreatedBy) - d.Set("name", es.Name) - d.Set("state", es.State) - - return nil -} diff --git a/aws/data_source_aws_cloudwatch_event_source_test.go b/aws/data_source_aws_cloudwatch_event_source_test.go deleted file mode 100644 index 4ea37acc63a..00000000000 --- a/aws/data_source_aws_cloudwatch_event_source_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package aws - -import ( - "fmt" - "os" - "strings" - "testing" - - "github.com/aws/aws-sdk-go/service/cloudwatchevents" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" -) - -func TestAccDataSourceAwsCloudWatchEventSource(t *testing.T) { - //resourceName := "aws_cloudwatch_event_bus.test" - dataSourceName := "data.aws_cloudwatch_event_source.test" - - key := "EVENT_BRIDGE_PARTNER_EVENT_BUS_NAME" - busName := os.Getenv(key) - if busName == "" { - t.Skipf("Environment variable %s is not set", key) - } - parts := strings.Split(busName, "/") - if len(parts) < 2 { - t.Errorf("unable to parse partner event bus name %s", busName) - } - namePrefix := parts[0] + "/" + parts[1] - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: testAccAwsDataSourcePartnerEventSourceConfig(namePrefix), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "name", busName), - resource.TestCheckResourceAttr(dataSourceName, "created_by", namePrefix), - resource.TestCheckResourceAttrSet(dataSourceName, "arn"), - ), - }, - }, - }) -} - -func testAccAwsDataSourcePartnerEventSourceConfig(namePrefix string) string { - return fmt.Sprintf(` -data "aws_cloudwatch_event_source" "test" { - name_prefix = "%s" -} -`, namePrefix) -} diff --git a/aws/provider.go b/aws/provider.go index 495289c981e..745c64e4937 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -217,7 +217,6 @@ func Provider() *schema.Provider { "aws_cloudfront_origin_request_policy": dataSourceAwsCloudFrontOriginRequestPolicy(), "aws_cloudhsm_v2_cluster": dataSourceCloudHsmV2Cluster(), "aws_cloudtrail_service_account": dataSourceAwsCloudTrailServiceAccount(), - "aws_cloudwatch_event_source": dataSourceAwsCloudWatchEventSource(), "aws_cloudwatch_log_group": dataSourceAwsCloudwatchLogGroup(), "aws_codeartifact_authorization_token": dataSourceAwsCodeArtifactAuthorizationToken(), "aws_codeartifact_repository_endpoint": dataSourceAwsCodeArtifactRepositoryEndpoint(), diff --git a/website/docs/d/cloudwatch_event_source.html.markdown b/website/docs/d/cloudwatch_event_source.html.markdown deleted file mode 100644 index 95c39bdab07..00000000000 --- a/website/docs/d/cloudwatch_event_source.html.markdown +++ /dev/null @@ -1,40 +0,0 @@ ---- -subcategory: "CloudWatch" -layout: "aws" -page_title: "AWS: aws_cloudwatch_event_source" -description: |- - Get information on an EventBridge (Cloudwatch) Event Source. ---- - -# Data Source: aws_cloudwatch_event_source - -Use this data source to get information about an EventBridge Partner Event Source. This data source will only return one partner event source. An error will be returned if multiple sources match the same name prefix. - -~> **Note:** EventBridge was formerly known as CloudWatch Events. The functionality is identical. - -## Example Usage - -```terraform -data "aws_cloudwatch_event_source" "examplepartner" { - name_prefix = "aws.partner/examplepartner.com" -} - -resource "aws_cloudwatch_event_bus" "examplepartner" { - name = data.aws_cloudwatch_event_source.examplepartner.name - event_source_name = data.aws_cloudwatch_event_source.examplepartner.name -} -``` - -## Argument Reference - -The following arguments are supported: - -* `name_prefix` - (Optional) A name prefix to filter results returned. Only API destinations with a name that starts with the prefix are returned - -## Attributes Reference - -In addition to all arguments above, the following attributes are exported: - -* `arn` - The ARN of the Partner event source -* `created_by` - The name of the SaaS partner that created the event source. -* `state` - The state of the event source (`ACTIVE` or `PENDING`)