forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add app engine flex version (GoogleCloudPlatform#3110)
* added flexible app version * add sweeper file for flexible_app_version * sweeper changes, add website link, etc * add exclude to inspec.yaml * add exclude to ansible.yaml * missed * sweeper review comments * add test, other changes * update test to flask, ignore read on beta_settings for now * add copyright to app.yaml * rm django zip * update after review comments
- Loading branch information
Showing
13 changed files
with
1,124 additions
and
11 deletions.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
obj["env"] = "flex" | ||
return obj, nil |
46 changes: 46 additions & 0 deletions
46
templates/terraform/examples/app_engine_flexible_app_version.tf.erb
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
resource "google_app_engine_flexible_app_version" "<%= ctx[:primary_resource_id] %>" { | ||
version_id = "v1" | ||
service = "<%= ctx[:vars]['service_name'] %>" | ||
runtime = "nodejs" | ||
|
||
entrypoint { | ||
shell = "node ./app.js" | ||
} | ||
|
||
deployment { | ||
zip { | ||
source_url = "https://storage.googleapis.com/${google_storage_bucket.bucket.name}/${google_storage_bucket_object.object.name}" | ||
} | ||
} | ||
|
||
liveness_check { | ||
path = "/" | ||
} | ||
|
||
readiness_check { | ||
path = "/" | ||
} | ||
|
||
env_variables = { | ||
port = "8080" | ||
} | ||
|
||
automatic_scaling { | ||
cool_down_period = "120s" | ||
cpu_utilization { | ||
target_utilization = 0.5 | ||
} | ||
} | ||
|
||
delete_service_on_destroy = true | ||
} | ||
|
||
resource "google_storage_bucket" "bucket" { | ||
name = "<%= ctx[:vars]['bucket_name'] %>" | ||
} | ||
|
||
resource "google_storage_bucket_object" "object" { | ||
name = "hello-world.zip" | ||
bucket = google_storage_bucket.bucket.name | ||
source = "./test-fixtures/appengine/hello-world.zip" | ||
} |
83 changes: 83 additions & 0 deletions
83
third_party/terraform/tests/resource_app_engine_app_version_sweeper_test.go
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package google | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
// This will sweep both Standard and Flexible App Engine App Versions | ||
func init() { | ||
resource.AddTestSweepers("AppEngineAppVersion", &resource.Sweeper{ | ||
Name: "AppEngineAppVersion", | ||
F: testSweepAppEngineAppVersion, | ||
}) | ||
} | ||
|
||
// At the time of writing, the CI only passes us-central1 as the region | ||
func testSweepAppEngineAppVersion(region string) error { | ||
resourceName := "AppEngineAppVersion" | ||
log.Printf("[INFO][SWEEPER_LOG] Starting sweeper for %s", resourceName) | ||
|
||
config, err := sharedConfigForRegion(region) | ||
if err != nil { | ||
log.Printf("[INFO][SWEEPER_LOG] error getting shared config for region: %s", err) | ||
return err | ||
} | ||
|
||
err = config.LoadAndValidate(context.Background()) | ||
if err != nil { | ||
log.Printf("[INFO][SWEEPER_LOG] error loading: %s", err) | ||
return err | ||
} | ||
|
||
servicesUrl := "https://appengine.googleapis.com/v1/apps/" + config.Project + "/services" | ||
res, err := sendRequest(config, "GET", config.Project, servicesUrl, nil) | ||
if err != nil { | ||
log.Printf("[INFO][SWEEPER_LOG] Error in response from request %s: %s", servicesUrl, err) | ||
return nil | ||
} | ||
|
||
resourceList, ok := res["services"] | ||
if !ok { | ||
log.Printf("[INFO][SWEEPER_LOG] Nothing found in response.") | ||
return nil | ||
} | ||
|
||
rl := resourceList.([]interface{}) | ||
|
||
log.Printf("[INFO][SWEEPER_LOG] Found %d items in %s list response.", len(rl), resourceName) | ||
// items who don't match the tf-test prefix | ||
nonPrefixCount := 0 | ||
for _, ri := range rl { | ||
obj := ri.(map[string]interface{}) | ||
if obj["id"] == nil { | ||
log.Printf("[INFO][SWEEPER_LOG] %s resource id was nil", resourceName) | ||
return nil | ||
} | ||
|
||
id := obj["id"].(string) | ||
// Only sweep resources with the test prefix | ||
if !strings.HasPrefix(id, "tf-test") { | ||
nonPrefixCount++ | ||
continue | ||
} | ||
|
||
deleteUrl := servicesUrl + "/" + id | ||
// Don't wait on operations as we may have a lot to delete | ||
_, err = sendRequest(config, "DELETE", config.Project, deleteUrl, nil) | ||
if err != nil { | ||
log.Printf("[INFO][SWEEPER_LOG] Error deleting for url %s : %s", deleteUrl, err) | ||
} else { | ||
log.Printf("[INFO][SWEEPER_LOG] Sent delete request for %s resource: %s", resourceName, id) | ||
} | ||
} | ||
|
||
if nonPrefixCount > 0 { | ||
log.Printf("[INFO][SWEEPER_LOG] %d items without tf_test prefix remain.", nonPrefixCount) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.