Skip to content

Commit

Permalink
add app engine flex version (#3110) (#5882)
Browse files Browse the repository at this point in the history
* 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

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Mar 11, 2020
1 parent a2821f3 commit 1647e8f
Show file tree
Hide file tree
Showing 13 changed files with 4,120 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .changelog/3110.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
appengine: added new resource `google_appengine_flexible_app_version"
```
5 changes: 3 additions & 2 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,9 @@ func Provider() terraform.ResourceProvider {
return provider
}

// Generated resources: 107
// Generated resources: 108
// Generated IAM resources: 51
// Total generated resources: 158
// Total generated resources: 159
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand All @@ -529,6 +529,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_app_engine_domain_mapping": resourceAppEngineDomainMapping(),
"google_app_engine_firewall_rule": resourceAppEngineFirewallRule(),
"google_app_engine_standard_app_version": resourceAppEngineStandardAppVersion(),
"google_app_engine_flexible_app_version": resourceAppEngineFlexibleAppVersion(),
"google_app_engine_application_url_dispatch_rules": resourceAppEngineApplicationUrlDispatchRules(),
"google_app_engine_service_split_traffic": resourceAppEngineServiceSplitTraffic(),
"google_bigquery_dataset": resourceBigQueryDataset(),
Expand Down
83 changes: 83 additions & 0 deletions google/resource_app_engine_app_version_sweeper_test.go
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
}
Loading

0 comments on commit 1647e8f

Please sign in to comment.