diff --git a/Makefile b/Makefile
index 98e083ecfa..dc555615ac 100644
--- a/Makefile
+++ b/Makefile
@@ -199,7 +199,7 @@ jira-release-version: ## Update Jira version in a release
.PHONY: enable-autogen
enable-autogen: ## Enable use of autogen resources in the provider
- make add-lines filename=./internal/provider/provider.go find="project.Resource," add="customdbroleapi.Resource,databaseuserapi.Resource,pushbasedlogexportapi.Resource,searchdeploymentapi.Resource,projectapi.Resource,resourcepolicyapi.Resource,"
+ make add-lines filename=./internal/provider/provider.go find="project.Resource," add="customdbroleapi.Resource,databaseuserapi.Resource,pushbasedlogexportapi.Resource,searchdeploymentapi.Resource,projectapi.Resource,resourcepolicyapi.Resource,streamconnectionapi.Resource,"
.PHONY: delete-lines ${filename} ${delete}
delete-lines:
diff --git a/docs/resources/stream_connection_api.md b/docs/resources/stream_connection_api.md
new file mode 100644
index 0000000000..a46de08573
--- /dev/null
+++ b/docs/resources/stream_connection_api.md
@@ -0,0 +1,248 @@
+# Resource: mongodbatlas_stream_connection_api
+
+
+## Schema
+
+### Required
+
+- `group_id` (String) Unique 24-hexadecimal digit string that identifies your project. Use the [/groups](#tag/Projects/operation/listProjects) endpoint to retrieve all projects to which the authenticated user has access.
+
+**NOTE**: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.
+- `tenant_name` (String) Human-readable label that identifies the stream instance.
+
+### Optional
+
+- `name` (String) Human-readable label that identifies the stream connection. In the case of the Sample type, this is the name of the sample source.
+- `type_awslambda` (Attributes) (see [below for nested schema](#nestedatt--type_awslambda))
+- `type_cluster` (Attributes) (see [below for nested schema](#nestedatt--type_cluster))
+- `type_https` (Attributes) (see [below for nested schema](#nestedatt--type_https))
+- `type_kafka` (Attributes) (see [below for nested schema](#nestedatt--type_kafka))
+- `type_s3` (Attributes) (see [below for nested schema](#nestedatt--type_s3))
+- `type_sample` (Attributes) (see [below for nested schema](#nestedatt--type_sample))
+
+### Read-Only
+
+- `links` (Attributes List) List of one or more Uniform Resource Locators (URLs) that point to API sub-resources, related API resources, or both. RFC 5988 outlines these relationships. (see [below for nested schema](#nestedatt--links))
+- `type` (String) Type of the connection.
+
+
+### Nested Schema for `type_awslambda`
+
+Optional:
+
+- `aws` (Attributes) AWS configurations for AWS-based connection types. (see [below for nested schema](#nestedatt--type_awslambda--aws))
+
+
+### Nested Schema for `type_awslambda.aws`
+
+Optional:
+
+- `role_arn` (String) Amazon Resource Name (ARN) that identifies the Amazon Web Services (AWS) Identity and Access Management (IAM) role that MongoDB Cloud assumes when it accesses resources in your AWS account.
+- `test_bucket` (String) The name of an S3 bucket used to check authorization of the passed-in IAM role ARN.
+
+Read-Only:
+
+- `links` (Attributes List) List of one or more Uniform Resource Locators (URLs) that point to API sub-resources, related API resources, or both. RFC 5988 outlines these relationships. (see [below for nested schema](#nestedatt--type_awslambda--aws--links))
+
+
+### Nested Schema for `type_awslambda.aws.links`
+
+Read-Only:
+
+- `href` (String) Uniform Resource Locator (URL) that points another API resource to which this response has some relationship. This URL often begins with `https://cloud.mongodb.com/api/atlas`.
+- `rel` (String) Uniform Resource Locator (URL) that defines the semantic relationship between this resource and another API resource. This URL often begins with `https://cloud.mongodb.com/api/atlas`.
+
+
+
+
+
+### Nested Schema for `type_cluster`
+
+Optional:
+
+- `cluster_name` (String) Name of the cluster configured for this connection.
+- `db_role_to_execute` (Attributes) The name of a Built in or Custom DB Role to connect to an Atlas Cluster. (see [below for nested schema](#nestedatt--type_cluster--db_role_to_execute))
+
+
+### Nested Schema for `type_cluster.db_role_to_execute`
+
+Optional:
+
+- `role` (String) The name of the role to use. Can be a built in role or a custom role.
+- `type` (String) Type of the DB role. Can be either BuiltIn or Custom.
+
+Read-Only:
+
+- `links` (Attributes List) List of one or more Uniform Resource Locators (URLs) that point to API sub-resources, related API resources, or both. RFC 5988 outlines these relationships. (see [below for nested schema](#nestedatt--type_cluster--db_role_to_execute--links))
+
+
+### Nested Schema for `type_cluster.db_role_to_execute.links`
+
+Read-Only:
+
+- `href` (String) Uniform Resource Locator (URL) that points another API resource to which this response has some relationship. This URL often begins with `https://cloud.mongodb.com/api/atlas`.
+- `rel` (String) Uniform Resource Locator (URL) that defines the semantic relationship between this resource and another API resource. This URL often begins with `https://cloud.mongodb.com/api/atlas`.
+
+
+
+
+
+### Nested Schema for `type_https`
+
+Optional:
+
+- `headers` (Map of String) A map of key-value pairs that will be passed as headers for the request.
+- `url` (String) The url to be used for the request.
+
+
+
+### Nested Schema for `type_kafka`
+
+Optional:
+
+- `authentication` (Attributes) User credentials required to connect to a Kafka Cluster. Includes the authentication type, as well as the parameters for that authentication mode. (see [below for nested schema](#nestedatt--type_kafka--authentication))
+- `bootstrap_servers` (String) Comma separated list of server addresses.
+- `config` (Map of String) A map of Kafka key-value pairs for optional configuration. This is a flat object, and keys can have '.' characters.
+- `networking` (Attributes) Networking Access Type can either be 'PUBLIC' (default) or VPC. VPC type is in public preview, please file a support ticket to enable VPC Network Access. (see [below for nested schema](#nestedatt--type_kafka--networking))
+- `security` (Attributes) Properties for the secure transport connection to Kafka. For SSL, this can include the trusted certificate to use. (see [below for nested schema](#nestedatt--type_kafka--security))
+
+
+### Nested Schema for `type_kafka.authentication`
+
+Optional:
+
+- `mechanism` (String) Style of authentication. Can be one of PLAIN, SCRAM-256, or SCRAM-512.
+- `password` (String, Sensitive) Password of the account to connect to the Kafka cluster.
+- `ssl_certificate` (String) SSL certificate for client authentication to Kafka.
+- `ssl_key` (String) SSL key for client authentication to Kafka.
+- `ssl_key_password` (String) Password for the SSL key, if it is password protected.
+- `username` (String) Username of the account to connect to the Kafka cluster.
+
+Read-Only:
+
+- `links` (Attributes List) List of one or more Uniform Resource Locators (URLs) that point to API sub-resources, related API resources, or both. RFC 5988 outlines these relationships. (see [below for nested schema](#nestedatt--type_kafka--authentication--links))
+
+
+### Nested Schema for `type_kafka.authentication.links`
+
+Read-Only:
+
+- `href` (String) Uniform Resource Locator (URL) that points another API resource to which this response has some relationship. This URL often begins with `https://cloud.mongodb.com/api/atlas`.
+- `rel` (String) Uniform Resource Locator (URL) that defines the semantic relationship between this resource and another API resource. This URL often begins with `https://cloud.mongodb.com/api/atlas`.
+
+
+
+
+### Nested Schema for `type_kafka.networking`
+
+Optional:
+
+- `access` (Attributes) Information about the networking access. (see [below for nested schema](#nestedatt--type_kafka--networking--access))
+
+Read-Only:
+
+- `links` (Attributes List) List of one or more Uniform Resource Locators (URLs) that point to API sub-resources, related API resources, or both. RFC 5988 outlines these relationships. (see [below for nested schema](#nestedatt--type_kafka--networking--links))
+
+
+### Nested Schema for `type_kafka.networking.access`
+
+Optional:
+
+- `connection_id` (String) Reserved. Will be used by PRIVATE_LINK connection type.
+- `name` (String) Reserved. Will be used by PRIVATE_LINK connection type.
+- `tgw_id` (String) Reserved. Will be used by TRANSIT_GATEWAY connection type.
+- `type` (String) Selected networking type. Either PUBLIC, VPC, PRIVATE_LINK, or TRANSIT_GATEWAY. Defaults to PUBLIC. For VPC, ensure that VPC peering exists and connectivity has been established between Atlas VPC and the VPC where Kafka cluster is hosted for the connection to function properly. TRANSIT_GATEWAY support is coming soon.
+- `vpc_cidr` (String) Reserved. Will be used by TRANSIT_GATEWAY connection type.
+
+Read-Only:
+
+- `links` (Attributes List) List of one or more Uniform Resource Locators (URLs) that point to API sub-resources, related API resources, or both. RFC 5988 outlines these relationships. (see [below for nested schema](#nestedatt--type_kafka--networking--access--links))
+
+
+### Nested Schema for `type_kafka.networking.access.links`
+
+Read-Only:
+
+- `href` (String) Uniform Resource Locator (URL) that points another API resource to which this response has some relationship. This URL often begins with `https://cloud.mongodb.com/api/atlas`.
+- `rel` (String) Uniform Resource Locator (URL) that defines the semantic relationship between this resource and another API resource. This URL often begins with `https://cloud.mongodb.com/api/atlas`.
+
+
+
+
+### Nested Schema for `type_kafka.networking.links`
+
+Read-Only:
+
+- `href` (String) Uniform Resource Locator (URL) that points another API resource to which this response has some relationship. This URL often begins with `https://cloud.mongodb.com/api/atlas`.
+- `rel` (String) Uniform Resource Locator (URL) that defines the semantic relationship between this resource and another API resource. This URL often begins with `https://cloud.mongodb.com/api/atlas`.
+
+
+
+
+### Nested Schema for `type_kafka.security`
+
+Optional:
+
+- `broker_public_certificate` (String) A trusted, public x509 certificate for connecting to Kafka over SSL.
+- `protocol` (String) Describes the transport type. Can be either SASL_PLAINTEXT, SASL_SSL, or SSL.
+
+Read-Only:
+
+- `links` (Attributes List) List of one or more Uniform Resource Locators (URLs) that point to API sub-resources, related API resources, or both. RFC 5988 outlines these relationships. (see [below for nested schema](#nestedatt--type_kafka--security--links))
+
+
+### Nested Schema for `type_kafka.security.links`
+
+Read-Only:
+
+- `href` (String) Uniform Resource Locator (URL) that points another API resource to which this response has some relationship. This URL often begins with `https://cloud.mongodb.com/api/atlas`.
+- `rel` (String) Uniform Resource Locator (URL) that defines the semantic relationship between this resource and another API resource. This URL often begins with `https://cloud.mongodb.com/api/atlas`.
+
+
+
+
+
+### Nested Schema for `type_s3`
+
+Optional:
+
+- `aws` (Attributes) AWS configurations for AWS-based connection types. (see [below for nested schema](#nestedatt--type_s3--aws))
+
+
+### Nested Schema for `type_s3.aws`
+
+Optional:
+
+- `role_arn` (String) Amazon Resource Name (ARN) that identifies the Amazon Web Services (AWS) Identity and Access Management (IAM) role that MongoDB Cloud assumes when it accesses resources in your AWS account.
+- `test_bucket` (String) The name of an S3 bucket used to check authorization of the passed-in IAM role ARN.
+
+Read-Only:
+
+- `links` (Attributes List) List of one or more Uniform Resource Locators (URLs) that point to API sub-resources, related API resources, or both. RFC 5988 outlines these relationships. (see [below for nested schema](#nestedatt--type_s3--aws--links))
+
+
+### Nested Schema for `type_s3.aws.links`
+
+Read-Only:
+
+- `href` (String) Uniform Resource Locator (URL) that points another API resource to which this response has some relationship. This URL often begins with `https://cloud.mongodb.com/api/atlas`.
+- `rel` (String) Uniform Resource Locator (URL) that defines the semantic relationship between this resource and another API resource. This URL often begins with `https://cloud.mongodb.com/api/atlas`.
+
+
+
+
+
+### Nested Schema for `type_sample`
+
+Optional:
+
+- `type` (String) This should always be set to Sample, but can also be omitted
+
+
+
+### Nested Schema for `links`
+
+Read-Only:
+
+- `href` (String) Uniform Resource Locator (URL) that points another API resource to which this response has some relationship. This URL often begins with `https://cloud.mongodb.com/api/atlas`.
+- `rel` (String) Uniform Resource Locator (URL) that defines the semantic relationship between this resource and another API resource. This URL often begins with `https://cloud.mongodb.com/api/atlas`.
diff --git a/internal/common/autogen/marshal.go b/internal/common/autogen/marshal.go
index 9f769cdf9a..1ef7c58169 100644
--- a/internal/common/autogen/marshal.go
+++ b/internal/common/autogen/marshal.go
@@ -3,7 +3,9 @@ package autogen
import (
"encoding/json"
"fmt"
+ "maps"
"reflect"
+ "strings"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -16,6 +18,28 @@ const (
tagValOmitJSONUpdate = "omitjsonupdate"
)
+type DiscriminatorTag struct {
+ DiscriminatorPropName string
+ DiscriminatorPropValue string
+}
+
+// / IsDiscriminatorTag decodes a autogen:"discriminator:type=Cluster" tag to a DiscriminatorTag struct.
+func IsDiscriminatorTag(tag string) *DiscriminatorTag {
+ if tag == "" || !strings.HasPrefix(tag, "discriminator:") {
+ return nil
+ }
+ // decode the tag
+ keyValue := strings.TrimPrefix(tag, "discriminator:")
+ propName, propValue, found := strings.Cut(keyValue, "=")
+ if !found {
+ return nil // not a valid discriminator tag
+ }
+ return &DiscriminatorTag{
+ DiscriminatorPropName: propName,
+ DiscriminatorPropValue: propValue,
+ }
+}
+
// Marshal gets a Terraform model and marshals it into JSON (e.g. for an Atlas request).
// It supports the following Terraform model types: String, Bool, Int64, Float64, Object, Map, List, Set.
// Attributes that are null or unknown are not marshaled.
@@ -53,10 +77,34 @@ func marshalAttrs(valModel reflect.Value, isUpdate bool) (map[string]any, error)
if err := marshalAttr(attrNameModel, attrValModel, objJSON); err != nil {
return nil, err
}
+ if err := handleDiscriminator(tag, attrNameModel, objJSON); err != nil {
+ return nil, err
+ }
}
return objJSON, nil
}
+func handleDiscriminator(tag, attrNameModel string, objJSON map[string]any) error {
+ discriminatorTag := IsDiscriminatorTag(tag)
+ if discriminatorTag == nil {
+ return nil // not a discriminator tag, nothing to do
+ }
+ attrNameJSON := xstrings.ToCamelCase(attrNameModel)
+ attrValJSON, ok := objJSON[attrNameJSON]
+ if !ok {
+ return nil // attribute not found in the JSON, nothing to do (probably Null or Unknown value)
+ }
+ // if the discriminator is set, we remove the attribute from the JSON
+ delete(objJSON, attrNameJSON)
+ objJSON[discriminatorTag.DiscriminatorPropName] = discriminatorTag.DiscriminatorPropValue // set the discriminator property in the JSON
+ attrValJSONObject, ok := attrValJSON.(map[string]any)
+ if !ok {
+ return fmt.Errorf("discriminator attribute %s must be an object", attrNameJSON)
+ }
+ maps.Copy(objJSON, attrValJSONObject) // copy the object attributes to the root JSON
+ return nil
+}
+
func marshalAttr(attrNameModel string, attrValModel reflect.Value, objJSON map[string]any) error {
attrNameJSON := xstrings.ToCamelCase(attrNameModel)
obj, ok := attrValModel.Interface().(attr.Value)
diff --git a/internal/common/autogen/marshal_test.go b/internal/common/autogen/marshal_test.go
index f0268e9d56..76c3d53d27 100644
--- a/internal/common/autogen/marshal_test.go
+++ b/internal/common/autogen/marshal_test.go
@@ -285,3 +285,57 @@ func TestMarshalPanic(t *testing.T) {
})
}
}
+
+func TestIsDiscriminatorTag(t *testing.T) {
+ testCases := map[string]struct {
+ expected *autogen.DiscriminatorTag
+ tagValue string
+ }{
+ "empty tag": {
+ tagValue: "",
+ expected: nil,
+ },
+ "valid tag with name": {
+ tagValue: "discriminator:type=Cluster",
+ expected: &autogen.DiscriminatorTag{
+ DiscriminatorPropName: "type",
+ DiscriminatorPropValue: "Cluster",
+ },
+ },
+ }
+ for name, tc := range testCases {
+ t.Run(name, func(t *testing.T) {
+ tag := autogen.IsDiscriminatorTag(tc.tagValue)
+ if tc.expected == nil {
+ assert.Nil(t, tag)
+ } else {
+ require.NotNil(t, tag)
+ assert.Equal(t, tc.expected.DiscriminatorPropName, tag.DiscriminatorPropName)
+ assert.Equal(t, tc.expected.DiscriminatorPropValue, tag.DiscriminatorPropValue)
+ }
+ })
+ }
+}
+
+func TestMarshalDiscriminator(t *testing.T) {
+ testCases := map[string]struct {
+ model streamConn
+ expectedJSON string
+ }{
+ "cluster model": {
+ model: streamConnModelCluster,
+ expectedJSON: jsonRespCluster,
+ },
+ "https model": {
+ model: streamConnModelHTTPS,
+ expectedJSON: jsonRespHTTPS,
+ },
+ }
+ for name, tc := range testCases {
+ t.Run(name, func(t *testing.T) {
+ raw, err := autogen.Marshal(&tc.model, false)
+ require.NoError(t, err)
+ assert.JSONEq(t, tc.expectedJSON, string(raw))
+ })
+ }
+}
diff --git a/internal/common/autogen/unmarshal.go b/internal/common/autogen/unmarshal.go
index 6ccc50c382..9c84c0cbca 100644
--- a/internal/common/autogen/unmarshal.go
+++ b/internal/common/autogen/unmarshal.go
@@ -12,6 +12,10 @@ import (
"github.com/huandu/xstrings"
)
+type Discriminator interface {
+ DiscriminatorAttr(objJSON map[string]any) string
+}
+
// Unmarshal gets a JSON (e.g. from an Atlas response) and unmarshals it into a Terraform model.
// It supports the following Terraform model types: String, Bool, Int64, Float64, Object, List, Set.
// Map is not supported yet, will be done in CLOUDP-312797.
@@ -38,6 +42,15 @@ func unmarshalAttrs(objJSON map[string]any, model any) error {
return err
}
}
+ discriminator, ok := model.(Discriminator)
+ if !ok {
+ return nil // skip if model does not implement Discriminator interface
+ }
+ if attrNameJSON := discriminator.DiscriminatorAttr(objJSON); attrNameJSON != "" {
+ if err := unmarshalAttr(attrNameJSON, objJSON, valModel); err != nil {
+ return err
+ }
+ }
return nil
}
diff --git a/internal/common/autogen/unmarshal_test.go b/internal/common/autogen/unmarshal_test.go
index 361d893628..c47aacac98 100644
--- a/internal/common/autogen/unmarshal_test.go
+++ b/internal/common/autogen/unmarshal_test.go
@@ -419,6 +419,104 @@ func TestUnmarshalZeroLenCollections(t *testing.T) {
assert.Equal(t, modelExpected, model)
}
+type streamConn struct {
+ Type types.String `tfsdk:"type"`
+ TypeCluster types.Object `tfsdk:"type_cluster" autogen:"discriminator:type=Cluster"`
+ TypeHTTPS types.Object `tfsdk:"type_https" autogen:"discriminator:type=Https"`
+}
+
+func (s *streamConn) DiscriminatorAttr(objJSON map[string]any) string {
+ // Probably can return a single attribute
+ switch objJSON["type"] {
+ case "Cluster":
+ return "TypeCluster"
+ case "Https":
+ return "TypeHTTPS"
+ }
+ return ""
+}
+
+var (
+ dbRoleObjType = types.ObjectType{
+ AttrTypes: map[string]attr.Type{
+ "role_name": types.StringType,
+ "type": types.StringType,
+ },
+ }
+ clusterObjType = types.ObjectType{
+ AttrTypes: map[string]attr.Type{
+ "cluster_name": types.StringType,
+ "db_role_to_execute": dbRoleObjType,
+ },
+ }
+ httpsObjType = types.ObjectType{
+ AttrTypes: map[string]attr.Type{
+ "url": types.StringType,
+ },
+ }
+ streamConnModelCluster = streamConn{
+ Type: types.StringValue("Cluster"),
+ TypeCluster: types.ObjectValueMust(clusterObjType.AttrTypes, map[string]attr.Value{
+ "cluster_name": types.StringValue("myCluster"),
+ "db_role_to_execute": types.ObjectValueMust(dbRoleObjType.AttrTypes, map[string]attr.Value{
+ "role_name": types.StringValue("myRole"),
+ "type": types.StringValue("myType"),
+ }),
+ }),
+ TypeHTTPS: types.ObjectNull(httpsObjType.AttrTypes),
+ }
+ streamConnModelHTTPS = streamConn{
+ Type: types.StringValue("Https"),
+ TypeCluster: types.ObjectNull(clusterObjType.AttrTypes),
+ TypeHTTPS: types.ObjectValueMust(httpsObjType.AttrTypes, map[string]attr.Value{
+ "url": types.StringValue("https://example.com"),
+ }),
+ }
+)
+
+const (
+ jsonRespCluster = `
+ {
+ "type": "Cluster",
+ "clusterName": "myCluster",
+ "dbRoleToExecute": {
+ "roleName": "myRole",
+ "type": "myType"
+ }
+ }`
+ jsonRespHTTPS = `{
+ "type": "Https",
+ "url": "https://example.com"
+ }`
+)
+
+func TestUnmarshalModelWithDiscriminator(t *testing.T) {
+ testCases := map[string]struct {
+ modelExpected streamConn
+ jsonResp string
+ }{
+ "cluster": {
+ modelExpected: streamConnModelCluster,
+ jsonResp: jsonRespCluster,
+ },
+ "https": {
+ modelExpected: streamConnModelHTTPS,
+ jsonResp: jsonRespHTTPS,
+ },
+ }
+ for name, tc := range testCases {
+ t.Run(name, func(t *testing.T) {
+ model := streamConn{
+ Type: types.StringUnknown(),
+ TypeCluster: types.ObjectNull(clusterObjType.AttrTypes),
+ TypeHTTPS: types.ObjectNull(httpsObjType.AttrTypes),
+ }
+ require.NoError(t, autogen.Unmarshal([]byte(tc.jsonResp), &model))
+ assert.Equal(t, tc.modelExpected, model)
+ })
+ }
+}
+
func TestUnmarshalErrors(t *testing.T) {
testCases := map[string]struct {
model any
diff --git a/internal/serviceapi/clusterapi/resource_schema.go b/internal/serviceapi/clusterapi/resource_schema.go
index 254ad4131a..e0a2abc551 100755
--- a/internal/serviceapi/clusterapi/resource_schema.go
+++ b/internal/serviceapi/clusterapi/resource_schema.go
@@ -446,48 +446,48 @@ func ResourceSchema(ctx context.Context) schema.Schema {
}
type TFModel struct {
- AcceptDataRisksAndForceReplicaSetReconfig types.String `tfsdk:"accept_data_risks_and_force_replica_set_reconfig"`
- AdvancedConfiguration types.Object `tfsdk:"advanced_configuration"`
- AutoScaling types.Object `tfsdk:"auto_scaling"`
- BackupEnabled types.Bool `tfsdk:"backup_enabled"`
- BiConnector types.Object `tfsdk:"bi_connector"`
- ClusterType types.String `tfsdk:"cluster_type"`
- ConfigServerManagementMode types.String `tfsdk:"config_server_management_mode"`
- ConfigServerType types.String `tfsdk:"config_server_type" autogen:"omitjson"`
+ DiskSizeGb types.Float64 `tfsdk:"disk_size_gb"`
+ Tags types.List `tfsdk:"tags"`
+ ReplicationSpecs types.List `tfsdk:"replication_specs"`
+ Links types.List `tfsdk:"links" autogen:"omitjson"`
+ Labels types.List `tfsdk:"labels"`
+ ReplicationSpec types.Map `tfsdk:"replication_spec"`
+ MongoDbemployeeAccessGrant types.Object `tfsdk:"mongo_dbemployee_access_grant"`
+ ProviderSettings types.Object `tfsdk:"provider_settings"`
ConnectionStrings types.Object `tfsdk:"connection_strings" autogen:"omitjson"`
CreateDate types.String `tfsdk:"create_date" autogen:"omitjson"`
- DiskSizeGb types.Float64 `tfsdk:"disk_size_gb"`
+ ConfigServerManagementMode types.String `tfsdk:"config_server_management_mode"`
DiskWarmingMode types.String `tfsdk:"disk_warming_mode"`
EncryptionAtRestProvider types.String `tfsdk:"encryption_at_rest_provider"`
FeatureCompatibilityVersion types.String `tfsdk:"feature_compatibility_version" autogen:"omitjson"`
FeatureCompatibilityVersionExpirationDate types.String `tfsdk:"feature_compatibility_version_expiration_date" autogen:"omitjson"`
- GlobalClusterSelfManagedSharding types.Bool `tfsdk:"global_cluster_self_managed_sharding"`
+ VersionReleaseSystem types.String `tfsdk:"version_release_system"`
GroupId types.String `tfsdk:"group_id" autogen:"omitjson"`
Id types.String `tfsdk:"id" autogen:"omitjson"`
- Labels types.List `tfsdk:"labels"`
- Links types.List `tfsdk:"links" autogen:"omitjson"`
- MongoDbemployeeAccessGrant types.Object `tfsdk:"mongo_dbemployee_access_grant"`
+ ClusterType types.String `tfsdk:"cluster_type"`
+ BiConnector types.Object `tfsdk:"bi_connector"`
+ AcceptDataRisksAndForceReplicaSetReconfig types.String `tfsdk:"accept_data_risks_and_force_replica_set_reconfig"`
MongoDbmajorVersion types.String `tfsdk:"mongo_dbmajor_version"`
MongoDbversion types.String `tfsdk:"mongo_dbversion"`
MongoUri types.String `tfsdk:"mongo_uri" autogen:"omitjson"`
MongoUriupdated types.String `tfsdk:"mongo_uriupdated" autogen:"omitjson"`
MongoUriwithOptions types.String `tfsdk:"mongo_uriwith_options" autogen:"omitjson"`
Name types.String `tfsdk:"name"`
- NumShards types.Int64 `tfsdk:"num_shards"`
- Paused types.Bool `tfsdk:"paused"`
- PitEnabled types.Bool `tfsdk:"pit_enabled"`
- ProviderBackupEnabled types.Bool `tfsdk:"provider_backup_enabled"`
- ProviderSettings types.Object `tfsdk:"provider_settings"`
+ AdvancedConfiguration types.Object `tfsdk:"advanced_configuration"`
+ StateName types.String `tfsdk:"state_name" autogen:"omitjson"`
+ SrvAddress types.String `tfsdk:"srv_address" autogen:"omitjson"`
+ RootCertType types.String `tfsdk:"root_cert_type"`
+ ConfigServerType types.String `tfsdk:"config_server_type" autogen:"omitjson"`
ReplicaSetScalingStrategy types.String `tfsdk:"replica_set_scaling_strategy"`
+ AutoScaling types.Object `tfsdk:"auto_scaling"`
ReplicationFactor types.Int64 `tfsdk:"replication_factor"`
- ReplicationSpec types.Map `tfsdk:"replication_spec"`
- ReplicationSpecs types.List `tfsdk:"replication_specs"`
- RootCertType types.String `tfsdk:"root_cert_type"`
- SrvAddress types.String `tfsdk:"srv_address" autogen:"omitjson"`
- StateName types.String `tfsdk:"state_name" autogen:"omitjson"`
- Tags types.List `tfsdk:"tags"`
+ NumShards types.Int64 `tfsdk:"num_shards"`
+ BackupEnabled types.Bool `tfsdk:"backup_enabled"`
+ ProviderBackupEnabled types.Bool `tfsdk:"provider_backup_enabled"`
+ PitEnabled types.Bool `tfsdk:"pit_enabled"`
+ Paused types.Bool `tfsdk:"paused"`
TerminationProtectionEnabled types.Bool `tfsdk:"termination_protection_enabled"`
- VersionReleaseSystem types.String `tfsdk:"version_release_system"`
+ GlobalClusterSelfManagedSharding types.Bool `tfsdk:"global_cluster_self_managed_sharding"`
}
type TFAdvancedConfigurationModel struct {
CustomOpensslCipherConfigTls12 types.List `tfsdk:"custom_openssl_cipher_config_tls12"`
@@ -504,8 +504,8 @@ type TFAutoScalingComputeModel struct {
ScaleDownEnabled types.Bool `tfsdk:"scale_down_enabled"`
}
type TFBiConnectorModel struct {
- Enabled types.Bool `tfsdk:"enabled"`
ReadPreference types.String `tfsdk:"read_preference"`
+ Enabled types.Bool `tfsdk:"enabled"`
}
type TFConnectionStringsModel struct {
AwsPrivateLink types.Map `tfsdk:"aws_private_link" autogen:"omitjson"`
@@ -555,10 +555,10 @@ type TFReplicationSpecModel struct {
ReadOnlyNodes types.Int64 `tfsdk:"read_only_nodes"`
}
type TFReplicationSpecsModel struct {
- Id types.String `tfsdk:"id"`
- NumShards types.Int64 `tfsdk:"num_shards"`
RegionsConfig types.Map `tfsdk:"regions_config"`
+ Id types.String `tfsdk:"id"`
ZoneName types.String `tfsdk:"zone_name"`
+ NumShards types.Int64 `tfsdk:"num_shards"`
}
type TFReplicationSpecsRegionsConfigModel struct {
AnalyticsNodes types.Int64 `tfsdk:"analytics_nodes"`
diff --git a/internal/serviceapi/customdbroleapi/resource_schema.go b/internal/serviceapi/customdbroleapi/resource_schema.go
index 975996f399..1e879b3ec4 100755
--- a/internal/serviceapi/customdbroleapi/resource_schema.go
+++ b/internal/serviceapi/customdbroleapi/resource_schema.go
@@ -83,9 +83,9 @@ type TFActionsModel struct {
Resources types.List `tfsdk:"resources"`
}
type TFActionsResourcesModel struct {
- Cluster types.Bool `tfsdk:"cluster"`
Collection types.String `tfsdk:"collection"`
Db types.String `tfsdk:"db"`
+ Cluster types.Bool `tfsdk:"cluster"`
}
type TFInheritedRolesModel struct {
Db types.String `tfsdk:"db"`
diff --git a/internal/serviceapi/projectapi/resource_schema.go b/internal/serviceapi/projectapi/resource_schema.go
index 18aa398efd..c358a0aa96 100755
--- a/internal/serviceapi/projectapi/resource_schema.go
+++ b/internal/serviceapi/projectapi/resource_schema.go
@@ -79,14 +79,14 @@ func ResourceSchema(ctx context.Context) schema.Schema {
}
type TFModel struct {
- ClusterCount types.Int64 `tfsdk:"cluster_count" autogen:"omitjson"`
+ Links types.List `tfsdk:"links" autogen:"omitjson"`
+ Tags types.List `tfsdk:"tags"`
Created types.String `tfsdk:"created" autogen:"omitjson"`
Id types.String `tfsdk:"id" autogen:"omitjson"`
- Links types.List `tfsdk:"links" autogen:"omitjson"`
Name types.String `tfsdk:"name"`
OrgId types.String `tfsdk:"org_id" autogen:"omitjsonupdate"`
RegionUsageRestrictions types.String `tfsdk:"region_usage_restrictions" autogen:"omitjsonupdate"`
- Tags types.List `tfsdk:"tags"`
+ ClusterCount types.Int64 `tfsdk:"cluster_count" autogen:"omitjson"`
WithDefaultAlertsSettings types.Bool `tfsdk:"with_default_alerts_settings" autogen:"omitjsonupdate"`
}
type TFLinksModel struct {
diff --git a/internal/serviceapi/streamconnectionapi/resource.go b/internal/serviceapi/streamconnectionapi/resource.go
new file mode 100755
index 0000000000..9ebfaecc3d
--- /dev/null
+++ b/internal/serviceapi/streamconnectionapi/resource.go
@@ -0,0 +1,148 @@
+// Code generated by terraform-provider-mongodbatlas using `make generate-resource`. DO NOT EDIT.
+
+package streamconnectionapi
+
+import (
+ "context"
+
+ "github.com/hashicorp/terraform-plugin-framework/resource"
+ "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/autogen"
+ "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
+ "github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
+)
+
+var _ resource.ResourceWithConfigure = &rs{}
+var _ resource.ResourceWithImportState = &rs{}
+
+const apiVersionHeader = "application/vnd.atlas.2023-02-01+json"
+
+func Resource() resource.Resource {
+ return &rs{
+ RSCommon: config.RSCommon{
+ ResourceName: "stream_connection_api",
+ },
+ }
+}
+
+type rs struct {
+ config.RSCommon
+}
+
+func (r *rs) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
+ resp.Schema = ResourceSchema(ctx)
+ conversion.UpdateSchemaDescription(&resp.Schema)
+}
+
+func (r *rs) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
+ var plan TFModel
+ resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
+ if resp.Diagnostics.HasError() {
+ return
+ }
+ pathParams := map[string]string{
+ "groupId": plan.GroupId.ValueString(),
+ "tenantName": plan.TenantName.ValueString(),
+ }
+ callParams := config.APICallParams{
+ VersionHeader: apiVersionHeader,
+ RelativePath: "/api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections",
+ PathParams: pathParams,
+ Method: "POST",
+ }
+ reqHandle := autogen.HandleCreateReq{
+ Resp: resp,
+ Client: r.Client,
+ Plan: &plan,
+ CallParams: &callParams,
+ }
+ autogen.HandleCreate(ctx, reqHandle)
+}
+
+func (r *rs) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
+ var state TFModel
+ resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
+ if resp.Diagnostics.HasError() {
+ return
+ }
+ reqHandle := autogen.HandleReadReq{
+ Resp: resp,
+ Client: r.Client,
+ State: &state,
+ CallParams: readAPICallParams(&state),
+ }
+ autogen.HandleRead(ctx, reqHandle)
+}
+
+func (r *rs) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
+ var plan TFModel
+ var state TFModel
+ resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
+ resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
+ if resp.Diagnostics.HasError() {
+ return
+ }
+ // Path params are grabbed from state as they may be computed-only and not present in the plan
+ pathParams := map[string]string{
+ "groupId": state.GroupId.ValueString(),
+ "tenantName": state.TenantName.ValueString(),
+ "name": state.Name.ValueString(),
+ }
+ callParams := config.APICallParams{
+ VersionHeader: apiVersionHeader,
+ RelativePath: "/api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections/{name}",
+ PathParams: pathParams,
+ Method: "PATCH",
+ }
+ reqHandle := autogen.HandleUpdateReq{
+ Resp: resp,
+ Client: r.Client,
+ Plan: &plan,
+ CallParams: &callParams,
+ }
+ autogen.HandleUpdate(ctx, reqHandle)
+}
+
+func (r *rs) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
+ var state TFModel
+ resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
+ if resp.Diagnostics.HasError() {
+ return
+ }
+ pathParams := map[string]string{
+ "groupId": state.GroupId.ValueString(),
+ "tenantName": state.TenantName.ValueString(),
+ "name": state.Name.ValueString(),
+ }
+ callParams := config.APICallParams{
+ VersionHeader: apiVersionHeader,
+ RelativePath: "/api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections/{name}",
+ PathParams: pathParams,
+ Method: "DELETE",
+ }
+ reqHandle := autogen.HandleDeleteReq{
+ Resp: resp,
+ Client: r.Client,
+ State: &state,
+ CallParams: &callParams,
+ }
+ autogen.HandleDelete(ctx, reqHandle)
+}
+
+func (r *rs) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
+ idAttributes := []string{"group_id", "tenant_name", "name"}
+ autogen.HandleImport(ctx, idAttributes, req, resp)
+}
+
+func readAPICallParams(state *TFModel) *config.APICallParams {
+ pathParams := map[string]string{
+ "groupId": state.GroupId.ValueString(),
+ "tenantName": state.TenantName.ValueString(),
+ "name": state.Name.ValueString(),
+ }
+ return &config.APICallParams{
+ VersionHeader: apiVersionHeader,
+ RelativePath: "/api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections/{name}",
+ PathParams: pathParams,
+ Method: "GET",
+ }
+}
diff --git a/internal/serviceapi/streamconnectionapi/resource_schema.go b/internal/serviceapi/streamconnectionapi/resource_schema.go
new file mode 100755
index 0000000000..86ff214f1d
--- /dev/null
+++ b/internal/serviceapi/streamconnectionapi/resource_schema.go
@@ -0,0 +1,466 @@
+// Code generated by terraform-provider-mongodbatlas using `make generate-resource`. DO NOT EDIT.
+
+package streamconnectionapi
+
+import (
+ "context"
+
+ "github.com/hashicorp/terraform-plugin-framework/resource/schema"
+ "github.com/hashicorp/terraform-plugin-framework/types"
+)
+
+func ResourceSchema(ctx context.Context) schema.Schema {
+ return schema.Schema{
+ Attributes: map[string]schema.Attribute{
+ "group_id": schema.StringAttribute{
+ Required: true,
+ MarkdownDescription: "Unique 24-hexadecimal digit string that identifies your project. Use the [/groups](#tag/Projects/operation/listProjects) endpoint to retrieve all projects to which the authenticated user has access.\n\n**NOTE**: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.",
+ },
+ "links": schema.ListNestedAttribute{
+ Computed: true,
+ MarkdownDescription: "List of one or more Uniform Resource Locators (URLs) that point to API sub-resources, related API resources, or both. RFC 5988 outlines these relationships.",
+ NestedObject: schema.NestedAttributeObject{
+ Attributes: map[string]schema.Attribute{
+ "href": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Uniform Resource Locator (URL) that points another API resource to which this response has some relationship. This URL often begins with `https://cloud.mongodb.com/api/atlas`.",
+ },
+ "rel": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Uniform Resource Locator (URL) that defines the semantic relationship between this resource and another API resource. This URL often begins with `https://cloud.mongodb.com/api/atlas`.",
+ },
+ },
+ },
+ },
+ "name": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "Human-readable label that identifies the stream connection. In the case of the Sample type, this is the name of the sample source.",
+ },
+ "tenant_name": schema.StringAttribute{
+ Required: true,
+ MarkdownDescription: "Human-readable label that identifies the stream instance.",
+ },
+ "type": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Type of the connection.",
+ },
+ "type_awslambda": schema.SingleNestedAttribute{
+ Optional: true,
+ Attributes: map[string]schema.Attribute{
+ "aws": schema.SingleNestedAttribute{
+ Optional: true,
+ MarkdownDescription: "AWS configurations for AWS-based connection types.",
+ Attributes: map[string]schema.Attribute{
+ "links": schema.ListNestedAttribute{
+ Computed: true,
+ MarkdownDescription: "List of one or more Uniform Resource Locators (URLs) that point to API sub-resources, related API resources, or both. RFC 5988 outlines these relationships.",
+ NestedObject: schema.NestedAttributeObject{
+ Attributes: map[string]schema.Attribute{
+ "href": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Uniform Resource Locator (URL) that points another API resource to which this response has some relationship. This URL often begins with `https://cloud.mongodb.com/api/atlas`.",
+ },
+ "rel": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Uniform Resource Locator (URL) that defines the semantic relationship between this resource and another API resource. This URL often begins with `https://cloud.mongodb.com/api/atlas`.",
+ },
+ },
+ },
+ },
+ "role_arn": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "Amazon Resource Name (ARN) that identifies the Amazon Web Services (AWS) Identity and Access Management (IAM) role that MongoDB Cloud assumes when it accesses resources in your AWS account.",
+ },
+ "test_bucket": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "The name of an S3 bucket used to check authorization of the passed-in IAM role ARN.",
+ },
+ },
+ },
+ },
+ },
+ "type_cluster": schema.SingleNestedAttribute{
+ Optional: true,
+ Attributes: map[string]schema.Attribute{
+ "cluster_name": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "Name of the cluster configured for this connection.",
+ },
+ "db_role_to_execute": schema.SingleNestedAttribute{
+ Optional: true,
+ MarkdownDescription: "The name of a Built in or Custom DB Role to connect to an Atlas Cluster.",
+ Attributes: map[string]schema.Attribute{
+ "links": schema.ListNestedAttribute{
+ Computed: true,
+ MarkdownDescription: "List of one or more Uniform Resource Locators (URLs) that point to API sub-resources, related API resources, or both. RFC 5988 outlines these relationships.",
+ NestedObject: schema.NestedAttributeObject{
+ Attributes: map[string]schema.Attribute{
+ "href": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Uniform Resource Locator (URL) that points another API resource to which this response has some relationship. This URL often begins with `https://cloud.mongodb.com/api/atlas`.",
+ },
+ "rel": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Uniform Resource Locator (URL) that defines the semantic relationship between this resource and another API resource. This URL often begins with `https://cloud.mongodb.com/api/atlas`.",
+ },
+ },
+ },
+ },
+ "role": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "The name of the role to use. Can be a built in role or a custom role.",
+ },
+ "type": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "Type of the DB role. Can be either BuiltIn or Custom.",
+ },
+ },
+ },
+ },
+ },
+ "type_https": schema.SingleNestedAttribute{
+ Optional: true,
+ Attributes: map[string]schema.Attribute{
+ "headers": schema.MapAttribute{
+ Optional: true,
+ MarkdownDescription: "A map of key-value pairs that will be passed as headers for the request.",
+ ElementType: types.StringType,
+ },
+ "url": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "The url to be used for the request.",
+ },
+ },
+ },
+ "type_kafka": schema.SingleNestedAttribute{
+ Optional: true,
+ Attributes: map[string]schema.Attribute{
+ "authentication": schema.SingleNestedAttribute{
+ Optional: true,
+ MarkdownDescription: "User credentials required to connect to a Kafka Cluster. Includes the authentication type, as well as the parameters for that authentication mode.",
+ Attributes: map[string]schema.Attribute{
+ "links": schema.ListNestedAttribute{
+ Computed: true,
+ MarkdownDescription: "List of one or more Uniform Resource Locators (URLs) that point to API sub-resources, related API resources, or both. RFC 5988 outlines these relationships.",
+ NestedObject: schema.NestedAttributeObject{
+ Attributes: map[string]schema.Attribute{
+ "href": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Uniform Resource Locator (URL) that points another API resource to which this response has some relationship. This URL often begins with `https://cloud.mongodb.com/api/atlas`.",
+ },
+ "rel": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Uniform Resource Locator (URL) that defines the semantic relationship between this resource and another API resource. This URL often begins with `https://cloud.mongodb.com/api/atlas`.",
+ },
+ },
+ },
+ },
+ "mechanism": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "Style of authentication. Can be one of PLAIN, SCRAM-256, or SCRAM-512.",
+ },
+ "password": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "Password of the account to connect to the Kafka cluster.",
+ Sensitive: true,
+ },
+ "ssl_certificate": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "SSL certificate for client authentication to Kafka.",
+ },
+ "ssl_key": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "SSL key for client authentication to Kafka.",
+ },
+ "ssl_key_password": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "Password for the SSL key, if it is password protected.",
+ },
+ "username": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "Username of the account to connect to the Kafka cluster.",
+ },
+ },
+ },
+ "bootstrap_servers": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "Comma separated list of server addresses.",
+ },
+ "config": schema.MapAttribute{
+ Optional: true,
+ MarkdownDescription: "A map of Kafka key-value pairs for optional configuration. This is a flat object, and keys can have '.' characters.",
+ ElementType: types.StringType,
+ },
+ "networking": schema.SingleNestedAttribute{
+ Optional: true,
+ MarkdownDescription: "Networking Access Type can either be 'PUBLIC' (default) or VPC. VPC type is in public preview, please file a support ticket to enable VPC Network Access.",
+ Attributes: map[string]schema.Attribute{
+ "access": schema.SingleNestedAttribute{
+ Optional: true,
+ MarkdownDescription: "Information about the networking access.",
+ Attributes: map[string]schema.Attribute{
+ "connection_id": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "Reserved. Will be used by PRIVATE_LINK connection type.",
+ },
+ "links": schema.ListNestedAttribute{
+ Computed: true,
+ MarkdownDescription: "List of one or more Uniform Resource Locators (URLs) that point to API sub-resources, related API resources, or both. RFC 5988 outlines these relationships.",
+ NestedObject: schema.NestedAttributeObject{
+ Attributes: map[string]schema.Attribute{
+ "href": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Uniform Resource Locator (URL) that points another API resource to which this response has some relationship. This URL often begins with `https://cloud.mongodb.com/api/atlas`.",
+ },
+ "rel": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Uniform Resource Locator (URL) that defines the semantic relationship between this resource and another API resource. This URL often begins with `https://cloud.mongodb.com/api/atlas`.",
+ },
+ },
+ },
+ },
+ "name": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "Reserved. Will be used by PRIVATE_LINK connection type.",
+ },
+ "tgw_id": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "Reserved. Will be used by TRANSIT_GATEWAY connection type.",
+ },
+ "type": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "Selected networking type. Either PUBLIC, VPC, PRIVATE_LINK, or TRANSIT_GATEWAY. Defaults to PUBLIC. For VPC, ensure that VPC peering exists and connectivity has been established between Atlas VPC and the VPC where Kafka cluster is hosted for the connection to function properly. TRANSIT_GATEWAY support is coming soon.",
+ },
+ "vpc_cidr": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "Reserved. Will be used by TRANSIT_GATEWAY connection type.",
+ },
+ },
+ },
+ "links": schema.ListNestedAttribute{
+ Computed: true,
+ MarkdownDescription: "List of one or more Uniform Resource Locators (URLs) that point to API sub-resources, related API resources, or both. RFC 5988 outlines these relationships.",
+ NestedObject: schema.NestedAttributeObject{
+ Attributes: map[string]schema.Attribute{
+ "href": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Uniform Resource Locator (URL) that points another API resource to which this response has some relationship. This URL often begins with `https://cloud.mongodb.com/api/atlas`.",
+ },
+ "rel": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Uniform Resource Locator (URL) that defines the semantic relationship between this resource and another API resource. This URL often begins with `https://cloud.mongodb.com/api/atlas`.",
+ },
+ },
+ },
+ },
+ },
+ },
+ "security": schema.SingleNestedAttribute{
+ Optional: true,
+ MarkdownDescription: "Properties for the secure transport connection to Kafka. For SSL, this can include the trusted certificate to use.",
+ Attributes: map[string]schema.Attribute{
+ "broker_public_certificate": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "A trusted, public x509 certificate for connecting to Kafka over SSL.",
+ },
+ "links": schema.ListNestedAttribute{
+ Computed: true,
+ MarkdownDescription: "List of one or more Uniform Resource Locators (URLs) that point to API sub-resources, related API resources, or both. RFC 5988 outlines these relationships.",
+ NestedObject: schema.NestedAttributeObject{
+ Attributes: map[string]schema.Attribute{
+ "href": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Uniform Resource Locator (URL) that points another API resource to which this response has some relationship. This URL often begins with `https://cloud.mongodb.com/api/atlas`.",
+ },
+ "rel": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Uniform Resource Locator (URL) that defines the semantic relationship between this resource and another API resource. This URL often begins with `https://cloud.mongodb.com/api/atlas`.",
+ },
+ },
+ },
+ },
+ "protocol": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "Describes the transport type. Can be either SASL_PLAINTEXT, SASL_SSL, or SSL.",
+ },
+ },
+ },
+ },
+ },
+ "type_s3": schema.SingleNestedAttribute{
+ Optional: true,
+ Attributes: map[string]schema.Attribute{
+ "aws": schema.SingleNestedAttribute{
+ Optional: true,
+ MarkdownDescription: "AWS configurations for AWS-based connection types.",
+ Attributes: map[string]schema.Attribute{
+ "links": schema.ListNestedAttribute{
+ Computed: true,
+ MarkdownDescription: "List of one or more Uniform Resource Locators (URLs) that point to API sub-resources, related API resources, or both. RFC 5988 outlines these relationships.",
+ NestedObject: schema.NestedAttributeObject{
+ Attributes: map[string]schema.Attribute{
+ "href": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Uniform Resource Locator (URL) that points another API resource to which this response has some relationship. This URL often begins with `https://cloud.mongodb.com/api/atlas`.",
+ },
+ "rel": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Uniform Resource Locator (URL) that defines the semantic relationship between this resource and another API resource. This URL often begins with `https://cloud.mongodb.com/api/atlas`.",
+ },
+ },
+ },
+ },
+ "role_arn": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "Amazon Resource Name (ARN) that identifies the Amazon Web Services (AWS) Identity and Access Management (IAM) role that MongoDB Cloud assumes when it accesses resources in your AWS account.",
+ },
+ "test_bucket": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "The name of an S3 bucket used to check authorization of the passed-in IAM role ARN.",
+ },
+ },
+ },
+ },
+ },
+ "type_sample": schema.SingleNestedAttribute{
+ Optional: true,
+ Attributes: map[string]schema.Attribute{
+ "type": schema.StringAttribute{
+ Optional: true,
+ MarkdownDescription: "This should always be set to Sample, but can also be omitted",
+ },
+ },
+ },
+ },
+ }
+}
+
+type TFModel struct {
+ GroupId types.String `tfsdk:"group_id" autogen:"omitjson"`
+ Links types.List `tfsdk:"links" autogen:"omitjson"`
+ Name types.String `tfsdk:"name"`
+ TenantName types.String `tfsdk:"tenant_name" autogen:"omitjson"`
+ Type types.String `tfsdk:"type"`
+ TypeAwslambda types.Object `tfsdk:"type_awslambda" autogen:"discriminator:type=AWSLambda"`
+ TypeCluster types.Object `tfsdk:"type_cluster" autogen:"discriminator:type=Cluster"`
+ TypeHttps types.Object `tfsdk:"type_https" autogen:"discriminator:type=Https"`
+ TypeKafka types.Object `tfsdk:"type_kafka" autogen:"discriminator:type=Kafka"`
+ TypeS3 types.Object `tfsdk:"type_s3" autogen:"discriminator:type=S3"`
+ TypeSample types.Object `tfsdk:"type_sample" autogen:"discriminator:type=Sample"`
+}
+
+func (t *TFModel) DiscriminatorAttr(objJSON map[string]any) string {
+ switch objJSON["type"] {
+ case "AWSLambda":
+ return "TypeAWSLambda"
+ case "Cluster":
+ return "TypeCluster"
+ case "Https":
+ return "TypeHttps"
+ case "Kafka":
+ return "TypeKafka"
+ case "S3":
+ return "TypeS3"
+ case "Sample":
+ return "TypeSample"
+ }
+ return ""
+}
+
+type TFLinksModel struct {
+ Href types.String `tfsdk:"href" autogen:"omitjson"`
+ Rel types.String `tfsdk:"rel" autogen:"omitjson"`
+}
+type TFTypeAwslambdaModel struct {
+ Aws types.Object `tfsdk:"aws"`
+}
+type TFTypeAwslambdaAwsModel struct {
+ Links types.List `tfsdk:"links" autogen:"omitjson"`
+ RoleArn types.String `tfsdk:"role_arn"`
+ TestBucket types.String `tfsdk:"test_bucket"`
+}
+type TFTypeAwslambdaAwsLinksModel struct {
+ Href types.String `tfsdk:"href" autogen:"omitjson"`
+ Rel types.String `tfsdk:"rel" autogen:"omitjson"`
+}
+type TFTypeClusterModel struct {
+ ClusterName types.String `tfsdk:"cluster_name"`
+ DbRoleToExecute types.Object `tfsdk:"db_role_to_execute"`
+}
+type TFTypeClusterDbRoleToExecuteModel struct {
+ Links types.List `tfsdk:"links" autogen:"omitjson"`
+ Role types.String `tfsdk:"role"`
+ Type types.String `tfsdk:"type"`
+}
+type TFTypeClusterDbRoleToExecuteLinksModel struct {
+ Href types.String `tfsdk:"href" autogen:"omitjson"`
+ Rel types.String `tfsdk:"rel" autogen:"omitjson"`
+}
+type TFTypeHttpsModel struct {
+ Headers types.Map `tfsdk:"headers"`
+ Url types.String `tfsdk:"url"`
+}
+type TFTypeKafkaModel struct {
+ Authentication types.Object `tfsdk:"authentication"`
+ BootstrapServers types.String `tfsdk:"bootstrap_servers"`
+ Config types.Map `tfsdk:"config"`
+ Networking types.Object `tfsdk:"networking"`
+ Security types.Object `tfsdk:"security"`
+}
+type TFTypeKafkaAuthenticationModel struct {
+ Links types.List `tfsdk:"links" autogen:"omitjson"`
+ Mechanism types.String `tfsdk:"mechanism"`
+ Password types.String `tfsdk:"password"`
+ SslCertificate types.String `tfsdk:"ssl_certificate"`
+ SslKey types.String `tfsdk:"ssl_key"`
+ SslKeyPassword types.String `tfsdk:"ssl_key_password"`
+ Username types.String `tfsdk:"username"`
+}
+type TFTypeKafkaAuthenticationLinksModel struct {
+ Href types.String `tfsdk:"href" autogen:"omitjson"`
+ Rel types.String `tfsdk:"rel" autogen:"omitjson"`
+}
+type TFTypeKafkaNetworkingModel struct {
+ Access types.Object `tfsdk:"access"`
+ Links types.List `tfsdk:"links" autogen:"omitjson"`
+}
+type TFTypeKafkaNetworkingAccessModel struct {
+ ConnectionId types.String `tfsdk:"connection_id"`
+ Links types.List `tfsdk:"links" autogen:"omitjson"`
+ Name types.String `tfsdk:"name"`
+ TgwId types.String `tfsdk:"tgw_id"`
+ Type types.String `tfsdk:"type"`
+ VpcCidr types.String `tfsdk:"vpc_cidr"`
+}
+type TFTypeKafkaNetworkingAccessLinksModel struct {
+ Href types.String `tfsdk:"href" autogen:"omitjson"`
+ Rel types.String `tfsdk:"rel" autogen:"omitjson"`
+}
+type TFTypeKafkaNetworkingLinksModel struct {
+ Href types.String `tfsdk:"href" autogen:"omitjson"`
+ Rel types.String `tfsdk:"rel" autogen:"omitjson"`
+}
+type TFTypeKafkaSecurityModel struct {
+ BrokerPublicCertificate types.String `tfsdk:"broker_public_certificate"`
+ Links types.List `tfsdk:"links" autogen:"omitjson"`
+ Protocol types.String `tfsdk:"protocol"`
+}
+type TFTypeKafkaSecurityLinksModel struct {
+ Href types.String `tfsdk:"href" autogen:"omitjson"`
+ Rel types.String `tfsdk:"rel" autogen:"omitjson"`
+}
+type TFTypeS3Model struct {
+ Aws types.Object `tfsdk:"aws"`
+}
+type TFTypeS3AwsModel struct {
+ Links types.List `tfsdk:"links" autogen:"omitjson"`
+ RoleArn types.String `tfsdk:"role_arn"`
+ TestBucket types.String `tfsdk:"test_bucket"`
+}
+type TFTypeS3AwsLinksModel struct {
+ Href types.String `tfsdk:"href" autogen:"omitjson"`
+ Rel types.String `tfsdk:"rel" autogen:"omitjson"`
+}
+type TFTypeSampleModel struct {
+ Type types.String `tfsdk:"type"`
+}
diff --git a/tools/codegen/codespec/api_to_provider_spec_mapper_test.go b/tools/codegen/codespec/api_to_provider_spec_mapper_test.go
index 915f4ca4e5..61942058e9 100644
--- a/tools/codegen/codespec/api_to_provider_spec_mapper_test.go
+++ b/tools/codegen/codespec/api_to_provider_spec_mapper_test.go
@@ -505,6 +505,121 @@ func TestConvertToProviderSpec_pathParamPresentInPostRequest(t *testing.T) {
runTestCase(t, tc)
}
+var streamConnectionExpectedSchema = codespec.Schema{
+ Description: conversion.StringPtr("create sc"),
+ Attributes: []codespec.Attribute{
+ {
+ Name: "group_id",
+ ComputedOptionalRequired: codespec.Required,
+ String: &codespec.StringAttribute{},
+ Description: conversion.StringPtr("Unique 24-hexadecimal digit"),
+ ReqBodyUsage: codespec.OmitAlways,
+ },
+ {
+ Name: "name",
+ ComputedOptionalRequired: codespec.Optional, // inferred wrongly
+ String: &codespec.StringAttribute{},
+ Description: conversion.StringPtr("Human-readable label that identifies the stream connection. In the case of the Sample type, this is the name of the sample source."),
+ },
+ {
+ Name: "tenant_name",
+ ComputedOptionalRequired: codespec.Required,
+ String: &codespec.StringAttribute{},
+ Description: conversion.StringPtr("Human-readable label that identifies the stream instance."),
+ ReqBodyUsage: codespec.OmitAlways,
+ },
+ {
+ Name: "type",
+ String: &codespec.StringAttribute{},
+ ComputedOptionalRequired: codespec.Computed,
+ Description: conversion.Pointer("Type of the connection."),
+ },
+ {
+ Name: "type_cluster",
+ ComputedOptionalRequired: codespec.Optional,
+ SingleNested: &codespec.SingleNestedAttribute{
+ NestedObject: codespec.NestedAttributeObject{
+ Attributes: []codespec.Attribute{
+ {
+ Name: "cluster_name",
+ String: &codespec.StringAttribute{},
+ ComputedOptionalRequired: codespec.Optional, // this is inferred as optional, but it should be required
+ Description: conversion.Pointer("Name of the cluster configured for this connection."),
+ },
+ },
+ },
+ },
+ Discriminator: &codespec.DiscriminatorMapping{
+ DiscriminatorProperty: "type",
+ DiscriminatorValue: "Cluster",
+ },
+ },
+ {
+ Name: "type_https",
+ ComputedOptionalRequired: codespec.Optional,
+ SingleNested: &codespec.SingleNestedAttribute{
+ NestedObject: codespec.NestedAttributeObject{
+ Attributes: []codespec.Attribute{
+ {
+ Name: "headers",
+ Map: &codespec.MapAttribute{
+ ElementType: codespec.String,
+ },
+ Description: conversion.StringPtr("A map of key-value pairs that will be passed as headers for the request."),
+ ComputedOptionalRequired: codespec.Optional,
+ },
+ {
+ Name: "url",
+ String: &codespec.StringAttribute{},
+ ComputedOptionalRequired: codespec.Optional, // this is inferred as optional, but it should be required
+ Description: conversion.Pointer("The url to be used for the request."),
+ },
+ },
+ },
+ },
+ Discriminator: &codespec.DiscriminatorMapping{
+ DiscriminatorProperty: "type",
+ DiscriminatorValue: "Https",
+ },
+ },
+ },
+}
+
+func TestConvertToProviderSpec_discriminatorStreamConnection(t *testing.T) {
+ tc := convertToSpecTestCase{
+ inputOpenAPISpecPath: "testdata/api-spec-stream_connection.yaml",
+ inputConfigPath: "testdata/config-stream_connection.yml",
+ inputResourceName: "stream_connection",
+ expectedResult: &codespec.Model{
+ Resources: []codespec.Resource{{
+ Schema: &streamConnectionExpectedSchema,
+ Name: "stream_connection",
+ Operations: codespec.APIOperations{
+ Create: codespec.APIOperation{
+ Path: "/api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections",
+ HTTPMethod: "POST",
+ },
+ Read: codespec.APIOperation{
+ Path: "/api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections/{connectionName}",
+ HTTPMethod: "GET",
+ },
+ Update: codespec.APIOperation{
+ Path: "/api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections/{connectionName}",
+ HTTPMethod: "PATCH",
+ },
+ Delete: codespec.APIOperation{
+ Path: "/api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections/{connectionName}",
+ HTTPMethod: "DELETE",
+ },
+ VersionHeader: "application/vnd.atlas.2023-02-01+json",
+ },
+ },
+ },
+ },
+ }
+ runTestCase(t, tc)
+}
+
func runTestCase(t *testing.T, tc convertToSpecTestCase) {
t.Helper()
result, err := codespec.ToCodeSpecModel(tc.inputOpenAPISpecPath, tc.inputConfigPath, &tc.inputResourceName)
diff --git a/tools/codegen/codespec/attribute.go b/tools/codegen/codespec/attribute.go
index 8633cb0625..72f3013075 100644
--- a/tools/codegen/codespec/attribute.go
+++ b/tools/codegen/codespec/attribute.go
@@ -3,8 +3,11 @@ package codespec
import (
"context"
"fmt"
+ "strings"
+ "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
"github.com/mongodb/terraform-provider-mongodbatlas/tools/codegen/stringcase"
+ "github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/pb33f/libopenapi/orderedmap"
)
@@ -35,10 +38,93 @@ func buildResourceAttrs(s *APISpecSchema, isFromRequest bool) (Attributes, error
objectAttributes = append(objectAttributes, *attribute)
}
}
+ oneOfRefsMap := map[string]*base.SchemaProxy{}
+ for i := range s.Schema.OneOf {
+ ref := s.Schema.OneOf[i]
+ if ref != nil {
+ refName := ref.GetReference()
+ oneOfRefsMap[refName] = ref
+ }
+ }
+ if discriminator := s.Schema.Discriminator; discriminator != nil && orderedmap.Len(discriminator.Mapping) == len(oneOfRefsMap) {
+ discriminatorProperty := discriminator.PropertyName
+ ensureComputed(objectAttributes, discriminatorProperty) // the discriminator property should always be computed
+ counter := -1
+ for pair := range orderedmap.Iterate(context.Background(), discriminator.Mapping) {
+ counter++
+ name := pair.Key()
+ refValue := pair.Value()
+ ref := oneOfRefsMap[refValue]
+ if ref == nil {
+ return nil, fmt.Errorf("discriminator mapping '%s' has no reference", name)
+ }
+ discriminatorAttribute, err := createDiscriminatorAttribute(ref, discriminatorProperty, name, isFromRequest)
+ if err != nil {
+ return nil, err
+ }
+ // the first schema in allOf is the discriminator schema, the second is the actual schema
+ objectAttributes = append(objectAttributes, *discriminatorAttribute)
+ }
+ }
return objectAttributes, nil
}
+func createDiscriminatorAttribute(ref *base.SchemaProxy, discriminatorProperty, discriminatorValue string, isFromRequest bool) (*Attribute, error) {
+ oneOfSchema, err := BuildSchema(ref)
+ if err != nil {
+ return nil, err
+ }
+ allOfRefs := oneOfSchema.Schema.AllOf
+ attrName := stringcase.SnakeCaseString(discriminatorProperty + "_" + strings.ToLower(discriminatorValue))
+ discriminatorMapping := DiscriminatorMapping{
+ DiscriminatorProperty: discriminatorProperty,
+ DiscriminatorValue: discriminatorValue,
+ }
+ if len(allOfRefs) == 0 || len(allOfRefs) > 2 {
+ return nil, fmt.Errorf("discriminator mapping '%s' has invalid schema, expected 1 or 2 schemas in allOf, got %d", discriminatorValue, len(allOfRefs))
+ }
+ if len(allOfRefs) == 1 { // if the specific oneOf has no special attributes, we can just use the discriminator property
+ return &Attribute{
+ Name: attrName,
+ ComputedOptionalRequired: Optional,
+ SingleNested: &SingleNestedAttribute{
+ NestedObject: NestedAttributeObject{
+ Attributes: []Attribute{
+ {
+ Name: stringcase.SnakeCaseString(discriminatorProperty),
+ ComputedOptionalRequired: Optional,
+ String: &StringAttribute{},
+ Description: conversion.Pointer(fmt.Sprintf("This should always be set to %s, but can also be omitted", discriminatorValue)),
+ },
+ },
+ },
+ },
+ Discriminator: &discriminatorMapping,
+ }, nil
+ }
+ // two allOfRefs
+ schema, err := BuildSchema(allOfRefs[1])
+ if err != nil {
+ return nil, err
+ }
+ attribute, err := schema.buildResourceAttr(attrName.SnakeCase(), Optional, isFromRequest)
+ if err != nil {
+ return nil, err
+ }
+ attribute.Discriminator = &discriminatorMapping
+ return attribute, nil
+}
+
+func ensureComputed(objectAttributes Attributes, discriminatorProperty string) {
+ for i := range objectAttributes {
+ attr := &objectAttributes[i]
+ if attr.Name == stringcase.SnakeCaseString(discriminatorProperty) {
+ attr.ComputedOptionalRequired = Computed
+ }
+ }
+}
+
func (s *APISpecSchema) buildResourceAttr(name string, computability ComputedOptionalRequired, isFromRequest bool) (*Attribute, error) {
switch s.Type {
case OASTypeString:
diff --git a/tools/codegen/codespec/model.go b/tools/codegen/codespec/model.go
index ff9c41de46..c3df9a9ba4 100644
--- a/tools/codegen/codespec/model.go
+++ b/tools/codegen/codespec/model.go
@@ -1,6 +1,8 @@
package codespec
-import "github.com/mongodb/terraform-provider-mongodbatlas/tools/codegen/stringcase"
+import (
+ "github.com/mongodb/terraform-provider-mongodbatlas/tools/codegen/stringcase"
+)
type ElemType int
@@ -55,10 +57,19 @@ type Schema struct {
type Attributes []Attribute
+type DiscriminatorMapping struct {
+ DiscriminatorProperty string
+ DiscriminatorValue string
+}
+
+func (d DiscriminatorMapping) AttributeName() string {
+ return stringcase.SnakeCaseString(d.DiscriminatorProperty + d.DiscriminatorValue).PascalCase()
+}
+
// Add this field to the Attribute struct
// Usage AttributeUsage
type Attribute struct {
- SetNested *SetNestedAttribute
+ Set *SetAttribute
String *StringAttribute
Float64 *Float64Attribute
List *ListAttribute
@@ -66,15 +77,16 @@ type Attribute struct {
ListNested *ListNestedAttribute
Map *MapAttribute
MapNested *MapNestedAttribute
- Int64 *Int64Attribute
Number *NumberAttribute
- Set *SetAttribute
- SingleNested *SingleNestedAttribute
+ Int64 *Int64Attribute
Timeouts *TimeoutsAttribute
+ SingleNested *SingleNestedAttribute
+ SetNested *SetNestedAttribute
Description *string
DeprecationMessage *string
- Name stringcase.SnakeCaseString
+ Discriminator *DiscriminatorMapping
ComputedOptionalRequired ComputedOptionalRequired
+ Name stringcase.SnakeCaseString
ReqBodyUsage AttributeReqBodyUsage
Sensitive bool
}
diff --git a/tools/codegen/codespec/testdata/api-spec-stream_connection.yaml b/tools/codegen/codespec/testdata/api-spec-stream_connection.yaml
new file mode 100644
index 0000000000..171021f502
--- /dev/null
+++ b/tools/codegen/codespec/testdata/api-spec-stream_connection.yaml
@@ -0,0 +1,283 @@
+openapi: 3.0.1
+info:
+ description: minimal spec
+ version: '2.0'
+ title: MongoDB Atlas Administration API
+paths:
+ /api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections/{connectionName}:
+ delete:
+ description: Delete one connection of the specified stream instance. To use this resource, the requesting Service Account or API Key must have the Project Owner role or Project Stream Processing Owner role.
+ operationId: deleteStreamConnection
+ parameters:
+ - $ref: '#/components/parameters/groupId'
+ - description: Human-readable label that identifies the stream instance.
+ in: path
+ name: tenantName
+ required: true
+ schema:
+ type: string
+ - description: Human-readable label that identifies the stream connection.
+ in: path
+ name: connectionName
+ required: true
+ schema:
+ type: string
+ responses:
+ '202':
+ content:
+ application/vnd.atlas.2023-02-01+json:
+ x-xgen-version: '2023-02-01'
+ description: Accepted
+ summary: Delete One Stream Connection
+ tags:
+ - Streams
+ x-codeSamples:
+ - label: curl
+ lang: cURL
+ source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2025-03-12+json\" \\\n -X DELETE \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections/{connectionName}\""
+ - label: Atlas CLI
+ lang: cURL
+ source: atlas api deleteStreamConnection --help
+ x-xgen-changelog:
+ '2023-09-11': The MongoDB Atlas Streams Processing API is now exposed as part of private preview, but is subject to change until GA.
+ x-xgen-docs-url: https://mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Streams/operation/deleteStreamConnection
+ get:
+ description: Returns the details of one stream connection within the specified stream instance. To use this resource, the requesting Service Account or API Key must have the Project Read Only role.
+ operationId: getStreamConnection
+ parameters:
+ - $ref: '#/components/parameters/groupId'
+ - description: Human-readable label that identifies the stream instance to return.
+ in: path
+ name: tenantName
+ required: true
+ schema:
+ type: string
+ - description: Human-readable label that identifies the stream connection to return.
+ in: path
+ name: connectionName
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ content:
+ application/vnd.atlas.2023-02-01+json:
+ schema:
+ $ref: '#/components/schemas/StreamsConnection'
+ x-xgen-IPA-exception:
+ xgen-IPA-104-get-method-returns-response-suffixed-object: API predates IPA validation
+ x-xgen-version: '2023-02-01'
+ description: OK
+ summary: Return One Stream Connection
+ tags:
+ - Streams
+ x-codeSamples:
+ - label: curl
+ lang: cURL
+ source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2025-03-12+json\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections/{connectionName}?pretty=true\""
+ - label: Atlas CLI
+ lang: cURL
+ source: atlas api getStreamConnection --help
+ x-xgen-changelog:
+ '2023-09-11': The MongoDB Atlas Streams Processing API is now exposed as part of private preview, but is subject to change until GA.
+ x-xgen-docs-url: https://mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Streams/operation/getStreamConnection
+ patch:
+ description: Update one connection for the specified stream instance in the specified project. To use this resource, the requesting Service Account or API Key must have the Project Owner role or Project Stream Processing Owner role.
+ operationId: updateStreamConnection
+ parameters:
+ - $ref: '#/components/parameters/groupId'
+ - description: Human-readable label that identifies the stream instance.
+ in: path
+ name: tenantName
+ required: true
+ schema:
+ type: string
+ - description: Human-readable label that identifies the stream connection.
+ in: path
+ name: connectionName
+ required: true
+ schema:
+ type: string
+ requestBody:
+ content:
+ application/vnd.atlas.2023-02-01+json:
+ schema:
+ $ref: '#/components/schemas/StreamsConnection'
+ description: Details to update one connection for a streams instance in the specified project.
+ required: true
+ responses:
+ '200':
+ content:
+ application/vnd.atlas.2023-02-01+json:
+ schema:
+ $ref: '#/components/schemas/StreamsConnection'
+ x-xgen-version: '2023-02-01'
+ description: OK
+ summary: Update One Stream Connection
+ tags:
+ - Streams
+ x-codeSamples:
+ - label: curl
+ lang: cURL
+ source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2025-03-12+json\" \\\n --header \"Content-Type: application/vnd.atlas.2025-03-12+json\" \\\n -X PATCH \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections/{connectionName}\"\n -d { }"
+ - label: Atlas CLI
+ lang: cURL
+ source: atlas api updateStreamConnection --help
+ x-xgen-changelog:
+ '2023-09-11': The MongoDB Atlas Streams Processing API is now exposed as part of private preview, but is subject to change until GA.
+ x-xgen-docs-url: https://mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Streams/operation/updateStreamConnection
+ /api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections:
+ get:
+ description: Returns all connections of the stream instance for the specified project.To use this resource, the requesting Service Account or API Key must have the Project Data Access roles, Project Owner role or Project Stream Processing Owner role.
+ operationId: listStreamConnections
+ parameters:
+ - $ref: '#/components/parameters/groupId'
+ - $ref: '#/components/parameters/itemsPerPage'
+ - $ref: '#/components/parameters/pageNum'
+ - description: Human-readable label that identifies the stream instance.
+ in: path
+ name: tenantName
+ required: true
+ schema:
+ type: string
+ responses:
+ '200':
+ content:
+ application/vnd.atlas.2023-02-01+json:
+ schema:
+ $ref: '#/components/schemas/PaginatedApiStreamsConnectionView'
+ x-xgen-version: '2023-02-01'
+ description: OK
+ summary: Return All Connections Of The Stream Instances
+ tags:
+ - Streams
+ x-codeSamples:
+ - label: curl
+ lang: cURL
+ source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2025-03-12+json\" \\\n -X GET \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections?pretty=true\""
+ - label: Atlas CLI
+ lang: cURL
+ source: atlas api listStreamConnections --help
+ x-xgen-changelog:
+ '2023-09-11': The MongoDB Atlas Streams Processing API is now exposed as part of private preview, but is subject to change until GA.
+ x-xgen-docs-url: https://mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Streams/operation/listStreamConnections
+ post:
+ description: "create sc"
+ operationId: createStreamConnection
+ parameters:
+ - $ref: '#/components/parameters/groupId'
+ - description: Human-readable label that identifies the stream instance.
+ in: path
+ name: tenantName
+ required: true
+ schema:
+ type: string
+ requestBody:
+ content:
+ application/vnd.atlas.2023-02-01+json:
+ schema:
+ $ref: '#/components/schemas/StreamsConnection'
+ description: Details to create one connection for a streams instance in the specified project.
+ required: true
+ responses:
+ '200':
+ content:
+ application/vnd.atlas.2023-02-01+json:
+ schema:
+ $ref: '#/components/schemas/StreamsConnection'
+ x-xgen-version: '2023-02-01'
+ description: OK
+ summary: Create One Connection
+ tags:
+ - Streams
+ x-codeSamples:
+ - label: curl
+ lang: cURL
+ source: "curl --user \"{PUBLIC-KEY}:{PRIVATE-KEY}\" \\\n --digest \\\n --header \"Accept: application/vnd.atlas.2025-03-12+json\" \\\n --header \"Content-Type: application/vnd.atlas.2025-03-12+json\" \\\n -X POST \"https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections\"\n -d { }"
+ - label: Atlas CLI
+ lang: cURL
+ source: atlas api createStreamConnection --help
+ x-xgen-changelog:
+ '2023-09-11': The MongoDB Atlas Streams Processing API is now exposed as part of private preview, but is subject to change until GA.
+ x-xgen-docs-url: https://mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Streams/operation/createStreamConnection
+components:
+ schemas:
+ PaginatedApiStreamsConnectionView:
+ properties: {}
+ type: object
+ StreamsClusterConnection:
+ allOf:
+ - $ref: '#/components/schemas/StreamsConnection'
+ - properties:
+ clusterName:
+ description: Name of the cluster configured for this connection.
+ type: string
+ type: object
+ type: object
+ StreamsConnection:
+ description: Settings that define a connection to an external data store.
+ discriminator:
+ mapping:
+ Cluster: '#/components/schemas/StreamsClusterConnection'
+ Https: '#/components/schemas/StreamsHttpsConnection'
+ propertyName: type
+ oneOf:
+ - $ref: '#/components/schemas/StreamsClusterConnection'
+ - $ref: '#/components/schemas/StreamsHttpsConnection'
+ properties:
+ name:
+ description: Human-readable label that identifies the stream connection. In the case of the Sample type, this is the name of the sample source.
+ type: string
+ type:
+ description: Type of the connection.
+ enum:
+ - Cluster
+ - Https
+ type: string
+ readOnly: true
+ type: object
+ StreamsHttpsConnection:
+ allOf:
+ - $ref: '#/components/schemas/StreamsConnection'
+ - properties:
+ headers:
+ additionalProperties:
+ description: A map of key-value pairs that will be passed as headers for the request.
+ type: string
+ description: A map of key-value pairs that will be passed as headers for the request.
+ type: object
+ url:
+ description: The url to be used for the request.
+ type: string
+ type: object
+ type: object
+ parameters:
+ groupId:
+ description: 'Unique 24-hexadecimal digit'
+ in: path
+ name: groupId
+ required: true
+ schema:
+ example: 32b6e34b3d91647abb20e7b8
+ pattern: ^([a-f0-9]{24})$
+ type: string
+ x-xgen-IPA-exception:
+ xgen-IPA-117-description-should-not-use-inline-links: Parameters don't support externalDocs
+ itemsPerPage:
+ description: Number of items that the response returns per page.
+ in: query
+ name: itemsPerPage
+ schema:
+ default: 100
+ maximum: 500
+ minimum: 1
+ type: integer
+ pageNum:
+ description: Number of the page that displays the current set of the total objects that the response returns.
+ in: query
+ name: pageNum
+ schema:
+ default: 1
+ minimum: 1
+ type: integer
+tags: []
diff --git a/tools/codegen/codespec/testdata/config-stream_connection.yml b/tools/codegen/codespec/testdata/config-stream_connection.yml
new file mode 100644
index 0000000000..3e5752e8a8
--- /dev/null
+++ b/tools/codegen/codespec/testdata/config-stream_connection.yml
@@ -0,0 +1,14 @@
+resources:
+ stream_connection:
+ create:
+ path: /api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections
+ method: POST
+ read:
+ path: /api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections/{connectionName}
+ method: GET
+ update:
+ path: /api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections/{connectionName}
+ method: PATCH
+ delete:
+ path: /api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections/{connectionName}
+ method: DELETE
\ No newline at end of file
diff --git a/tools/codegen/config.yml b/tools/codegen/config.yml
index d17a07f6aa..befd5d0bf6 100644
--- a/tools/codegen/config.yml
+++ b/tools/codegen/config.yml
@@ -145,6 +145,23 @@ resources:
schema:
aliases:
tenant_name: name # path param name does not match the API request property
+ stream_connection_api:
+ create:
+ path: /api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections
+ method: POST
+ read:
+ path: /api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections/{connectionName}
+ method: GET
+ update:
+ path: /api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections/{connectionName}
+ method: PATCH
+ delete:
+ path: /api/atlas/v2/groups/{groupId}/streams/{tenantName}/connections/{connectionName}
+ method: DELETE
+ schema:
+ aliases:
+ connection_name: name # path param name does not match the API request property
+
# No fully functional yet so it doesn't have acceptance tests yet.
cluster_api:
diff --git a/tools/codegen/gofilegen/schema/schema_attribute.go b/tools/codegen/gofilegen/schema/schema_attribute.go
index 05f06a9984..8290266622 100644
--- a/tools/codegen/gofilegen/schema/schema_attribute.go
+++ b/tools/codegen/gofilegen/schema/schema_attribute.go
@@ -16,7 +16,7 @@ func GenerateSchemaAttributes(attrs codespec.Attributes) CodeStatement {
imports = append(imports, result.Imports...)
}
finalAttrs := strings.Join(attrsCode, ",\n")
- if len(finalAttrs) > 0 {
+ if finalAttrs != "" {
finalAttrs += ","
}
return CodeStatement{
diff --git a/tools/codegen/gofilegen/schema/schema_file_test.go b/tools/codegen/gofilegen/schema/schema_file_test.go
index 579bf3a9db..c3d748d75a 100644
--- a/tools/codegen/gofilegen/schema/schema_file_test.go
+++ b/tools/codegen/gofilegen/schema/schema_file_test.go
@@ -259,6 +259,65 @@ func TestSchemaGenerationFromCodeSpec(t *testing.T) {
withObjType: true,
goldenFileName: "multiple-nested-models-same-parent-attr-name",
},
+ "Discriminator mapping": {
+ inputModel: codespec.Resource{
+ Name: "test_name",
+ Schema: &codespec.Schema{
+ Attributes: []codespec.Attribute{
+ {
+ Name: "type",
+ String: &codespec.StringAttribute{},
+ ComputedOptionalRequired: codespec.Computed,
+ Description: admin.PtrString("Type of the stream connection"),
+ },
+ {
+ Name: "type_cluster",
+ ComputedOptionalRequired: codespec.Optional,
+ Description: admin.PtrString("Use this when you want a cluster stream connection"),
+ SingleNested: &codespec.SingleNestedAttribute{
+ NestedObject: codespec.NestedAttributeObject{
+ Attributes: []codespec.Attribute{
+ {
+ Name: "cluster_name",
+ String: &codespec.StringAttribute{},
+ ComputedOptionalRequired: codespec.Required,
+ Description: admin.PtrString("Name of the cluster to connect to"),
+ },
+ },
+ },
+ },
+ Discriminator: &codespec.DiscriminatorMapping{
+ DiscriminatorProperty: "type",
+ DiscriminatorValue: "Cluster",
+ },
+ },
+ {
+ Name: "type_https",
+ ComputedOptionalRequired: codespec.Optional,
+ Description: admin.PtrString("Use this when you want a https stream connection"),
+ SingleNested: &codespec.SingleNestedAttribute{
+ NestedObject: codespec.NestedAttributeObject{
+ Attributes: []codespec.Attribute{
+ {
+ Name: "url",
+ String: &codespec.StringAttribute{},
+ ComputedOptionalRequired: codespec.Required,
+ Description: admin.PtrString("Url of the https stream connection"),
+ },
+ },
+ },
+ },
+ Discriminator: &codespec.DiscriminatorMapping{
+ DiscriminatorProperty: "type",
+ DiscriminatorValue: "Https",
+ },
+ },
+ },
+ },
+ },
+ withObjType: false,
+ goldenFileName: "discriminator-mapping-stream-connection",
+ },
}
for testName, tc := range testCases {
diff --git a/tools/codegen/gofilegen/schema/testdata/discriminator-mapping-stream-connection.golden.go b/tools/codegen/gofilegen/schema/testdata/discriminator-mapping-stream-connection.golden.go
new file mode 100644
index 0000000000..928884e678
--- /dev/null
+++ b/tools/codegen/gofilegen/schema/testdata/discriminator-mapping-stream-connection.golden.go
@@ -0,0 +1,64 @@
+// Code generated by terraform-provider-mongodbatlas using `make generate-resource`. DO NOT EDIT.
+
+package testname
+
+import (
+ "context"
+
+ "github.com/hashicorp/terraform-plugin-framework/resource/schema"
+ "github.com/hashicorp/terraform-plugin-framework/types"
+)
+
+func ResourceSchema(ctx context.Context) schema.Schema {
+ return schema.Schema{
+ Attributes: map[string]schema.Attribute{
+ "type": schema.StringAttribute{
+ Computed: true,
+ MarkdownDescription: "Type of the stream connection",
+ },
+ "type_cluster": schema.SingleNestedAttribute{
+ Optional: true,
+ MarkdownDescription: "Use this when you want a cluster stream connection",
+ Attributes: map[string]schema.Attribute{
+ "cluster_name": schema.StringAttribute{
+ Required: true,
+ MarkdownDescription: "Name of the cluster to connect to",
+ },
+ },
+ },
+ "type_https": schema.SingleNestedAttribute{
+ Optional: true,
+ MarkdownDescription: "Use this when you want a https stream connection",
+ Attributes: map[string]schema.Attribute{
+ "url": schema.StringAttribute{
+ Required: true,
+ MarkdownDescription: "Url of the https stream connection",
+ },
+ },
+ },
+ },
+ }
+}
+
+type TFModel struct {
+ Type types.String `tfsdk:"type"`
+ TypeCluster types.Object `tfsdk:"type_cluster" autogen:"discriminator:type=Cluster"`
+ TypeHttps types.Object `tfsdk:"type_https" autogen:"discriminator:type=Https"`
+}
+
+func (t *TFModel) DiscriminatorAttr(objJSON map[string]any) string {
+ switch objJSON["type"] {
+ case "Cluster":
+ return "TypeCluster"
+ case "Https":
+ return "TypeHttps"
+ }
+ return ""
+}
+
+type TFTypeClusterModel struct {
+ ClusterName types.String `tfsdk:"cluster_name"`
+}
+type TFTypeHttpsModel struct {
+ Url types.String `tfsdk:"url"`
+}
diff --git a/tools/codegen/gofilegen/schema/typed_model.go b/tools/codegen/gofilegen/schema/typed_model.go
index d7dda4f829..c6b38336b9 100644
--- a/tools/codegen/gofilegen/schema/typed_model.go
+++ b/tools/codegen/gofilegen/schema/typed_model.go
@@ -72,14 +72,60 @@ func generateStructOfTypedModel(attributes codespec.Attributes, name string) Cod
structProperties = append(structProperties, typedModelProperty(&attributes[i]))
}
structPropsCode := strings.Join(structProperties, "\n")
+ tfModelName := "TF" + name + "Model"
+ discriminatorAttrFunc := generateDiscriminatorAttrFunc(tfModelName, attributes)
return CodeStatement{
- Code: fmt.Sprintf(`type TF%sModel struct {
+ Code: fmt.Sprintf(`type %s struct {
%s
- }`, name, structPropsCode),
+ }`, tfModelName, structPropsCode) + discriminatorAttrFunc,
Imports: []string{"github.com/hashicorp/terraform-plugin-framework/types"},
}
}
+func generateDiscriminatorAttrFunc(tfModelName string, attributes codespec.Attributes) string {
+ /*
+ Example of stream_connection:
+ func (s *streamConn) DiscriminatorAttr(objJSON map[string]any) string {
+ // Probably can return a single attribute
+ switch objJSON["type"] {
+ case "Cluster":
+ return "TypeCluster"
+ case "Https":
+ return "TypeHttps"
+ }
+ return ""
+ }
+ */
+ discriminators := []codespec.DiscriminatorMapping{}
+ for i := range attributes {
+ attr := &attributes[i]
+ if attr.Discriminator != nil {
+ discriminators = append(discriminators, *attr.Discriminator)
+ }
+ }
+ if len(discriminators) == 0 {
+ return ""
+ }
+ discriminatorCases := []string{}
+ discriminatorPropName := ""
+ for _, disc := range discriminators {
+ discriminatorCases = append(discriminatorCases, fmt.Sprintf(`case %q: return %q`, disc.DiscriminatorValue, disc.AttributeName()))
+ if discriminatorPropName == "" {
+ discriminatorPropName = disc.DiscriminatorProperty
+ }
+ if discriminatorPropName != disc.DiscriminatorProperty {
+ panic(fmt.Sprintf("Discriminator mappings must have the same DiscriminatorProperty, found %s and %s for model %s", discriminatorPropName, disc.DiscriminatorProperty, tfModelName))
+ }
+ }
+ return fmt.Sprintf(`
+func (t *%s) DiscriminatorAttr(objJSON map[string]any) string {
+ switch objJSON["%s"] {
+ %s
+ }
+ return ""
+}`, tfModelName, discriminatorPropName, strings.Join(discriminatorCases, "\n\t"))
+}
+
func typedModelProperty(attr *codespec.Attribute) string {
var (
namePascalCase = attr.Name.PascalCase()
@@ -92,6 +138,9 @@ func typedModelProperty(attr *codespec.Attribute) string {
case codespec.OmitInUpdateBody:
autogenTag = ` autogen:"omitjsonupdate"`
}
+ if discriminator := attr.Discriminator; discriminator != nil {
+ autogenTag = fmt.Sprintf(` autogen:"discriminator:%s=%s"`, discriminator.DiscriminatorProperty, discriminator.DiscriminatorValue)
+ }
return fmt.Sprintf("%s %s", namePascalCase, propType) + " `" + fmt.Sprintf("tfsdk:%q", attr.Name.SnakeCase()) + autogenTag + "`"
}