Skip to content

Commit

Permalink
Add support for IAP in google_app_engine_application resource (#3058) (
Browse files Browse the repository at this point in the history
…#1703)

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Jan 31, 2020
1 parent 2c2e5b9 commit b28ffaa
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/3058.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
appengine: added support for `google_app_engine_application.iap`
```
61 changes: 61 additions & 0 deletions google-beta/resource_app_engine_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,30 @@ func resourceAppEngineApplication() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"iap": {
Type: schema.TypeList,
Optional: true,
Description: `Settings for enabling Cloud Identity Aware Proxy`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"oauth2_client_id": {
Type: schema.TypeString,
Required: true,
},
"oauth2_client_secret": {
Type: schema.TypeString,
Required: true,
Sensitive: true,
},
"oauth2_client_secret_sha256": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -195,6 +219,14 @@ func resourceAppEngineApplicationRead(d *schema.ResourceData, meta interface{})
if err != nil {
return fmt.Errorf("Error setting feature settings in state. This is a bug, please report it at https://github.com/terraform-providers/terraform-provider-google/issues. Error is:\n%s", err.Error())
}
iap, err := flattenAppEngineApplicationIap(d, app.Iap)
if err != nil {
return err
}
err = d.Set("iap", iap)
if err != nil {
return fmt.Errorf("Error setting iap in state. This is a bug, please report it at https://github.com/terraform-providers/terraform-provider-google/issues. Error is:\n%s", err.Error())
}
return nil
}

Expand Down Expand Up @@ -239,6 +271,11 @@ func expandAppEngineApplication(d *schema.ResourceData, project string) (*appeng
return nil, err
}
result.FeatureSettings = featureSettings
iap, err := expandAppEngineApplicationIap(d)
if err != nil {
return nil, err
}
result.Iap = iap
return result, nil
}

Expand All @@ -254,6 +291,18 @@ func expandAppEngineApplicationFeatureSettings(d *schema.ResourceData) (*appengi
}, nil
}

func expandAppEngineApplicationIap(d *schema.ResourceData) (*appengine.IdentityAwareProxy, error) {
blocks := d.Get("iap").([]interface{})
if len(blocks) < 1 {
return nil, nil
}
return &appengine.IdentityAwareProxy{
Oauth2ClientId: d.Get("iap.0.oauth2_client_id").(string),
Oauth2ClientSecret: d.Get("iap.0.oauth2_client_secret").(string),
Oauth2ClientSecretSha256: d.Get("iap.0.oauth2_client_secret_sha256").(string),
}, nil
}

func flattenAppEngineApplicationFeatureSettings(settings *appengine.FeatureSettings) ([]map[string]interface{}, error) {
if settings == nil {
return []map[string]interface{}{}, nil
Expand All @@ -264,6 +313,18 @@ func flattenAppEngineApplicationFeatureSettings(settings *appengine.FeatureSetti
return []map[string]interface{}{result}, nil
}

func flattenAppEngineApplicationIap(d *schema.ResourceData, iap *appengine.IdentityAwareProxy) ([]map[string]interface{}, error) {
if iap == nil {
return []map[string]interface{}{}, nil
}
result := map[string]interface{}{
"oauth2_client_id": iap.Oauth2ClientId,
"oauth2_client_secret": d.Get("iap.0.oauth2_client_secret"),
"oauth2_client_secret_sha256": iap.Oauth2ClientSecretSha256,
}
return []map[string]interface{}{result}, nil
}

func flattenAppEngineApplicationDispatchRules(rules []*appengine.UrlDispatchRule) ([]map[string]interface{}, error) {
results := make([]map[string]interface{}, 0, len(rules))
for _, rule := range rules {
Expand Down
45 changes: 45 additions & 0 deletions google-beta/resource_app_engine_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,51 @@ func TestAccAppEngineApplication_basic(t *testing.T) {
})
}

func TestAccAppEngineApplication_withIAP(t *testing.T) {
t.Parallel()

org := getTestOrgFromEnv(t)
pid := acctest.RandomWithPrefix("tf-test")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAppEngineApplication_withIAP(pid, org),
},
{
ResourceName: "google_app_engine_application.acceptance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"iap.0.oauth2_client_secret"},
},
},
})
}

func testAccAppEngineApplication_withIAP(pid, org string) string {
return fmt.Sprintf(`
resource "google_project" "acceptance" {
project_id = "%s"
name = "%s"
org_id = "%s"
}
resource "google_app_engine_application" "acceptance" {
project = google_project.acceptance.project_id
auth_domain = "hashicorptest.com"
location_id = "us-central"
serving_status = "SERVING"
iap {
oauth2_client_id = "test"
oauth2_client_secret = "test"
}
}
`, pid, pid, org)
}

func testAccAppEngineApplication_basic(pid, org string) string {
return fmt.Sprintf(`
resource "google_project" "acceptance" {
Expand Down

0 comments on commit b28ffaa

Please sign in to comment.