Skip to content
Merged
Show file tree
Hide file tree
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
Dec 2, 2022
5c687f3
fix indentation issue for sharedflow
Dec 2, 2022
2a963f0
add semi auto generated resourceApigeeSharedFlow
Dec 5, 2022
730431f
remove sharedflow mmv1 and add sharedflow manual provider
Dec 16, 2022
88d07da
Merge branch 'main' into sharedflows
Dec 16, 2022
e0576c6
adding files for debugging review, test have issue
Jan 31, 2023
4c58df8
adding files for debugging review, test have issue
Jan 31, 2023
1217528
update test, doc, provider for apigee
Feb 1, 2023
3141ab6
Merge commit 'f9e53cbd7dcbbf1037090db7ac40860f12add257' into sharedfl…
Feb 2, 2023
c21bfd4
Merge branch 'main' into sharedflow-probably-good
5fff Feb 7, 2023
7b9b569
Update api.yaml
5fff Feb 8, 2023
97dde6c
Update api.yaml
5fff Feb 8, 2023
6d50fc0
Rename resource_apigee_shared_flow_generated_test.go to resource_apig…
5fff Feb 8, 2023
1d526c0
Update resource_apigee_shared_flow.go
5fff Feb 8, 2023
f49215a
Update mmv1/third_party/terraform/utils/provider.go.erb
5fff Feb 10, 2023
993f851
update PR to address comments
Feb 15, 2023
a323142
merge
Feb 15, 2023
af6e332
Merge branch 'GoogleCloudPlatform:main' into sharedflow-probably-good
5fff Feb 16, 2023
7c2ab14
Merge branch 'GoogleCloudPlatform:main' into sharedflow-probably-good
5fff Feb 16, 2023
4353e36
update test
Feb 16, 2023
13b8a44
Merge branch 'GoogleCloudPlatform:main' into sharedflow-probably-good
5fff Feb 16, 2023
37d4fd4
Merge branch 'GoogleCloudPlatform:main' into sharedflow-probably-good
5fff Feb 17, 2023
a2b9453
fix sharedflow attribute update issue, add sharedflow deployment
Feb 28, 2023
bbee68b
Merge branch 'main' into sharedflow-probably-good
5fff Feb 28, 2023
fdb4e17
Update apigee_shared_flow_deployment.html.markdown
5fff Feb 28, 2023
a84b32d
Update mmv1/third_party/terraform/utils/provider.go.erb
5fff Feb 28, 2023
7921f9f
Update mmv1/third_party/terraform/website/docs/r/apigee_shared_flow.h…
5fff Feb 28, 2023
378fa0a
Update resource_apigee_shared_flow_test.go
5fff Feb 28, 2023
724c350
Delete api.yaml
5fff Feb 28, 2023
bb3ed9a
Rename apigee_shared_flow.html.markdown to apigee_sharedflow.html.mar…
5fff Feb 28, 2023
fb1ab7a
Rename apigee_shared_flow_deployment.html.markdown to apigee_sharedfl…
5fff Feb 28, 2023
810f23e
Rename resource_apigee_shared_flow.go to resource_apigee_sharedflow.go
5fff Feb 28, 2023
7ab690b
Rename resource_apigee_shared_flow_deployment_test.go to resource_api…
5fff Feb 28, 2023
30903e1
Rename resource_apigee_shared_flow_test.go to resource_apigee_sharedf…
5fff Feb 28, 2023
0664047
Rename resource_apigee_shared_flow_sweeper_test.go to resource_apigee…
5fff Feb 28, 2023
13fb482
Update resource_apigee_sharedflow.go
5fff Feb 28, 2023
2703308
Update mmv1/third_party/terraform/resources/resource_apigee_sharedflo…
5fff Feb 28, 2023
f364572
Update resource_apigee_sharedflow_deployment_test.go
5fff Feb 28, 2023
b262d88
Merge branch 'GoogleCloudPlatform:main' into sharedflow-probably-good
5fff Feb 28, 2023
415c3ff
update function name to capitalize
Mar 1, 2023
b9c6e59
Update resource_apigee_sharedflow_deployment_test.go
5fff Mar 1, 2023
f2fe53a
add flowhook
Mar 2, 2023
a05ebea
move flowhook doc
Mar 2, 2023
68d8ce7
Update mmv1/third_party/terraform/tests/resource_apigee_flowhook_test.go
5fff Mar 2, 2023
7984858
Update mmv1/third_party/terraform/website/docs/r/apigee_flowhook.html…
5fff Mar 2, 2023
823c092
Update mmv1/third_party/terraform/website/docs/r/apigee_flowhook.html…
5fff Mar 2, 2023
2a4df9c
Update mmv1/third_party/terraform/tests/resource_apigee_flowhook_test.go
5fff Mar 2, 2023
3defe5f
Update resource_apigee_flowhook_test.go
5fff Mar 2, 2023
b8ec591
update some resource attribute properties
Mar 6, 2023
ff82a53
Update apigee_flowhook.html.markdown
5fff Mar 6, 2023
6f9cbf7
Merge branch 'GoogleCloudPlatform:main' into sharedflow-probably-good
5fff Mar 7, 2023
0acefe3
update referenced function naming case
Mar 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 240 additions & 0 deletions mmv1/third_party/terraform/resources/resource_apigee_flowhook.go
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,
Comment thread
megan07 marked this conversation as resolved.
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
//if response does not contain shared_flow field, then nothing is attached to this flowhook, we treat this "binding" resource non-existent
// if response does not contain shared_flow field, then nothing is attached to this flowhook, we treat this "binding" resource non-existent

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
}
Loading