Skip to content

Commit dd49c69

Browse files
authored
feat: Adds mongodbatlas_log_integration data source (#3978)
* generate data source of log integration * add data source to the provider and make data sources be added when running make enable-autogen * changelog * regenerate * add alias
1 parent 8ab1d8a commit dd49c69

File tree

10 files changed

+312
-30
lines changed

10 files changed

+312
-30
lines changed

.changelog/3978.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-datasource
2+
mongodbatlas_log_integration
3+
```

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,11 @@ access-token-revoke: ## Revoke an OAuth2 access token. Usage: make access-token-
219219
@go run ./tools/access-token/*.go revoke $(token)
220220

221221
.PHONY: enable-autogen
222-
enable-autogen: ## Enable use of autogen resources in the provider
222+
enable-autogen: ## Enable use of autogen resources and data sources in the provider
223223
$(eval filename := ./internal/provider/provider.go)
224224
$(eval resources := $(shell ls -d internal/serviceapi/*/ | xargs -n1 basename))
225225
$(foreach resource,$(resources),make add-lines-if-missing filename=${filename} resource=${resource};)
226+
$(foreach resource,$(resources),make add-datasource-if-exists filename=${filename} resource=${resource};)
226227
goimports -w ${filename}
227228

228229
.PHONY: delete-lines ${filename} ${delete}
@@ -244,6 +245,12 @@ add-lines-if-missing:
244245
make add-lines filename=${filename} find="project.Resource," add="${resource}.Resource,\n"; \
245246
fi
246247

248+
.PHONY: add-datasource-if-exists ${filename} ${resource}
249+
add-datasource-if-exists:
250+
@if [ -f "internal/serviceapi/${resource}/data_source.go" ] && ! grep -q "${resource}.DataSource," "${filename}" 2>/dev/null; then \
251+
make add-lines filename=${filename} find="project.DataSource," add="${resource}.DataSource,\n"; \
252+
fi
253+
247254
.PHONY: change-lines ${filename} ${find} ${new}
248255
change-lines:
249256
rm -f file.tmp

internal/provider/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ func (p *MongodbtlasProvider) DataSources(context.Context) []func() datasource.D
302302
apikeyprojectassignment.PluralDataSource,
303303
advancedcluster.DataSource,
304304
advancedcluster.PluralDataSource,
305+
logintegration.DataSource,
305306
}
306307
analyticsDataSources := []func() datasource.DataSource{}
307308
for _, dataSourceFunc := range dataSources {

internal/serviceapi/logintegration/data_source.go

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/serviceapi/logintegration/data_source_schema.go

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/serviceapi/logintegration/resource.go

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/serviceapi/logintegration/resource_schema.go

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/serviceapi/logintegration/resource_test.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
const (
1616
resourceName = "mongodbatlas_log_integration.test"
17+
dataSourceName = "data.mongodbatlas_log_integration.test"
1718
nonEmptyPrefixPath = "push-log-prefix-v3"
1819
)
1920

@@ -40,8 +41,10 @@ func basicTestCase(tb testing.TB) *resource.TestCase {
4041
CheckDestroy: checkDestroy,
4142
Steps: []resource.TestStep{
4243
{
43-
Config: configBasic(projectID, s3BucketName, s3BucketPolicyName, awsIAMRoleName, awsIAMRolePolicyName, nonEmptyPrefixPath, true, false, ""),
44-
Check: resource.ComposeAggregateTestCheckFunc(commonChecks(s3BucketName, nonEmptyPrefixPath)...),
44+
Config: configWithDataSource(projectID, s3BucketName, s3BucketPolicyName, awsIAMRoleName, awsIAMRolePolicyName, nonEmptyPrefixPath),
45+
Check: resource.ComposeAggregateTestCheckFunc(
46+
append(commonChecks(s3BucketName, nonEmptyPrefixPath), dataSourceChecks(s3BucketName, nonEmptyPrefixPath)...)...,
47+
),
4548
},
4649
{
4750
Config: configBasic(projectID, s3BucketName, s3BucketPolicyName, awsIAMRoleName, awsIAMRolePolicyName, nonEmptyPrefixPath, true, true, kmsKey),
@@ -62,6 +65,28 @@ func basicTestCase(tb testing.TB) *resource.TestCase {
6265
}
6366
}
6467

68+
func dataSourceChecks(s3BucketName, prefixPath string) []resource.TestCheckFunc {
69+
mapChecks := map[string]string{
70+
"bucket_name": s3BucketName,
71+
"prefix_path": prefixPath,
72+
"type": "S3_LOG_EXPORT",
73+
"log_types.#": "1",
74+
}
75+
checks := acc.AddAttrChecks(dataSourceName, nil, mapChecks)
76+
return acc.AddAttrSetChecks(dataSourceName, checks, "project_id", "iam_role_id", "id")
77+
}
78+
79+
func configWithDataSource(projectID, s3BucketName, s3BucketPolicyName, awsIAMRoleName, awsIAMRolePolicyName, prefixPath string) string {
80+
return fmt.Sprintf(`
81+
%s
82+
83+
data "mongodbatlas_log_integration" "test" {
84+
project_id = mongodbatlas_log_integration.test.project_id
85+
id = mongodbatlas_log_integration.test.id
86+
}
87+
`, configBasic(projectID, s3BucketName, s3BucketPolicyName, awsIAMRoleName, awsIAMRolePolicyName, prefixPath, true, false, ""))
88+
}
89+
6590
func commonChecks(s3BucketName, prefixPath string) []resource.TestCheckFunc {
6691
mapChecks := map[string]string{
6792
"bucket_name": s3BucketName,
@@ -88,12 +113,12 @@ func configBasic(projectID, s3BucketName, s3BucketPolicyName, awsIAMRoleName, aw
88113
89114
%[7]s
90115
`, projectID, s3BucketName, s3BucketPolicyName, awsIAMRoleName, awsIAMRolePolicyName,
91-
awsIAMroleAuthAndS3Config(s3BucketName), pushBasedLogExportConfig(usePrefixPath, useKmsKey, prefixPath, kmsKey))
116+
awsIAMroleAuthAndS3Config(s3BucketName), logIntegrationConfig(usePrefixPath, useKmsKey, prefixPath, kmsKey))
92117
}
93118

94-
// pushBasedLogExportConfig returns config for mongodbatlas_log_integration resource.
119+
// logIntegrationConfig returns config for mongodbatlas_log_integration resource.
95120
// This method uses the project and S3 bucket created in awsIAMroleAuthAndS3Config()
96-
func pushBasedLogExportConfig(usePrefixPath, useKmsKey bool, prefixPath, kmsKey string) string {
121+
func logIntegrationConfig(usePrefixPath, useKmsKey bool, prefixPath, kmsKey string) string {
97122
prefixPathAttr := ""
98123
if usePrefixPath {
99124
prefixPathAttr = fmt.Sprintf("prefix_path = %[1]q", prefixPath)

tools/codegen/config.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,3 +856,17 @@ resources:
856856
schema:
857857
aliases:
858858
groupId: projectId
859+
alertConfigId: integrationId
860+
id: integrationId
861+
datasources:
862+
read:
863+
path: /api/atlas/v2/groups/{groupId}/logIntegrations/{id}
864+
method: GET
865+
list:
866+
path: /api/atlas/v2/groups/{groupId}/logIntegrations/
867+
method: GET
868+
schema:
869+
aliases:
870+
groupId: projectId
871+
alertConfigId: integrationId
872+
id: integrationId

0 commit comments

Comments
 (0)