-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add support for Apigee Sharedflow #7202
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
megan07
merged 52 commits into
GoogleCloudPlatform:main
from
5fff:sharedflow-probably-good
Mar 8, 2023
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
fd5c40b
added sharedflows mmv1 with error
5c687f3
fix indentation issue for sharedflow
2a963f0
add semi auto generated resourceApigeeSharedFlow
730431f
remove sharedflow mmv1 and add sharedflow manual provider
88d07da
Merge branch 'main' into sharedflows
e0576c6
adding files for debugging review, test have issue
4c58df8
adding files for debugging review, test have issue
1217528
update test, doc, provider for apigee
3141ab6
Merge commit 'f9e53cbd7dcbbf1037090db7ac40860f12add257' into sharedfl…
c21bfd4
Merge branch 'main' into sharedflow-probably-good
5fff 7b9b569
Update api.yaml
5fff 97dde6c
Update api.yaml
5fff 6d50fc0
Rename resource_apigee_shared_flow_generated_test.go to resource_apig…
5fff 1d526c0
Update resource_apigee_shared_flow.go
5fff f49215a
Update mmv1/third_party/terraform/utils/provider.go.erb
5fff 993f851
update PR to address comments
a323142
merge
af6e332
Merge branch 'GoogleCloudPlatform:main' into sharedflow-probably-good
5fff 7c2ab14
Merge branch 'GoogleCloudPlatform:main' into sharedflow-probably-good
5fff 4353e36
update test
13b8a44
Merge branch 'GoogleCloudPlatform:main' into sharedflow-probably-good
5fff 37d4fd4
Merge branch 'GoogleCloudPlatform:main' into sharedflow-probably-good
5fff a2b9453
fix sharedflow attribute update issue, add sharedflow deployment
bbee68b
Merge branch 'main' into sharedflow-probably-good
5fff fdb4e17
Update apigee_shared_flow_deployment.html.markdown
5fff a84b32d
Update mmv1/third_party/terraform/utils/provider.go.erb
5fff 7921f9f
Update mmv1/third_party/terraform/website/docs/r/apigee_shared_flow.h…
5fff 378fa0a
Update resource_apigee_shared_flow_test.go
5fff 724c350
Delete api.yaml
5fff bb3ed9a
Rename apigee_shared_flow.html.markdown to apigee_sharedflow.html.mar…
5fff fb1ab7a
Rename apigee_shared_flow_deployment.html.markdown to apigee_sharedfl…
5fff 810f23e
Rename resource_apigee_shared_flow.go to resource_apigee_sharedflow.go
5fff 7ab690b
Rename resource_apigee_shared_flow_deployment_test.go to resource_api…
5fff 30903e1
Rename resource_apigee_shared_flow_test.go to resource_apigee_sharedf…
5fff 0664047
Rename resource_apigee_shared_flow_sweeper_test.go to resource_apigee…
5fff 13fb482
Update resource_apigee_sharedflow.go
5fff 2703308
Update mmv1/third_party/terraform/resources/resource_apigee_sharedflo…
5fff f364572
Update resource_apigee_sharedflow_deployment_test.go
5fff b262d88
Merge branch 'GoogleCloudPlatform:main' into sharedflow-probably-good
5fff 415c3ff
update function name to capitalize
b9c6e59
Update resource_apigee_sharedflow_deployment_test.go
5fff f2fe53a
add flowhook
a05ebea
move flowhook doc
68d8ce7
Update mmv1/third_party/terraform/tests/resource_apigee_flowhook_test.go
5fff 7984858
Update mmv1/third_party/terraform/website/docs/r/apigee_flowhook.html…
5fff 823c092
Update mmv1/third_party/terraform/website/docs/r/apigee_flowhook.html…
5fff 2a4df9c
Update mmv1/third_party/terraform/tests/resource_apigee_flowhook_test.go
5fff 3defe5f
Update resource_apigee_flowhook_test.go
5fff b8ec591
update some resource attribute properties
ff82a53
Update apigee_flowhook.html.markdown
5fff 6f9cbf7
Merge branch 'GoogleCloudPlatform:main' into sharedflow-probably-good
5fff 0acefe3
update referenced function naming case
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
240 changes: 240 additions & 0 deletions
240
mmv1/third_party/terraform/resources/resource_apigee_flowhook.go
This file contains hidden or 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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,240 @@ | ||||||
| package google | ||||||
|
|
||||||
| import ( | ||||||
| "fmt" | ||||||
| "log" | ||||||
| "reflect" | ||||||
| "time" | ||||||
|
|
||||||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||||||
| ) | ||||||
|
|
||||||
| func ResourceApigeeFlowhook() *schema.Resource { | ||||||
| return &schema.Resource{ | ||||||
| Create: resourceApigeeFlowhookCreate, | ||||||
| Read: resourceApigeeFlowhookRead, | ||||||
| Delete: resourceApigeeFlowhookDelete, | ||||||
|
|
||||||
| Importer: &schema.ResourceImporter{ | ||||||
| State: resourceApigeeFlowhookImport, | ||||||
| }, | ||||||
|
|
||||||
| Timeouts: &schema.ResourceTimeout{ | ||||||
| Create: schema.DefaultTimeout(20 * time.Minute), | ||||||
| Delete: schema.DefaultTimeout(20 * time.Minute), | ||||||
| }, | ||||||
|
|
||||||
| Schema: map[string]*schema.Schema{ | ||||||
| "description": { | ||||||
| Type: schema.TypeString, | ||||||
| Optional: true, | ||||||
| ForceNew: true, | ||||||
| Description: `Description of the flow hook.`, | ||||||
| }, | ||||||
| "environment": { | ||||||
| Type: schema.TypeString, | ||||||
| Required: true, | ||||||
| ForceNew: true, | ||||||
| Description: `The resource ID of the environment.`, | ||||||
| }, | ||||||
| "flow_hook_point": { | ||||||
| Type: schema.TypeString, | ||||||
| Required: true, | ||||||
| ForceNew: true, | ||||||
| Description: `Where in the API call flow the flow hook is invoked. Must be one of PreProxyFlowHook, PostProxyFlowHook, PreTargetFlowHook, or PostTargetFlowHook.`, | ||||||
| }, | ||||||
| "org_id": { | ||||||
| Type: schema.TypeString, | ||||||
| Required: true, | ||||||
| ForceNew: true, | ||||||
| Description: `The Apigee Organization associated with the environment`, | ||||||
| }, | ||||||
| "sharedflow": { | ||||||
| Type: schema.TypeString, | ||||||
| Required: true, | ||||||
| ForceNew: true, | ||||||
| Description: `Id of the Sharedflow attaching to a flowhook point.`, | ||||||
| }, | ||||||
| "continue_on_error": { | ||||||
| Type: schema.TypeBool, | ||||||
| ForceNew: true, | ||||||
| Optional: true, | ||||||
| Default: true, | ||||||
| Description: `Flag that specifies whether execution should continue if the flow hook throws an exception. Set to true to continue execution. Set to false to stop execution if the flow hook throws an exception. Defaults to true.`, | ||||||
| }, | ||||||
| }, | ||||||
| UseJSONNumber: true, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| func resourceApigeeFlowhookCreate(d *schema.ResourceData, meta interface{}) error { | ||||||
| config := meta.(*Config) | ||||||
| userAgent, err := generateUserAgentString(d, config.UserAgent) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
|
|
||||||
| obj := make(map[string]interface{}) | ||||||
| descriptionProp, err := expandApigeeFlowhookDescription(d.Get("description"), d, config) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { | ||||||
| obj["description"] = descriptionProp | ||||||
| } | ||||||
| sharedflowProp, err := expandApigeeFlowhookSharedflow(d.Get("sharedflow"), d, config) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } else if v, ok := d.GetOkExists("sharedflow"); !isEmptyValue(reflect.ValueOf(sharedflowProp)) && (ok || !reflect.DeepEqual(v, sharedflowProp)) { | ||||||
| obj["sharedFlow"] = sharedflowProp | ||||||
| } | ||||||
| continue_on_errorProp, err := expandApigeeFlowhookContinueOnError(d.Get("continue_on_error"), d, config) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } else if v, ok := d.GetOkExists("continue_on_error"); !isEmptyValue(reflect.ValueOf(continue_on_errorProp)) && (ok || !reflect.DeepEqual(v, continue_on_errorProp)) { | ||||||
| obj["continueOnError"] = continue_on_errorProp | ||||||
| } | ||||||
|
|
||||||
| url, err := replaceVars(d, config, "{{ApigeeBasePath}}organizations/{{org_id}}/environments/{{environment}}/flowhooks/{{flow_hook_point}}") | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
|
|
||||||
| log.Printf("[DEBUG] Creating new Flowhook: %#v", obj) | ||||||
| billingProject := "" | ||||||
|
|
||||||
| // err == nil indicates that the billing_project value was found | ||||||
| if bp, err := getBillingProject(d, config); err == nil { | ||||||
| billingProject = bp | ||||||
| } | ||||||
|
|
||||||
| res, err := SendRequestWithTimeout(config, "PUT", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate)) | ||||||
| if err != nil { | ||||||
| return fmt.Errorf("Error creating Flowhook: %s", err) | ||||||
| } | ||||||
|
|
||||||
| // Store the ID now | ||||||
| id, err := replaceVars(d, config, "organizations/{{org_id}}/environments/{{environment}}/flowhooks/{{flow_hook_point}}") | ||||||
| if err != nil { | ||||||
| return fmt.Errorf("Error constructing id: %s", err) | ||||||
| } | ||||||
| d.SetId(id) | ||||||
|
|
||||||
| log.Printf("[DEBUG] Finished creating Flowhook %q: %#v", d.Id(), res) | ||||||
|
|
||||||
| return resourceApigeeFlowhookRead(d, meta) | ||||||
| } | ||||||
|
|
||||||
| func resourceApigeeFlowhookRead(d *schema.ResourceData, meta interface{}) error { | ||||||
| config := meta.(*Config) | ||||||
| userAgent, err := generateUserAgentString(d, config.UserAgent) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
|
|
||||||
| url, err := replaceVars(d, config, "{{ApigeeBasePath}}organizations/{{org_id}}/environments/{{environment}}/flowhooks/{{flow_hook_point}}") | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
|
|
||||||
| billingProject := "" | ||||||
|
|
||||||
| // err == nil indicates that the billing_project value was found | ||||||
| if bp, err := getBillingProject(d, config); err == nil { | ||||||
| billingProject = bp | ||||||
| } | ||||||
|
|
||||||
| res, err := SendRequest(config, "GET", billingProject, url, userAgent, nil) | ||||||
| if err != nil { | ||||||
| return handleNotFoundError(err, d, fmt.Sprintf("ApigeeFlowhook %q", d.Id())) | ||||||
| } | ||||||
| if res["sharedFlow"] == nil || res["sharedFlow"].(string) == "" { | ||||||
| //if response does not contain shared_flow field, then nothing is attached to this flowhook, we treat this "binding" resource non-existent | ||||||
|
Contributor
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.
Suggested change
|
||||||
| d.SetId("") | ||||||
| return nil | ||||||
| } | ||||||
| if err := d.Set("description", flattenApigeeFlowhookDescription(res["description"], d, config)); err != nil { | ||||||
| return fmt.Errorf("Error reading Flowhook: %s", err) | ||||||
| } | ||||||
| if err := d.Set("sharedflow", flattenApigeeFlowhookSharedflow(res["sharedFlow"], d, config)); err != nil { | ||||||
| return fmt.Errorf("Error reading Flowhook: %s", err) | ||||||
| } | ||||||
| if err := d.Set("continue_on_error", flattenApigeeFlowhookContinueOnError(res["continueOnError"], d, config)); err != nil { | ||||||
| return fmt.Errorf("Error reading Flowhook: %s", err) | ||||||
| } | ||||||
|
|
||||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| func resourceApigeeFlowhookDelete(d *schema.ResourceData, meta interface{}) error { | ||||||
| config := meta.(*Config) | ||||||
| userAgent, err := generateUserAgentString(d, config.UserAgent) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
|
|
||||||
| billingProject := "" | ||||||
|
|
||||||
| url, err := replaceVars(d, config, "{{ApigeeBasePath}}organizations/{{org_id}}/environments/{{environment}}/flowhooks/{{flow_hook_point}}") | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
|
|
||||||
| var obj map[string]interface{} | ||||||
| log.Printf("[DEBUG] Deleting Flowhook %q", d.Id()) | ||||||
|
|
||||||
| // err == nil indicates that the billing_project value was found | ||||||
| if bp, err := getBillingProject(d, config); err == nil { | ||||||
| billingProject = bp | ||||||
| } | ||||||
|
|
||||||
| res, err := SendRequestWithTimeout(config, "DELETE", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutDelete)) | ||||||
| if err != nil { | ||||||
| return handleNotFoundError(err, d, "Flowhook") | ||||||
| } | ||||||
|
|
||||||
| log.Printf("[DEBUG] Finished deleting Flowhook %q: %#v", d.Id(), res) | ||||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| func resourceApigeeFlowhookImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { | ||||||
| config := meta.(*Config) | ||||||
| if err := parseImportId([]string{ | ||||||
| "organizations/(?P<org_id>[^/]+)/environments/(?P<environment>[^/]+)/flowhooks/(?P<flow_hook_point>[^/]+)", | ||||||
| "(?P<org_id>[^/]+)/(?P<environment>[^/]+)/(?P<flow_hook_point>[^/]+)", | ||||||
| }, d, config); err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| // Replace import id for the resource id | ||||||
| id, err := replaceVars(d, config, "organizations/{{org_id}}/environments/{{environment}}/flowhooks/{{flow_hook_point}}") | ||||||
| if err != nil { | ||||||
| return nil, fmt.Errorf("Error constructing id: %s", err) | ||||||
| } | ||||||
| d.SetId(id) | ||||||
|
|
||||||
| return []*schema.ResourceData{d}, nil | ||||||
| } | ||||||
|
|
||||||
| func flattenApigeeFlowhookDescription(v interface{}, d *schema.ResourceData, config *Config) interface{} { | ||||||
| return v | ||||||
| } | ||||||
|
|
||||||
| func flattenApigeeFlowhookSharedflow(v interface{}, d *schema.ResourceData, config *Config) interface{} { | ||||||
| return v | ||||||
| } | ||||||
|
|
||||||
| func flattenApigeeFlowhookContinueOnError(v interface{}, d *schema.ResourceData, config *Config) interface{} { | ||||||
| return v | ||||||
| } | ||||||
|
|
||||||
| func expandApigeeFlowhookDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { | ||||||
| return v, nil | ||||||
| } | ||||||
|
|
||||||
| func expandApigeeFlowhookSharedflow(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { | ||||||
| return v, nil | ||||||
| } | ||||||
|
|
||||||
| func expandApigeeFlowhookContinueOnError(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { | ||||||
| return v, nil | ||||||
| } | ||||||
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.
Uh oh!
There was an error while loading. Please reload this page.