Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3978.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-datasource
mongodbatlas_log_integration
```
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,11 @@ access-token-revoke: ## Revoke an OAuth2 access token. Usage: make access-token-
@go run ./tools/access-token/*.go revoke $(token)

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

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

.PHONY: add-datasource-if-exists ${filename} ${resource}
add-datasource-if-exists:
@if [ -f "internal/serviceapi/${resource}/data_source.go" ] && ! grep -q "${resource}.DataSource," "${filename}" 2>/dev/null; then \
make add-lines filename=${filename} find="project.DataSource," add="${resource}.DataSource,\n"; \
fi

.PHONY: change-lines ${filename} ${find} ${new}
change-lines:
rm -f file.tmp
Expand Down
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ func (p *MongodbtlasProvider) DataSources(context.Context) []func() datasource.D
apikeyprojectassignment.PluralDataSource,
advancedcluster.DataSource,
advancedcluster.PluralDataSource,
logintegration.DataSource,
}
analyticsDataSources := []func() datasource.DataSource{}
for _, dataSourceFunc := range dataSources {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions internal/serviceapi/logintegration/data_source.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions internal/serviceapi/logintegration/data_source_schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions internal/serviceapi/logintegration/resource.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions internal/serviceapi/logintegration/resource_schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 30 additions & 5 deletions internal/serviceapi/logintegration/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

const (
resourceName = "mongodbatlas_log_integration.test"
dataSourceName = "data.mongodbatlas_log_integration.test"
nonEmptyPrefixPath = "push-log-prefix-v3"
)

Expand All @@ -40,8 +41,10 @@ func basicTestCase(tb testing.TB) *resource.TestCase {
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
Config: configBasic(projectID, s3BucketName, s3BucketPolicyName, awsIAMRoleName, awsIAMRolePolicyName, nonEmptyPrefixPath, true, false, ""),
Check: resource.ComposeAggregateTestCheckFunc(commonChecks(s3BucketName, nonEmptyPrefixPath)...),
Config: configWithDataSource(projectID, s3BucketName, s3BucketPolicyName, awsIAMRoleName, awsIAMRolePolicyName, nonEmptyPrefixPath),
Check: resource.ComposeAggregateTestCheckFunc(
append(commonChecks(s3BucketName, nonEmptyPrefixPath), dataSourceChecks(s3BucketName, nonEmptyPrefixPath)...)...,
),
},
{
Config: configBasic(projectID, s3BucketName, s3BucketPolicyName, awsIAMRoleName, awsIAMRolePolicyName, nonEmptyPrefixPath, true, true, kmsKey),
Expand All @@ -62,6 +65,28 @@ func basicTestCase(tb testing.TB) *resource.TestCase {
}
}

func dataSourceChecks(s3BucketName, prefixPath string) []resource.TestCheckFunc {
mapChecks := map[string]string{
"bucket_name": s3BucketName,
"prefix_path": prefixPath,
"type": "S3_LOG_EXPORT",
"log_types.#": "1",
}
checks := acc.AddAttrChecks(dataSourceName, nil, mapChecks)
return acc.AddAttrSetChecks(dataSourceName, checks, "project_id", "iam_role_id", "id")
}

func configWithDataSource(projectID, s3BucketName, s3BucketPolicyName, awsIAMRoleName, awsIAMRolePolicyName, prefixPath string) string {
return fmt.Sprintf(`
%s

data "mongodbatlas_log_integration" "test" {
project_id = mongodbatlas_log_integration.test.project_id
id = mongodbatlas_log_integration.test.id
}
`, configBasic(projectID, s3BucketName, s3BucketPolicyName, awsIAMRoleName, awsIAMRolePolicyName, prefixPath, true, false, ""))
}

func commonChecks(s3BucketName, prefixPath string) []resource.TestCheckFunc {
mapChecks := map[string]string{
"bucket_name": s3BucketName,
Expand All @@ -88,12 +113,12 @@ func configBasic(projectID, s3BucketName, s3BucketPolicyName, awsIAMRoleName, aw

%[7]s
`, projectID, s3BucketName, s3BucketPolicyName, awsIAMRoleName, awsIAMRolePolicyName,
awsIAMroleAuthAndS3Config(s3BucketName), pushBasedLogExportConfig(usePrefixPath, useKmsKey, prefixPath, kmsKey))
awsIAMroleAuthAndS3Config(s3BucketName), logIntegrationConfig(usePrefixPath, useKmsKey, prefixPath, kmsKey))
}

// pushBasedLogExportConfig returns config for mongodbatlas_log_integration resource.
// logIntegrationConfig returns config for mongodbatlas_log_integration resource.
// This method uses the project and S3 bucket created in awsIAMroleAuthAndS3Config()
func pushBasedLogExportConfig(usePrefixPath, useKmsKey bool, prefixPath, kmsKey string) string {
func logIntegrationConfig(usePrefixPath, useKmsKey bool, prefixPath, kmsKey string) string {
prefixPathAttr := ""
if usePrefixPath {
prefixPathAttr = fmt.Sprintf("prefix_path = %[1]q", prefixPath)
Expand Down
14 changes: 14 additions & 0 deletions tools/codegen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -856,3 +856,17 @@ resources:
schema:
aliases:
groupId: projectId
alertConfigId: integrationId
id: integrationId
datasources:
read:
path: /api/atlas/v2/groups/{groupId}/logIntegrations/{id}
method: GET
list:
path: /api/atlas/v2/groups/{groupId}/logIntegrations/
method: GET
schema:
aliases:
groupId: projectId
alertConfigId: integrationId
id: integrationId
Loading