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

[WIP] feat: add resource for managing custom applications #109

Closed
wants to merge 6 commits into from

Conversation

emmenko
Copy link
Contributor

@emmenko emmenko commented Mar 3, 2020

DO NOT MERGE YET

Since Custom Applications are in public beta now, we can provide a Terraform resource to manage their "registration" (currently possible only via the Merchant Center).

https://docs.commercetools.com/custom-applications/register-applications/configuring-a-custom-application

Some important notes for the reviewers:

  • the MC API endpoint to allow authorized requests needs to be adjusted a bit. The PR is already being reviewed and it will probably be available this week.

  • I decided to add the mc_api_url as a required field to the TF provider, in order to configure the graphql HTTP client.

    NOTE that if we were to reconfigure the provider with using region and cloud_region fields, all URLs can be automatically built internally and the user does not need to worry about that. Until then, we need to request the URLs explicitly.

  • I tested this manually locally and it seems to work as it should. The error handling of the graphql library is a bit "buggy" (there are some issues already), for example when the HTTP response is not a 200. I couldn't find a "better" graphql client, we can still write our own (it shouldn't be too difficult). We might also consider adding it to the go-sdk library.

  • I only added a basic unit test, I'm a bit unsure about the acceptance tests, as we would need to use the production APIs.

"commercetools_channel": resourceChannel(),
"commercetools_custom_application": resourceCustomApplication(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the new resource. The other changes here are because I sorted the list alphabetically.

// TerraformContext holds the HTTP and GraphQL clients to be used by the Terraform resources.
// We recommend to use the utility functions `getClient` and `getGraphQLClient`
// to get the necessary client object.
type TerraformContext struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This struct is used to hold different values that are used within the resources. Besides the HTTP client, I added the GraphQLClient and the ProjectKey.

// https://github.com/hashicorp/terraform-plugin-sdk/issues/62
// https://github.com/hashicorp/terraform-plugin-sdk/issues/155.
"navbar_menu": {
Type: schema.TypeList,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In JSON, this is an object, not a list. However, as far as I understand, nested object maps are not supported yet by the terraform sdk. See comment above

@mvantellingen
Copy link
Member

@emmenko sorry for getting back to this so late. I'm working on extracting your code and moving it to the commercetools-go-sdk project. See labd/commercetools-go-sdk#52

However i'm running into a permission issue so would be great to get some help over there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants