Skip to content
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

[datadog_app_builder_app_json] APPS-2248 & APPS-2144 App Builder Terraform Provider #2723

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

tyffical
Copy link

@tyffical tyffical commented Dec 16, 2024

Motivation

  • Adds the TF provider for the new App Builder Public API.
  • Includes
    • A data source for using Apps outside of resource definitions
    • A resource for managing Apps, with an app_json input
    • Support for importing existing Apps as resources.
    • Support for dynamically specifying Connection IDs using an optional action_query_ids_to_connection_ids map
  • Usage: copy and paste App definition JSON from App Builder's JSON editor into Terraform
    • We don't expect users to really create Apps from scratch using TF syntax (too complex). If users come to want this, we will put it in future work.
  • Ticket: https://datadoghq.atlassian.net/browse/APPS-2248
  • Epic: https://datadoghq.atlassian.net/browse/APPS-2144

References

Testing

  • Local manual testing (CRUD)
  • Record test cassettes with test org

Wait Before Merging

Open Questions

UPDATE: name will be datadog_app_builder_app b/c we decided offline we'll just keep this one resource and add extra TF optional fields if customer feedback suggests it is necessary
RESOLVED: name will be datadog_app_builder_app_json

  • Currently, this resource is called datadog_app. The plan is, in the future, updating this resource with extra structs in order to build an app in TF with TF syntax, strongly typing structs like queries and components.
    • Alternatively, what about creating a separate resource? This would help with making the code cleaner and disambiguate the two use cases. For instance, this resource would instead be datadog_app_json similar to how dashboards has a datadog_dashboard_json, and the non-json usage would be called datadog_app, like how dashboards also has datadog_dashboard.

@tyffical tyffical self-assigned this Dec 16, 2024
@tyffical tyffical force-pushed the tiffany.trinh/apps-2144-terraform branch 2 times, most recently from c37ed5c to 8006937 Compare December 18, 2024 19:32
@tyffical tyffical force-pushed the tiffany.trinh/apps-2144-terraform branch 2 times, most recently from 0e763b7 to 422a9c9 Compare January 13, 2025 19:44
Copy link
Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@tyffical tyffical force-pushed the tiffany.trinh/apps-2144-terraform branch from e7878b0 to 25dde39 Compare January 24, 2025 22:02
@tyffical tyffical changed the title scaffold app in tf provider [WIP] App Builder Terraform Provider Jan 24, 2025
@tyffical tyffical changed the title [WIP] App Builder Terraform Provider [WIP] [APPS-2132] [APPS-2144] App Builder Terraform Provider Jan 24, 2025
@tyffical tyffical force-pushed the tiffany.trinh/apps-2144-terraform branch from ce431ec to 19f3d2b Compare January 27, 2025 22:38
@tyffical tyffical changed the title [WIP] [APPS-2132] [APPS-2144] App Builder Terraform Provider [WIP] [APPS-2248] [APPS-2144] App Builder Terraform Provider Jan 29, 2025
@tyffical tyffical requested a review from oliverli February 4, 2025 21:15
@tyffical tyffical changed the title [WIP] [APPS-2248] [APPS-2144] App Builder Terraform Provider [APPS-2248] [APPS-2144] App Builder Terraform Provider Feb 4, 2025
@tyffical tyffical force-pushed the tiffany.trinh/apps-2144-terraform branch from 07cf33b to 02d8ac5 Compare February 4, 2025 23:07
@tyffical tyffical marked this pull request as ready for review February 5, 2025 21:51
@tyffical tyffical requested review from a team as code owners February 5, 2025 21:51
Copy link
Contributor

@embeaken embeaken left a comment

Choose a reason for hiding this comment

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

great work!

@@ -409,6 +411,16 @@ func defaultConfigureFunc(p *FrameworkProvider, request *provider.ConfigureReque
ddClientConfig.SetUnstableOperationEnabled("v2.DeleteAWSAccount", true)
ddClientConfig.SetUnstableOperationEnabled("v2.GetAWSAccount", true)

// Enable unstable operations for the App Builder API
Copy link
Contributor

Choose a reason for hiding this comment

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

before public release let's make sure the endpoints are on v2

resp, httpResp, err := r.Api.CreateApp(r.Auth, *createRequest)
if err != nil {
if httpResp != nil {
// error body may have useful info for the user
Copy link
Contributor

Choose a reason for hiding this comment

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

just an observation from my testing - you should make sure your API doesn't expose any internal errors or they will show up in TF errors as well

drichards-87
drichards-87 previously approved these changes Feb 6, 2025
Copy link
Contributor

@drichards-87 drichards-87 left a comment

Choose a reason for hiding this comment

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

Left some suggestions from the Docs and approved the PR.

oliverli

This comment was marked as resolved.

@tyffical tyffical force-pushed the tiffany.trinh/apps-2144-terraform branch 2 times, most recently from 0391be0 to 6807aa8 Compare February 14, 2025 06:48
@tyffical tyffical changed the title [APPS-2248] [APPS-2144] App Builder Terraform Provider [datadog_app_builder_app_json] [APPS-2248] [APPS-2144] App Builder Terraform Provider Feb 14, 2025
@tyffical tyffical changed the title [datadog_app_builder_app_json] [APPS-2248] [APPS-2144] App Builder Terraform Provider [datadog_app_builder_app_json] APPS-2248 & APPS-2144 App Builder Terraform Provider Feb 14, 2025
@tyffical tyffical force-pushed the tiffany.trinh/apps-2144-terraform branch from 58c3dac to 96dded8 Compare February 19, 2025 07:21
@tyffical tyffical requested a review from a team as a code owner February 21, 2025 23:53
}

func appJSONEqual(s1, s2 string) (bool, error) {
s1, err := normalizeAppBuilderAppJSONString(s1)

Choose a reason for hiding this comment

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

🔵 Code Quality Violation

Avoid modifying function parameters (...read more)

Assigning new values to function parameters exhibits several bad coding practices and should be avoided for several reasons:

  1. Redefining parameters: The code redefines a parameter within the function body by assigning a new value. This is considered a bad practice because it can lead to confusion and make the code harder to understand. Modifying a function parameter in this manner breaks the expected behavior and can cause unexpected side effects. It is generally best to treat function parameters as read-only values and avoid reassigning them.
  2. Shadowing variables: The code further exacerbates the issue by using the short variable declaration := to define a new variable within the function body. This shadows the original parameter, making it inaccessible within the function. Shadowing variables can cause confusion and make the code harder to reason about. It is better to use distinct variable names to maintain clarity and avoid any unintended side effects.

To write more maintainable and understandable code, it is advisable to adhere to the following practices:

  • Avoid redefining function parameters.
  • Use descriptive and unambiguous variable names.
  • Avoid shadowing variables.
  • Maintain consistency in variable references.

By following these best practices, the code becomes more readable and easier to manage and avoids introducing unnecessary complexity and confusion.

View in Datadog  Leave us feedback  Documentation

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.

4 participants