-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Access Context Manager product, AccessPolicy resource (…
…#96) <!-- This change is generated by MagicModules. --> /cc @rileykarson
- Loading branch information
1 parent
f068263
commit f705d93
Showing
7 changed files
with
586 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"google.golang.org/api/accesscontextmanager/v1beta" | ||
) | ||
|
||
type AccessContextManagerOperationWaiter struct { | ||
Service *accesscontextmanager.OperationsService | ||
Op *accesscontextmanager.Operation | ||
} | ||
|
||
func (w *AccessContextManagerOperationWaiter) RefreshFunc() resource.StateRefreshFunc { | ||
return func() (interface{}, string, error) { | ||
op, err := w.Service.Get(w.Op.Name).Do() | ||
|
||
if err != nil { | ||
return nil, "", err | ||
} | ||
|
||
log.Printf("[DEBUG] Got %v while polling for operation %s's 'done' status", op.Done, w.Op.Name) | ||
|
||
return op, fmt.Sprint(op.Done), nil | ||
} | ||
} | ||
|
||
func (w *AccessContextManagerOperationWaiter) Conf() *resource.StateChangeConf { | ||
return &resource.StateChangeConf{ | ||
Pending: []string{"false"}, | ||
Target: []string{"true"}, | ||
Refresh: w.RefreshFunc(), | ||
} | ||
} | ||
|
||
func accessContextManagerOperationWait(service *accesscontextmanager.Service, op *accesscontextmanager.Operation, activity string) error { | ||
return accessContextManagerOperationWaitTime(service, op, activity, 4) | ||
} | ||
|
||
func accessContextManagerOperationWaitTime(service *accesscontextmanager.Service, op *accesscontextmanager.Operation, activity string, timeoutMin int) error { | ||
if op.Done { | ||
if op.Error != nil { | ||
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message) | ||
} | ||
return nil | ||
} | ||
|
||
w := &AccessContextManagerOperationWaiter{ | ||
Service: service.Operations, | ||
Op: op, | ||
} | ||
|
||
state := w.Conf() | ||
state.Delay = 10 * time.Second | ||
state.Timeout = time.Duration(timeoutMin) * time.Minute | ||
state.MinTimeout = 2 * time.Second | ||
opRaw, err := state.WaitForState() | ||
if err != nil { | ||
return fmt.Errorf("Error waiting for %s: %s", activity, err) | ||
} | ||
|
||
op = opRaw.(*accesscontextmanager.Operation) | ||
if op.Error != nil { | ||
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message) | ||
} | ||
|
||
return 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
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 @@ | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// This file is automatically generated by Magic Modules and manual | ||
// changes will be clobbered when the file is regenerated. | ||
// | ||
// Please read more about how to change this file in | ||
// .github/CONTRIBUTING.md. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
|
||
package google | ||
|
||
import "github.com/hashicorp/terraform/helper/schema" | ||
|
||
var GeneratedAccessContextManagerResourcesMap = map[string]*schema.Resource{ | ||
"google_access_context_manager_access_policy": resourceAccessContextManagerAccessPolicy(), | ||
} |
71 changes: 71 additions & 0 deletions
71
google-beta/resource_access_context_manager_access_policy_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,71 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
// We can only have a single test as long as we are using a single organization | ||
func TestAccAccessContextManagerAccessPolicy_basic(t *testing.T) { | ||
t.Parallel() | ||
|
||
org := getTestOrgFromEnv(t) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAccessContextManagerAccessPolicyDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAccessContextManagerAccessPolicy_basic(org, "my policy"), | ||
}, | ||
{ | ||
ResourceName: "google_access_context_manager_access_policy.test-access", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
{ | ||
Config: testAccAccessContextManagerAccessPolicy_basic(org, "my new policy"), | ||
}, | ||
{ | ||
ResourceName: "google_access_context_manager_access_policy.test-access", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAccessContextManagerAccessPolicyDestroy(s *terraform.State) error { | ||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "google_access_context_manager_access_policy" { | ||
continue | ||
} | ||
|
||
config := testAccProvider.Meta().(*Config) | ||
|
||
url, err := replaceVarsForTest(rs, "https://accesscontextmanager.googleapis.com/v1beta/accessPolicies/{{name}}") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = sendRequest(config, "GET", url, nil) | ||
if err == nil { | ||
return fmt.Errorf("AccessPolicy still exists at %s", url) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func testAccAccessContextManagerAccessPolicy_basic(org, title string) string { | ||
return fmt.Sprintf(` | ||
resource "google_access_context_manager_access_policy" "test-access" { | ||
parent = "organizations/%s" | ||
title = "%s" | ||
} | ||
`, org, title) | ||
} |
Oops, something went wrong.