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.
IAP brand & client (GoogleCloudPlatform#3135)
* IAP brand & client * First pass at review * get rid of extra_schema entry * Make GOOGLE_ORG_DOMAIN a test variable
- Loading branch information
Showing
12 changed files
with
272 additions
and
1 deletion.
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
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,18 @@ | ||
config := meta.(*Config) | ||
|
||
// current import_formats can't import fields with forward slashes in their value | ||
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil { | ||
return nil, err | ||
} | ||
|
||
nameParts := strings.Split(d.Get("name").(string), "/") | ||
if len(nameParts) != 4 { | ||
return nil, fmt.Errorf( | ||
"Saw %s when the name is expected to have shape %s", | ||
d.Get("name"), | ||
"projects/{{project}}/brands/{{name}}", | ||
) | ||
} | ||
|
||
d.Set("project", nameParts[1]) | ||
return []*schema.ResourceData{d}, nil |
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,19 @@ | ||
config := meta.(*Config) | ||
|
||
// current import_formats can't import fields with forward slashes in their value | ||
if err := parseImportId([]string{"(?P<brand>.+)"}, d, config); err != nil { | ||
return nil, err | ||
} | ||
|
||
nameParts := strings.Split(d.Get("brand").(string), "/") | ||
if len(nameParts) != 6 { | ||
return nil, fmt.Errorf( | ||
"Saw %s when the name is expected to have shape %s", | ||
d.Get("brand").(string), | ||
"projects/{{project_number}}/brands/{{brand_id}}/identityAwareProxyClients/{{client_id}}", | ||
) | ||
} | ||
|
||
d.Set("brand", fmt.Sprintf("projects/%s/brands/%s", nameParts[1], nameParts[3])) | ||
d.Set("client_id", nameParts[5]) | ||
return []*schema.ResourceData{d}, nil |
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,16 @@ | ||
resource "google_project" "project" { | ||
project_id = "tf-test%{random_suffix}" | ||
name = "tf-test%{random_suffix}" | ||
org_id = "<%= ctx[:test_env_vars]['org_id'] %>" | ||
} | ||
|
||
resource "google_project_service" "project_service" { | ||
project = google_project.project.project_id | ||
service = "iap.googleapis.com" | ||
} | ||
|
||
resource "google_iap_brand" "project_brand" { | ||
support_email = "support@<%= ctx[:test_env_vars]['org_domain'] %>" | ||
application_title = "Cloud IAP protected Application" | ||
project = google_project_service.project_service.project | ||
} |
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,21 @@ | ||
resource "google_project" "project" { | ||
project_id = "tf-test%{random_suffix}" | ||
name = "tf-test%{random_suffix}" | ||
org_id = "<%= ctx[:test_env_vars]['org_id'] %>" | ||
} | ||
|
||
resource "google_project_service" "project_service" { | ||
project = google_project.project.project_id | ||
service = "iap.googleapis.com" | ||
} | ||
|
||
resource "google_iap_brand" "project_brand" { | ||
support_email = "support@<%= ctx[:test_env_vars]['org_domain'] %>" | ||
application_title = "Cloud IAP protected Application" | ||
project = google_project_service.project_service.project | ||
} | ||
|
||
resource "google_iap_client" "project_client" { | ||
display_name = "Test Client" | ||
brand = google_iap_brand.project_brand.name | ||
} |
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,5 @@ | ||
brand := d.Get("brand") | ||
clientId := flattenIapClientClientId(res["name"], d, config) | ||
|
||
d.Set("client_id", clientId) | ||
d.SetId(fmt.Sprintf("%s/identityAwareProxyClients/%s", brand, clientId)) |
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,55 @@ | ||
package google | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccIapBrand_iapBrandExample(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"org_id": getTestOrgFromEnv(t), | ||
"org_domain": getTestOrgDomainFromEnv(t), | ||
"random_suffix": acctest.RandString(10), | ||
} | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccIapBrand_iapBrandExample(context), | ||
}, | ||
{ | ||
ResourceName: "google_iap_brand.project_brand", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"project"}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccIapBrand_iapBrandExample(context map[string]interface{}) string { | ||
return Nprintf(` | ||
resource "google_project" "project" { | ||
project_id = "tf-test%{random_suffix}" | ||
name = "tf-test%{random_suffix}" | ||
org_id = "%{org_id}" | ||
} | ||
resource "google_project_service" "project_service" { | ||
project = google_project.project.project_id | ||
service = "iap.googleapis.com" | ||
} | ||
resource "google_iap_brand" "project_brand" { | ||
support_email = "support@%{org_domain}" | ||
application_title = "Cloud IAP protected Application" | ||
project = google_project_service.project_service.project | ||
} | ||
`, context) | ||
} |
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