Skip to content

Commit 2791495

Browse files
authored
Merge pull request #205 from SumoLogic/ssong-gcp-tpr
Remove references to GCP domain verification
2 parents 22da288 + eee80ae commit 2791495

File tree

4 files changed

+38
-89
lines changed

4 files changed

+38
-89
lines changed

sumologic/resource_sumologic_gcp_source.go

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package sumologic
22

33
import (
4-
"errors"
54
"fmt"
65
"log"
76
"strconv"
@@ -39,7 +38,7 @@ func resourceSumologicGCPSource() *schema.Resource {
3938
Type: schema.TypeList,
4039
Optional: true,
4140
ForceNew: true,
42-
MinItems: 1,
41+
MinItems: 0,
4342
MaxItems: 1,
4443
Elem: &schema.Resource{
4544
Schema: map[string]*schema.Schema{
@@ -56,7 +55,7 @@ func resourceSumologicGCPSource() *schema.Resource {
5655
Type: schema.TypeList,
5756
Optional: true,
5857
ForceNew: true,
59-
MinItems: 1,
58+
MinItems: 0,
6059
MaxItems: 1,
6160
Elem: &schema.Resource{
6261
Schema: map[string]*schema.Schema{
@@ -144,74 +143,11 @@ func resourceToGCPSource(d *schema.ResourceData) (GCPSource, error) {
144143
MessagePerRequest: d.Get("message_per_request").(bool),
145144
}
146145

147-
authSettings, errAuthSettings := getGCPAuthentication(d)
148-
if errAuthSettings != nil {
149-
return gcpSource, errAuthSettings
150-
}
151-
152-
pathSettings, errPathSettings := getGCPPathSettings(d)
153-
if errPathSettings != nil {
154-
return gcpSource, errPathSettings
155-
}
156-
157146
GCPResource := GCPResource{
158-
ServiceType: d.Get("content_type").(string),
159-
Authentication: authSettings,
160-
Path: pathSettings,
147+
ServiceType: d.Get("content_type").(string),
161148
}
162149

163150
gcpSource.ThirdPartyRef.Resources = append(gcpSource.ThirdPartyRef.Resources, GCPResource)
164151

165152
return gcpSource, nil
166153
}
167-
168-
func getGCPThirdPartyPathAttributes(GCPResource []GCPResource) []map[string]interface{} {
169-
170-
var s []map[string]interface{}
171-
172-
for _, t := range GCPResource {
173-
mapping := map[string]interface{}{
174-
"type": t.Path.Type,
175-
}
176-
s = append(s, mapping)
177-
}
178-
return s
179-
}
180-
181-
func getGCPAuthentication(d *schema.ResourceData) (GCPAuthentication, error) {
182-
auths := d.Get("authentication").([]interface{})
183-
authSettings := GCPAuthentication{}
184-
185-
if len(auths) > 0 {
186-
auth := auths[0].(map[string]interface{})
187-
switch authType := auth["type"].(string); authType {
188-
case "NoAuthentication":
189-
authSettings.Type = "NoAuthentication"
190-
default:
191-
errorMessage := fmt.Sprintf("[ERROR] Unknown authType: %v", authType)
192-
log.Print(errorMessage)
193-
return authSettings, errors.New(errorMessage)
194-
}
195-
}
196-
197-
return authSettings, nil
198-
}
199-
200-
func getGCPPathSettings(d *schema.ResourceData) (GCPPath, error) {
201-
pathSettings := GCPPath{}
202-
paths := d.Get("path").([]interface{})
203-
204-
if len(paths) > 0 {
205-
path := paths[0].(map[string]interface{})
206-
switch pathType := path["type"].(string); pathType {
207-
case "NoPathExpression":
208-
pathSettings.Type = "NoPathExpression"
209-
default:
210-
errorMessage := fmt.Sprintf("[ERROR] Unknown resourceType in path: %v", pathType)
211-
log.Print(errorMessage)
212-
return pathSettings, errors.New(errorMessage)
213-
}
214-
}
215-
216-
return pathSettings, nil
217-
}

sumologic/resource_sumologic_gcp_source_test.go

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ import (
1010
)
1111

1212
func TestAccSumologicGCPSource_create(t *testing.T) {
13+
testGCPSourceCreate(t, testAccSumologicGCPSourceConfig)
14+
testGCPSourceCreate(t, testAccSumologicGCPSourceConfigDeprecated)
15+
}
16+
17+
func TestAccSumologicGCPSource_update(t *testing.T) {
18+
testGCPSourceUpdate(t, testAccSumologicGCPSourceConfig)
19+
testGCPSourceUpdate(t, testAccSumologicGCPSourceConfigDeprecated)
20+
}
21+
22+
func testGCPSourceCreate(t *testing.T, getConfig func(string, string, string, string, string, string) string) {
1323
var gcpSource GCPSource
1424
var collector Collector
1525
cName, cDescription, cCategory := getRandomizedParams()
@@ -21,7 +31,7 @@ func TestAccSumologicGCPSource_create(t *testing.T) {
2131
CheckDestroy: testAccCheckGCPSourceDestroy,
2232
Steps: []resource.TestStep{
2333
{
24-
Config: testAccSumologicGCPSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory),
34+
Config: getConfig(cName, cDescription, cCategory, sName, sDescription, sCategory),
2535
Check: resource.ComposeTestCheckFunc(
2636
testAccCheckGCPSourceExists(resourceName, &gcpSource),
2737
testAccCheckGCPSourceValues(&gcpSource, sName, sDescription, sCategory),
@@ -40,7 +50,7 @@ func TestAccSumologicGCPSource_create(t *testing.T) {
4050
})
4151
}
4252

43-
func TestAccSumologicGCPSource_update(t *testing.T) {
53+
func testGCPSourceUpdate(t *testing.T, getConfig func(string, string, string, string, string, string) string) {
4454
var gcpSource GCPSource
4555
cName, cDescription, cCategory := getRandomizedParams()
4656
sName, sDescription, sCategory := getRandomizedParams()
@@ -52,7 +62,7 @@ func TestAccSumologicGCPSource_update(t *testing.T) {
5262
CheckDestroy: testAccCheckGCPSourceDestroy,
5363
Steps: []resource.TestStep{
5464
{
55-
Config: testAccSumologicGCPSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory),
65+
Config: getConfig(cName, cDescription, cCategory, sName, sDescription, sCategory),
5666
Check: resource.ComposeTestCheckFunc(
5767
testAccCheckGCPSourceExists(resourceName, &gcpSource),
5868
testAccCheckGCPSourceValues(&gcpSource, sName, sDescription, sCategory),
@@ -66,7 +76,7 @@ func TestAccSumologicGCPSource_update(t *testing.T) {
6676
),
6777
},
6878
{
69-
Config: testAccSumologicGCPSourceConfig(cName, cDescription, cCategory, sNameUpdated, sDescriptionUpdated, sCategoryUpdated),
79+
Config: getConfig(cName, cDescription, cCategory, sNameUpdated, sDescriptionUpdated, sCategoryUpdated),
7080
Check: resource.ComposeTestCheckFunc(
7181
testAccCheckGCPSourceExists(resourceName, &gcpSource),
7282
testAccCheckGCPSourceValues(&gcpSource, sNameUpdated, sDescriptionUpdated, sCategoryUpdated),
@@ -163,28 +173,35 @@ func testAccCheckGCPSourceValues(gcpSource *GCPSource, name, description, catego
163173
}
164174
}
165175

166-
func testAccSumologicGCPSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory string) string {
176+
func testGCPSourceTemplate(cName, cDescription, cCategory, sName, sDescription, sCategory, thirdPartyRef string) string {
167177
return fmt.Sprintf(`
168178
resource "sumologic_collector" "test" {
169179
name = "%s"
170180
description = "%s"
171181
category = "%s"
172182
}
173-
183+
174184
resource "sumologic_gcp_source" "gcp" {
175185
name = "%s"
176186
description = "%s"
177187
message_per_request = false
178188
category = "%s"
179-
collector_id = "${sumologic_collector.test.id}"
189+
collector_id = "${sumologic_collector.test.id}"%s
190+
}
191+
`, cName, cDescription, cCategory, sName, sDescription, sCategory, thirdPartyRef)
192+
}
193+
194+
func testAccSumologicGCPSourceConfig(cName, cDescription, cCategory, sName, sDescription, sCategory string) string {
195+
return testGCPSourceTemplate(cName, cDescription, cCategory, sName, sDescription, sCategory, "")
196+
}
197+
198+
func testAccSumologicGCPSourceConfigDeprecated(cName, cDescription, cCategory, sName, sDescription, sCategory string) string {
199+
deprecatedTPR := `
180200
authentication {
181201
type = "NoAuthentication"
182202
}
183-
184203
path {
185204
type = "NoPathExpression"
186-
}
187-
}
188-
189-
`, cName, cDescription, cCategory, sName, sDescription, sCategory)
205+
}`
206+
return testGCPSourceTemplate(cName, cDescription, cCategory, sName, sDescription, sCategory, deprecatedTPR)
190207
}

sumologic/sumologic_gcp_source.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ type GCPThirdPartyRef struct {
1717
}
1818

1919
type GCPResource struct {
20-
ServiceType string `json:"serviceType"`
21-
Authentication GCPAuthentication `json:"authentication,omitempty"`
22-
Path GCPPath `json:"path,omitempty"`
20+
ServiceType string `json:"serviceType"`
21+
Authentication *GCPAuthentication `json:"authentication,omitempty"`
22+
Path *GCPPath `json:"path,omitempty"`
2323
}
2424

2525
type GCPAuthentication struct {

website/docs/r/gcp_source.html.markdown

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ description: |-
88
# sumologic_gcp_source
99
Provides a [Sumo Logic Google Cloud Platform Source][2].
1010

11+
***Note:*** Google no longer requires a pub/sub domain to be [verified][3]. You no longer have to set up domain verification with your GCP Source endpoint.
12+
1113
## Example Usage
1214
```hcl
1315
@@ -16,13 +18,6 @@ resource "sumologic_gcp_source" "terraform_gcp_source" {
1618
description = "My description"
1719
category = "gcp"
1820
collector_id = "${sumologic_collector.collector.id}"
19-
authentication {
20-
type = "NoAuthentication"
21-
}
22-
23-
path {
24-
type = "NoPathExpression"
25-
}
2621
}
2722
2823
resource "sumologic_collector" "collector" {
@@ -55,3 +50,4 @@ terraform import sumologic_gcp_source.test my-test-collector/my-test-source
5550

5651
[1]: https://help.sumologic.com/Send_Data/Sources/03Use_JSON_to_Configure_Sources/JSON_Parameters_for_Hosted_Sources
5752
[2]: https://help.sumologic.com/03Send-Data/Sources/02Sources-for-Hosted-Collectors/Google-Cloud-Platform-Source
53+
[3]: https://cloud.google.com/pubsub/docs/push

0 commit comments

Comments
 (0)