Skip to content

Commit 029a209

Browse files
feat: Adds new mongodbatlas_control_plane_ip_addresses data source (#2331)
* initial scaffolding * adds unit testing * add changelog entry * adding acceptance test * add docs * include acceptance test in CI * add function to test cidr block * refactor conversion function into common package * include mention of new data source in migration guide * adjust const to private * fix links * fix link * change structure of test fixture to use a map
1 parent 2c59e08 commit 029a209

File tree

26 files changed

+508
-43
lines changed

26 files changed

+508
-43
lines changed

.changelog/2331.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_control_plane_ip_addresses
3+
```

.github/workflows/acceptance-tests-runner.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ jobs:
187187
search_index: ${{ steps.filter.outputs.search_index == 'true' || env.mustTrigger == 'true' }}
188188
serverless: ${{ steps.filter.outputs.serverless == 'true' || env.mustTrigger == 'true' }}
189189
stream: ${{ steps.filter.outputs.stream == 'true' || env.mustTrigger == 'true' }}
190+
control_plane_ip_addresses: ${{ steps.filter.outputs.control_plane_ip_addresses == 'true' || env.mustTrigger == 'true' }}
190191
steps:
191192
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
192193
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36
@@ -269,6 +270,8 @@ jobs:
269270
stream:
270271
- 'internal/service/streamconnection/*.go'
271272
- 'internal/service/streaminstance/*.go'
273+
control_plane_ip_addresses:
274+
- 'internal/service/controlplaneipaddresses/*.go'
272275
273276
advanced_cluster:
274277
needs: [ change-detection, get-provider-version ]
@@ -815,3 +818,26 @@ jobs:
815818
./internal/service/streamconnection
816819
./internal/service/streaminstance
817820
run: make testacc
821+
822+
control_plane_ip_addresses:
823+
needs: [ change-detection, get-provider-version ]
824+
if: ${{ needs.change-detection.outputs.control_plane_ip_addresses == 'true' || inputs.test_group == 'control_plane_ip_addresses' }}
825+
runs-on: ubuntu-latest
826+
permissions: {}
827+
steps:
828+
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
829+
with:
830+
ref: ${{ inputs.ref || github.ref }}
831+
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7
832+
with:
833+
go-version-file: 'go.mod'
834+
- uses: hashicorp/setup-terraform@651471c36a6092792c552e8b1bef71e592b462d8
835+
with:
836+
terraform_version: ${{ inputs.terraform_version }}
837+
terraform_wrapper: false
838+
- name: Acceptance Tests
839+
env:
840+
MONGODB_ATLAS_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }}
841+
ACCTEST_PACKAGES: |
842+
./internal/service/controlplaneipaddresses
843+
run: make testacc

contributing/documentation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ We autogenerate the documentation of our provider resources and data sources via
99
### How to generate the documentation for a resource
1010
- Make sure that the resource and data source schemas have defined the fields `MarkdownDescription` and `Description`.
1111
- We recommend to use [Scaffolding Schema and Model Definitions](#scaffolding-schema-and-model-definitions) to autogenerate the schema via the Open API specification.
12-
- Add the resource/data source templates to the [templates](templates) folder. See [README.md](templates/README.md) for more info.
12+
- Add the resource/data source templates to the [templates](https://github.com/mongodb/terraform-provider-mongodbatlas/blob/master/templates) folder. See [README.md](https://github.com/mongodb/terraform-provider-mongodbatlas/blob/master/templates/README.md) for more info.
1313
- Run the Makefile command `generate-doc`
1414
```bash
1515
export resource_name=search_deployment && make generate-doc
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
data "mongodbatlas_control_plane_ip_addresses" "test" {
2+
}
3+
4+
output "outbound-aws-ip-addresses" {
5+
value = data.mongodbatlas_control_plane_ip_addresses.test.outbound.aws
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
provider "mongodbatlas" {
2+
public_key = var.public_key
3+
private_key = var.private_key
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
variable "public_key" {
2+
description = "Public API key to authenticate to Atlas"
3+
type = string
4+
}
5+
variable "private_key" {
6+
description = "Private API key to authenticate to Atlas"
7+
type = string
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
required_providers {
3+
mongodbatlas = {
4+
source = "mongodb/mongodbatlas"
5+
version = "~> 1.17"
6+
}
7+
}
8+
required_version = ">= 1.0"
9+
}

internal/common/conversion/string_framework.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package conversion
33
import (
44
"context"
55

6+
"github.com/hashicorp/terraform-plugin-framework/diag"
67
"github.com/hashicorp/terraform-plugin-framework/types"
8+
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
79
)
810

911
func TypesSetToString(ctx context.Context, set types.Set) []string {
@@ -18,6 +20,10 @@ func TypesListToString(ctx context.Context, list types.List) []string {
1820
return results
1921
}
2022

23+
func ToTFMapOfSlices(ctx context.Context, values map[string][]string) (basetypes.MapValue, diag.Diagnostics) {
24+
return types.MapValueFrom(ctx, types.ListType{ElemType: types.StringType}, values)
25+
}
26+
2127
// StringNullIfEmpty converts a string value to a Framework String value.
2228
// An empty string is converted to a null String. Useful for optional attributes.
2329
func StringNullIfEmpty(v string) types.String {

internal/provider/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
2929
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/alertconfiguration"
3030
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/atlasuser"
31+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/controlplaneipaddresses"
3132
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/databaseuser"
3233
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/encryptionatrest"
3334
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/project"
@@ -431,6 +432,7 @@ func (p *MongodbtlasProvider) DataSources(context.Context) []func() datasource.D
431432
streaminstance.PluralDataSource,
432433
streamconnection.DataSource,
433434
streamconnection.PluralDataSource,
435+
controlplaneipaddresses.DataSource,
434436
}
435437
previewDataSources := []func() datasource.DataSource{} // Data sources not yet in GA
436438
if providerEnablePreview {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package controlplaneipaddresses
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-framework/datasource"
7+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
8+
)
9+
10+
const controlPlaneIPAddressesName = "control_plane_ip_addresses"
11+
12+
var _ datasource.DataSource = &controlPlaneIPAddressesDS{}
13+
var _ datasource.DataSourceWithConfigure = &controlPlaneIPAddressesDS{}
14+
15+
func DataSource() datasource.DataSource {
16+
return &controlPlaneIPAddressesDS{
17+
DSCommon: config.DSCommon{
18+
DataSourceName: controlPlaneIPAddressesName,
19+
},
20+
}
21+
}
22+
23+
type controlPlaneIPAddressesDS struct {
24+
config.DSCommon
25+
}
26+
27+
func (d *controlPlaneIPAddressesDS) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
28+
resp.Schema = DataSourceSchema(ctx)
29+
}
30+
31+
func (d *controlPlaneIPAddressesDS) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
32+
connV2 := d.Client.AtlasV2
33+
apiResp, _, err := connV2.RootApi.ReturnAllControlPlaneIPAddresses(ctx).Execute()
34+
if err != nil {
35+
resp.Diagnostics.AddError("error fetching control plane ip addresses", err.Error())
36+
return
37+
}
38+
newControlPlaneIPAddressesModel, diags := NewTFControlPlaneIPAddresses(ctx, apiResp)
39+
if diags.HasError() {
40+
resp.Diagnostics.Append(diags...)
41+
return
42+
}
43+
resp.Diagnostics.Append(resp.State.Set(ctx, newControlPlaneIPAddressesModel)...)
44+
}

0 commit comments

Comments
 (0)