Skip to content

feat: Adds new mongodbatlas_control_plane_ip_addresses data source #2331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 7, 2024

Conversation

AgustinBettati
Copy link
Member

@AgustinBettati AgustinBettati commented Jun 5, 2024

Description

Link to any related issue(s): CLOUDP-250897

Defines a new data source for the following endpoint: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Root/operation/returnAllControlPlaneIPAddresses

Example API response and resulting tf state
---[ REQUEST ]---------------------------------------
GET /api/atlas/v2/unauth/controlPlaneIPAddresses HTTP/1.1

---[ RESPONSE ]--------------------------------------
HTTP/2.0 200 OK
{
 "inbound": {
  "aws": {
   "ap-southeast-1": [],
   "eu-west-1": [],
  },
  "azure": {
   "australiaeast": [],
   "eastus2": [],
  },
  "gcp": {
   "europe-west1": [],
  }
 },
 "outbound": {
  "aws": {
   "ap-southeast-1": [
    "54.66.0.167/32",
    "54.253.68.72/32"
   ],
   "eu-west-1": [
    "54.78.184.167/32",
    "52.210.32.198/32"
   ],
   "us-east-1": [
    "3.90.117.229/32",
    "3.224.224.200/32"
   ]
  },
  "azure": {
   "australiaeast": [
    "20.53.129.178/32"
   ],
   "eastus2": [
    "20.94.32.37/32"
   ]
  },
  "gcp": {
   "europe-west1": [
    "34.78.42.14/32"
   ],
   "us-east4": [
    "34.85.218.41/32"
   ]
  }
 }
}

Resulting terraform state:

{
      "mode": "data",
      "type": "mongodbatlas_control_plane_ip_addresses",
      "name": "test",
      "provider": "provider[\"registry.terraform.io/mongodb/mongodbatlas\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "inbound": {
              "aws": {
                "ap-southeast-1": [],
                "eu-west-1": []
              },
              "azure": {
                "australiaeast": [],
                "eastus2": [],
                "westeurope": []
              },
              "gcp": {
                "europe-west1": []
              }
            },
            "outbound": {
              "aws": {
                "ap-southeast-1": [
                  "54.66.0.167/32",
                  "54.253.68.72/32"
                ],
                "eu-west-1": [
                  "54.78.184.167/32",
                  "52.210.32.198/32"
                ],
                "us-east-1": [
                  "3.90.117.229/32",
                  "3.224.224.200/32"
                ]
              },
              "azure": {
                "australiaeast": [
                  "20.53.129.178/32"
                ],
                "eastus2": [
                  "20.94.32.37/32"
                ]
              },
              "gcp": {
                "europe-west1": [
                  "34.78.42.14/32"
                ],
                "us-east4": [
                  "34.85.218.41/32"
                ]
              }
            }
          }
...

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR. A migration guide must be created or updated if the new feature will go in a major version.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR. A migration guide must be created or updated.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contributing guides
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals, I defined an isolated PR with a relevant title as it will be used in the auto-generated changelog.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

outboundGcpTfMap, outGcpDiags := toTFMap(ctx, outbound.GetGcp())
outboundAzureTfMap, outAzureDiags := toTFMap(ctx, outbound.GetAzure())

allDiags := slices.Concat(inAwsDiags, inGcpDiags, inAzureDiags, outAwsDiags, outGcpDiags, outAzureDiags)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go 1.22 :)

@AgustinBettati AgustinBettati marked this pull request as ready for review June 6, 2024 09:48
@AgustinBettati AgustinBettati requested review from a team as code owners June 6, 2024 09:48
Copy link
Contributor

github-actions bot commented Jun 6, 2024

APIx bot: a message has been sent to Docs Slack channel

Copy link
Collaborator

@oarbusi oarbusi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! LGTM

Copy link
Collaborator

@EspenAlbert EspenAlbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

Copy link
Collaborator

@maastha maastha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

nit: could this PR have been split into smaller ones?

@marcosuma
Copy link
Collaborator

Great job @AgustinBettati - did you use the automation to create the scaffolding?

Also +1 to @maastha sentiment, curious if we can come up with a smaller PR approach next time: biggest challenge is to make sure we don't miss smaller bugs such as misspells

Copy link
Collaborator

@jwilliams-mongo jwilliams-mongo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AgustinBettati LGTM % a few minor tweaks


### Read-Only

- `inbound` (Attributes) List of inbound IP addresses to the Atlas control plane, categorized by cloud provider. If your application allows outbound HTTP requests only to specific IP addresses, you must allow access to the following IP addresses so that your API requests can reach the Atlas control plane. (see [below for nested schema](#nestedatt--inbound))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added period at end + removed parenthetical as the last phrase is a complete sentence.

Suggested change
- `inbound` (Attributes) List of inbound IP addresses to the Atlas control plane, categorized by cloud provider. If your application allows outbound HTTP requests only to specific IP addresses, you must allow access to the following IP addresses so that your API requests can reach the Atlas control plane. (see [below for nested schema](#nestedatt--inbound))
- `inbound` (Attributes) List of inbound IP addresses to the Atlas control plane, categorized by cloud provider. If your application allows outbound HTTP requests only to specific IP addresses, you must allow access to the following IP addresses so that your API requests can reach the Atlas control plane. See [below for nested schema](#nestedatt--inbound).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this part of the text is autogenerated by an external tool. Can look into raising an issue if this is a concern.

- `azure` (Map of List of String) Control plane IP addresses in Azure. Each key identifies an Azure region. Each value identifies control plane IP addresses in the Azure region.
- `gcp` (Map of List of String) Control plane IP addresses in GCP. Each key identifies a Google Cloud (GCP) region. Each value identifies control plane IP addresses in the GCP region.

For more information see: [MongoDB Atlas API - Return All Control Plane IP Addresses](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Root/operation/returnAllControlPlaneIPAddresses) Documentation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For more information see: [MongoDB Atlas API - Return All Control Plane IP Addresses](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Root/operation/returnAllControlPlaneIPAddresses) Documentation.
For more information see: [MongoDB Atlas API - Return All Control Plane IP Addresses](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Root/operation/returnAllControlPlaneIPAddresses) in the Atlas Administration API documentation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that it is already mentioning MongoDB Atlas API I believe this additional text could be redundant. WDYT?

},
Computed: true,
Description: "Control plane IP addresses in AWS. Each key identifies an Amazon Web Services (AWS) region. Each value identifies control plane IP addresses in the AWS region.",
MarkdownDescription: "Control plane IP addresses in AWS. Each key identifies an Amazon Web Services (AWS) region. Each value identifies control plane IP addresses in the AWS region.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not in this PR but at some moment we might want to create a utility function that for instance, you only define Description, and it goes through the schema recursively filling MarkdownDescription

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that could be a possibility. Would take into account that these descriptions are created by the scaffolding tool (coming from the api spec), so not much effort from our side when they are being defined.

@@ -187,6 +187,7 @@ jobs:
search_index: ${{ steps.filter.outputs.search_index == 'true' || env.mustTrigger == 'true' }}
serverless: ${{ steps.filter.outputs.serverless == 'true' || env.mustTrigger == 'true' }}
stream: ${{ steps.filter.outputs.stream == 'true' || env.mustTrigger == 'true' }}
control_plane_ip_addresses: ${{ steps.filter.outputs.control_plane_ip_addresses == 'true' || env.mustTrigger == 'true' }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we also creating the resource for CFN and CDK?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that it is only a get request (and therefor a single data source in tf) I believe this could not be added as a resource in CFN.

@AgustinBettati
Copy link
Member Author

did you use the automation to create the scaffolding?

@marcosuma yes for this case used initial file scaffolding, schema and model scaffolding, and then documentation autogeneration. Included some fixes to these tools along the way, related to our new file naming convention aligned with our latest resource push-based log export.

could this PR have been split into smaller ones?

@maastha yes I see how this got a little to big as many small changes were included. Would keep fixes related to scaffolding + setup in CI as separate PR to avoid additional noise to the actual production code. Thanks for the input and sorry if the review was a challenge here.

@maastha
Copy link
Collaborator

maastha commented Jun 7, 2024

@maastha yes I see how this got a little to big as many small changes were included. Would keep fixes related to scaffolding + setup in CI as separate PR to avoid additional noise to the actual production code. Thanks for the input and sorry if the review was a challenge here.

no problem! Also, just FYI we do have a possible approach to split new feature PRs captured in our TF best practices doc, happy to discuss any alternatives/your general inputs there:)

@AgustinBettati AgustinBettati merged commit 029a209 into master Jun 7, 2024
35 checks passed
@AgustinBettati AgustinBettati deleted the CLOUDP-207757 branch June 7, 2024 11:00
svc-apix-Bot added a commit that referenced this pull request Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants