Skip to content

Commit d0b898b

Browse files
authored
Merge pull request #688 from SumoLogic/adding_TF_support_for_DF_rules
Adding TF support for configuring Data Forwarding Rules
2 parents bd9ed6b + 1d024cb commit d0b898b

9 files changed

+730
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
DEPRECATIONS:
33
* resource_sumologic_ingest_budget : Deprecated in favour of `resource_sumologic_ingest_budget_v2`.
44

5+
## 2.31.4 (September 19, 2024)
6+
* **New Resource:** sumologic_data_forwarding_destination (GH-678)
7+
* **New Resource:** sumologic_data_forwarding_rule (GH-688)
8+
59
## 2.31.3 (August 28, 2024)
610
ENHANCEMENTS:
711
* Add time source and parse mode to dashboard search panel query (GH-679)

sumologic/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func Provider() terraform.ResourceProvider {
9393
"sumologic_content": resourceSumologicContent(),
9494
"sumologic_scheduled_view": resourceSumologicScheduledView(),
9595
"sumologic_data_forwarding_destination": resourceSumologicDataForwardingDestination(),
96+
"sumologic_data_forwarding_rule": resourceSumologicDataForwardingRule(),
9697
"sumologic_partition": resourceSumologicPartition(),
9798
"sumologic_field_extraction_rule": resourceSumologicFieldExtractionRule(),
9899
"sumologic_connection": resourceSumologicConnection(),

sumologic/resource_sumologic_data_forwarding_destination.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ func resourceSumologicDataForwardingDestination() *schema.Resource {
5858
},
5959
},
6060
},
61+
"enabled": {
62+
Type: schema.TypeBool,
63+
Optional: true,
64+
Default: false,
65+
},
6166
"s3_region": {
6267
Type: schema.TypeString,
6368
Optional: true,
@@ -124,6 +129,7 @@ func resourceSumologicDataForwardingDestinationRead(d *schema.ResourceData, meta
124129
d.Set("description", dataForwardingDestination.Description)
125130
d.Set("bucket_name", dataForwardingDestination.BucketName)
126131
d.Set("S3_region", dataForwardingDestination.S3Region)
132+
d.Set("enabled", dataForwardingDestination.Enabled)
127133
d.Set("S3_server_side_encryption", dataForwardingDestination.S3ServerSideEncryption)
128134

129135
return nil
@@ -149,6 +155,7 @@ func resourceToDataForwardingDestination(d *schema.ResourceData) DataForwardingD
149155
AccessKey: authentication["access_key"].(string),
150156
SecretKey: authentication["secret_key"].(string),
151157
RoleArn: authentication["role_arn"].(string),
158+
Enabled: d.Get("enabled").(bool),
152159
S3Region: d.Get("s3_region").(string),
153160
S3ServerSideEncryption: d.Get("s3_server_side_encryption").(bool),
154161
}
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
package sumologic
2+
3+
// Todo: (ngoyal, 09-19-2024) - Uncomment the test cases once the issue with PUT permissions on SUMOLOGIC_TEST_BUCKET_NAME is fixed
4+
5+
/*
6+
7+
import (
8+
"fmt"
9+
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
10+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
11+
"github.com/hashicorp/terraform-plugin-sdk/terraform"
12+
"os"
13+
"strings"
14+
"testing"
15+
)
16+
17+
func getTestParams() (string, string, string, string, string, string) {
18+
dataForwardingDestinationResourceName := "sumologic_data_forwarding_destination.test"
19+
destinationName, description := getRandomizedDataForwardingDestinationParams()
20+
testAwsRoleArn := os.Getenv("SUMOLOGIC_TEST_ROLE_ARN")
21+
testAwsBucket := os.Getenv("SUMOLOGIC_TEST_BUCKET_NAME")
22+
testAwsRegion := os.Getenv("SUMOLOGIC_TEST_AWS_REGION")
23+
println("AWS Test Bucket: ", testAwsBucket)
24+
println("AWS Test ARN: ", testAwsRoleArn)
25+
println("AWS Test Region: ", testAwsRegion)
26+
return dataForwardingDestinationResourceName, destinationName, description, testAwsRegion, testAwsRoleArn, testAwsBucket
27+
}
28+
29+
func getRandomizedDataForwardingDestinationParams() (string, string) {
30+
destinationName := acctest.RandomWithPrefix("tf-acc-test")
31+
description := acctest.RandomWithPrefix("tf-acc-test")
32+
return destinationName, description
33+
}
34+
35+
func TestAccSumologicDataForwarding_create(t *testing.T) {
36+
dataForwardingDestinationResourceName, destinationName, description, testAwsRegion, testAwsRoleArn, testAwsBucket := getTestParams()
37+
resource.Test(t, resource.TestCase{
38+
PreCheck: func() { testAccPreCheckWithAWS(t) },
39+
Providers: testAccProviders,
40+
CheckDestroy: testAccCheckDataForwardingDestinationDestroy(),
41+
Steps: []resource.TestStep{
42+
{
43+
Config: testAccSumologicDataForwardingCreateConfig(destinationName, description, testAwsBucket, testAwsRoleArn, testAwsRegion),
44+
Check: resource.ComposeTestCheckFunc(
45+
testAccCheckDataForwardingDestinationExists(),
46+
resource.TestCheckResourceAttr(dataForwardingDestinationResourceName, "destination_name", destinationName),
47+
resource.TestCheckResourceAttr(dataForwardingDestinationResourceName, "description", description),
48+
resource.TestCheckResourceAttr(dataForwardingDestinationResourceName, "s3_region", testAwsRegion),
49+
resource.TestCheckResourceAttr(dataForwardingDestinationResourceName, "s3_server_side_encryption", "false"),
50+
),
51+
},
52+
},
53+
})
54+
}
55+
56+
func TestAccSumologicDataForwarding_read(t *testing.T) {
57+
dataForwardingResourceName, destinationName, description, testAwsRegion, testAwsRoleArn, testAwsBucket := getTestParams()
58+
resource.Test(t, resource.TestCase{
59+
PreCheck: func() { testAccPreCheckWithAWS(t) },
60+
Providers: testAccProviders,
61+
CheckDestroy: testAccCheckDataForwardingDestinationDestroy(),
62+
Steps: []resource.TestStep{
63+
{
64+
Config: testAccSumologicDataForwardingCreateConfig(destinationName, description, testAwsBucket, testAwsRoleArn, testAwsRegion),
65+
Check: resource.ComposeTestCheckFunc(
66+
testAccCheckDataForwardingDestinationExists(),
67+
resource.TestCheckResourceAttr(dataForwardingResourceName, "destination_name", destinationName),
68+
resource.TestCheckResourceAttr(dataForwardingResourceName, "description", description),
69+
resource.TestCheckResourceAttr(dataForwardingResourceName, "bucket_name", testAwsBucket),
70+
resource.TestCheckResourceAttr(dataForwardingResourceName, "s3_region", testAwsRegion),
71+
resource.TestCheckResourceAttr(dataForwardingResourceName, "s3_server_side_encryption", "false"),
72+
),
73+
},
74+
{
75+
ResourceName: dataForwardingResourceName,
76+
ImportState: true,
77+
},
78+
},
79+
})
80+
}
81+
82+
func TestAccSumologicDataForwarding_update(t *testing.T) {
83+
dataForwardingResourceName, destinationName, description, testAwsRegion, testAwsRoleArn, testAwsBucket := getTestParams()
84+
resource.Test(t, resource.TestCase{
85+
PreCheck: func() { testAccPreCheckWithAWS(t) },
86+
Providers: testAccProviders,
87+
CheckDestroy: testAccCheckDataForwardingDestinationDestroy(),
88+
Steps: []resource.TestStep{
89+
{
90+
Config: testAccSumologicDataForwardingCreateConfig(destinationName, description, testAwsBucket, testAwsRoleArn, testAwsRegion),
91+
Check: resource.ComposeTestCheckFunc(
92+
testAccCheckDataForwardingDestinationExists(),
93+
resource.TestCheckResourceAttr(dataForwardingResourceName, "destination_name", destinationName),
94+
resource.TestCheckResourceAttr(dataForwardingResourceName, "description", description),
95+
resource.TestCheckResourceAttr(dataForwardingResourceName, "s3_region", testAwsRegion),
96+
resource.TestCheckResourceAttr(dataForwardingResourceName, "s3_server_side_encryption", "false"),
97+
),
98+
}, {
99+
Config: testAccSumologicDataForwardingUpdateConfig(destinationName, description, testAwsBucket, testAwsRoleArn, testAwsRegion),
100+
Check: resource.ComposeTestCheckFunc(
101+
testAccCheckDataForwardingDestinationExists(),
102+
resource.TestCheckResourceAttr(dataForwardingResourceName, "destination_name", destinationName),
103+
resource.TestCheckResourceAttr(dataForwardingResourceName, "description", description),
104+
resource.TestCheckResourceAttr(dataForwardingResourceName, "s3_region", testAwsRegion),
105+
resource.TestCheckResourceAttr(dataForwardingResourceName, "s3_server_side_encryption", "true"),
106+
),
107+
},
108+
},
109+
})
110+
111+
}
112+
113+
func TestAccSumologicDataForwarding_delete(t *testing.T) {
114+
dataForwardingResourceName, destinationName, description, testAwsRegion, testAwsRoleArn, testAwsBucket := getTestParams()
115+
resource.Test(t, resource.TestCase{
116+
PreCheck: func() { testAccPreCheckWithAWS(t) },
117+
Providers: testAccProviders,
118+
CheckDestroy: testAccCheckDataForwardingDestinationDestroy(),
119+
Steps: []resource.TestStep{
120+
{
121+
Config: testAccSumologicDataForwardingCreateConfig(destinationName, description, testAwsBucket, testAwsRoleArn, testAwsRegion),
122+
Check: resource.ComposeTestCheckFunc(
123+
testAccCheckDataForwardingDestinationExists(),
124+
resource.TestCheckResourceAttr(dataForwardingResourceName, "destination_name", destinationName),
125+
resource.TestCheckResourceAttr(dataForwardingResourceName, "description", description),
126+
resource.TestCheckResourceAttr(dataForwardingResourceName, "s3_region", testAwsRegion),
127+
resource.TestCheckResourceAttr(dataForwardingResourceName, "s3_server_side_encryption", "false"),
128+
),
129+
}, {
130+
Config: testAccSumologicDataForwardingDeleteConfig(),
131+
Check: resource.ComposeTestCheckFunc(testAccCheckDataForwardingDestinationDestroy()),
132+
},
133+
},
134+
})
135+
}
136+
137+
func testAccCheckDataForwardingDestinationExists() resource.TestCheckFunc {
138+
return func(s *terraform.State) error {
139+
client := testAccProvider.Meta().(*Client)
140+
for _, r := range s.RootModule().Resources {
141+
id := r.Primary.ID
142+
if _, err := client.getDataForwardingDestination(id); err != nil {
143+
return fmt.Errorf("Received an error retrieving data forwarding destination %s", err)
144+
}
145+
}
146+
return nil
147+
}
148+
}
149+
150+
func testAccCheckDataForwardingDestinationDestroy() resource.TestCheckFunc {
151+
return func(s *terraform.State) error {
152+
client := testAccProvider.Meta().(*Client)
153+
for _, r := range s.RootModule().Resources {
154+
id := r.Primary.ID
155+
p, err := client.getDataForwardingDestination(id)
156+
157+
if err != nil {
158+
if strings.Contains(err.Error(), "Data forwarding Destination doesn't exists") {
159+
continue
160+
}
161+
162+
return fmt.Errorf("Encountered an error: " + err.Error())
163+
}
164+
165+
if p != nil {
166+
return fmt.Errorf("Data Forwarding Destination still exists!")
167+
}
168+
}
169+
return nil
170+
}
171+
}
172+
173+
func testAccSumologicDataForwardingCreateConfig(destinationName string, description string, testAwsBucket string, testAwsRoleArn string, testAwsRegion string) string {
174+
return fmt.Sprintf(`
175+
resource "sumologic_data_forwarding_destination" "test" {
176+
destination_name = "%s"
177+
description = "%s"
178+
bucket_name = "%s"
179+
authentication {
180+
type = "RoleBased"
181+
role_arn = "%s"
182+
}
183+
s3_region = "%s"
184+
s3_server_side_encryption = false
185+
}
186+
`, destinationName, description, testAwsBucket, testAwsRoleArn, testAwsRegion)
187+
}
188+
189+
func testAccSumologicDataForwardingUpdateConfig(destinationName string, description string, testAwsBucket string, testAwsRoleArn string, testAwsRegion string) string {
190+
return fmt.Sprintf(`
191+
resource "sumologic_data_forwarding_destination" "test" {
192+
destination_name = "%s"
193+
description = "%s"
194+
bucket_name = "%s"
195+
authentication {
196+
type = "RoleBased"
197+
role_arn = "%s"
198+
}
199+
s3_region = "%s"
200+
s3_server_side_encryption = true
201+
}
202+
`, destinationName, description, testAwsBucket, testAwsRoleArn, testAwsRegion)
203+
}
204+
205+
func testAccSumologicDataForwardingDeleteConfig() string {
206+
return fmt.Sprintf(` `)
207+
}
208+
*/

0 commit comments

Comments
 (0)