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

add app engine flex version #5882

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/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