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

Added google_apigee_api resource #20113

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .changelog/12036.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
`google_apigee_api`
```
1 change: 1 addition & 0 deletions google/provider/provider_mmv1_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,7 @@ var generatedResources = map[string]*schema.Resource{
var handwrittenResources = map[string]*schema.Resource{
// ####### START handwritten resources ###########
"google_app_engine_application": appengine.ResourceAppEngineApplication(),
"google_apigee_api": apigee.ResourceApigeeApi(),
"google_apigee_sharedflow": apigee.ResourceApigeeSharedFlow(),
"google_apigee_sharedflow_deployment": apigee.ResourceApigeeSharedFlowDeployment(),
"google_apigee_flowhook": apigee.ResourceApigeeFlowhook(),
Expand Down
76 changes: 74 additions & 2 deletions google/services/apigee/apigee_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
package apigee

import (
"encoding/json"
"fmt"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
"google.golang.org/api/googleapi"
"io"
"log"
"net/http"
"time"
)

func resourceApigeeNatAddressActivate(config *transport_tpg.Config, d *schema.ResourceData, billingProject string, userAgent string) error {
Expand Down Expand Up @@ -47,3 +51,71 @@ func resourceApigeeNatAddressActivate(config *transport_tpg.Config, d *schema.Re
}
return nil
}

// sendRequestRawBodyWithTimeout is derived from sendRequestWithTimeout with direct pass through of request body
func sendRequestRawBodyWithTimeout(config *transport_tpg.Config, method, project, rawurl, userAgent string, body io.Reader, contentType string, timeout time.Duration, errorRetryPredicates ...transport_tpg.RetryErrorPredicateFunc) (map[string]interface{}, error) {
log.Printf("[DEBUG] sendRequestRawBodyWithTimeout start")
reqHeaders := make(http.Header)
reqHeaders.Set("User-Agent", userAgent)
reqHeaders.Set("Content-Type", contentType)

if config.UserProjectOverride && project != "" {
// Pass the project into this fn instead of parsing it from the URL because
// both project names and URLs can have colons in them.
reqHeaders.Set("X-Goog-User-Project", project)
}

if timeout == 0 {
timeout = time.Duration(1) * time.Minute
}

var res *http.Response

log.Printf("[DEBUG] sendRequestRawBodyWithTimeout sending request")

err := transport_tpg.Retry(transport_tpg.RetryOptions{
RetryFunc: func() error {
req, err := http.NewRequest(method, rawurl, body)
if err != nil {
return err
}

req.Header = reqHeaders
res, err = config.Client.Do(req)
if err != nil {
return err
}

if err := googleapi.CheckResponse(res); err != nil {
googleapi.CloseBody(res)
return err
}

return nil
},
Timeout: timeout,
ErrorRetryPredicates: errorRetryPredicates,
})
if err != nil {
return nil, err
}

if res == nil {
return nil, fmt.Errorf("Unable to parse server response. This is most likely a terraform problem, please file a bug at https://github.com/hashicorp/terraform-provider-google/issues.")
}

// The defer call must be made outside of the retryFunc otherwise it's closed too soon.
defer googleapi.CloseBody(res)

// 204 responses will have no body, so we're going to error with "EOF" if we
// try to parse it. Instead, we can just return nil.
if res.StatusCode == 204 {
return nil, nil
}
result := make(map[string]interface{})
if err := json.NewDecoder(res.Body).Decode(&result); err != nil {
return nil, err
}
log.Printf("[DEBUG] sendRequestRawBodyWithTimeout returning")
return result, nil
}
Loading