-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1d61c27
feat: add resource for managing custom applications
emmenko e4564cb
test: add basic test for custom apps
emmenko 5728b9e
docs(custom-apps): document resource fields
emmenko 0bb9e14
chore: missing env var for tests
emmenko 24790b3
test: add test for slugify function
emmenko 7cf828b
test: add test for TF meta object
emmenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/terraform" | ||
"github.com/labd/commercetools-go-sdk/commercetools" | ||
"github.com/machinebox/graphql" | ||
"golang.org/x/oauth2/clientcredentials" | ||
) | ||
|
||
|
@@ -55,34 +56,51 @@ func Provider() terraform.ResourceProvider { | |
DefaultFunc: schema.EnvDefaultFunc("CTP_AUTH_URL", nil), | ||
Description: "The authentication URL of the commercetools platform. https://docs.commercetools.com/http-api-authorization", | ||
}, | ||
"mc_api_url": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
DefaultFunc: schema.EnvDefaultFunc("CTP_MC_API_URL", nil), | ||
Description: "The API URL of the Merchant Center. https://docs.commercetools.com/custom-applications/main-concepts/api-gateway#hostnames", | ||
}, | ||
}, | ||
ResourcesMap: map[string]*schema.Resource{ | ||
"commercetools_api_client": resourceAPIClient(), | ||
"commercetools_api_extension": resourceAPIExtension(), | ||
"commercetools_subscription": resourceSubscription(), | ||
"commercetools_project_settings": resourceProjectSettings(), | ||
"commercetools_type": resourceType(), | ||
"commercetools_channel": resourceChannel(), | ||
"commercetools_custom_application": resourceCustomApplication(), | ||
"commercetools_product_type": resourceProductType(), | ||
"commercetools_project_settings": resourceProjectSettings(), | ||
"commercetools_shipping_method": resourceShippingMethod(), | ||
"commercetools_shipping_zone": resourceShippingZone(), | ||
"commercetools_shipping_zone_rate": resourceShippingZoneRate(), | ||
"commercetools_state": resourceState(), | ||
"commercetools_store": resourceStore(), | ||
"commercetools_subscription": resourceSubscription(), | ||
"commercetools_tax_category": resourceTaxCategory(), | ||
"commercetools_tax_category_rate": resourceTaxCategoryRate(), | ||
"commercetools_shipping_zone": resourceShippingZone(), | ||
"commercetools_state": resourceState(), | ||
"commercetools_type": resourceType(), | ||
}, | ||
ConfigureFunc: providerConfigure, | ||
} | ||
} | ||
|
||
// 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
HTTPClient *commercetools.Client | ||
GraphQLClient *graphql.Client | ||
ProjectKey string | ||
} | ||
|
||
func providerConfigure(d *schema.ResourceData) (interface{}, error) { | ||
clientID := d.Get("client_id").(string) | ||
clientSecret := d.Get("client_secret").(string) | ||
projectKey := d.Get("project_key").(string) | ||
scopesRaw := d.Get("scopes").(string) | ||
apiURL := d.Get("api_url").(string) | ||
authURL := d.Get("token_url").(string) | ||
mcAPIURL := d.Get("mc_api_url").(string) | ||
|
||
oauthScopes := strings.Split(scopesRaw, " ") | ||
|
||
|
@@ -103,7 +121,15 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) { | |
ContactEmail: "opensource@labdigital.nl", | ||
}) | ||
|
||
return client, nil | ||
graphqlClient := graphql.NewClient(fmt.Sprintf("%s/graphql", mcAPIURL), graphql.WithHTTPClient(httpClient)) | ||
|
||
meta := TerraformContext{ | ||
HTTPClient: client, | ||
GraphQLClient: graphqlClient, | ||
ProjectKey: projectKey, | ||
} | ||
|
||
return meta, nil | ||
} | ||
|
||
// This is a global MutexKV for use within this plugin. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.