-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
19 changed files
with
670 additions
and
506 deletions.
There are no files selected for viewing
Submodule terraform
updated
from 0cd8e8 to db5eba
Submodule terraform-beta
updated
from 8b10f9 to 27b6ba
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 |
---|---|---|
|
@@ -423,5 +423,7 @@ def effective_copyright_year(out_file) | |
end | ||
Time.now.year | ||
end | ||
|
||
def generate_iam_policy(data) end | ||
end | ||
end |
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
182 changes: 182 additions & 0 deletions
182
templates/terraform/examples/base_configs/iam_test_file.go.erb
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,182 @@ | ||
<%= lines(autogen_notice :go) -%> | ||
|
||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
<%# Since most resources define a "basic" config as their first example, we can reuse that config to create a resource to test IAM resources with. -%> | ||
<% example = object.examples.reject(&:skip_test) | ||
.reject { |e| @api.version_obj_or_closest(version) < @api.version_obj_or_closest(e.min_version) } | ||
.first -%> | ||
<% resource_name = product_ns + object.name -%> | ||
<% | ||
individual_url = object.self_link_url | ||
params = individual_url.scan(/({{)(\w+)(}})/).map { |arr| arr[1] } | ||
-%> | ||
<% | ||
if @config.legacy_name.nil? | ||
terraform_name = "google_" + (product_ns + object.name).underscore | ||
else | ||
terraform_name = "google_" + @config.legacy_name + '_' + object.name.underscore | ||
end | ||
-%> | ||
<% import_url = individual_url.gsub(/({{)(\w+)(}})/, '%s').gsub(object.__product.base_url, '') -%> | ||
<% import_str = Array.new(params.length, '%s').join('/') -%> | ||
<% import_qualifiers = [] -%> | ||
<% params.each do |param| -%> | ||
<% if param == 'project' -%> | ||
<% import_qualifiers.push('getTestProjectFromEnv()') -%> | ||
<% elsif param == 'zone' -%> | ||
<% import_qualifiers.push('getTestZoneFromEnv(t)') -%> | ||
<% elsif param == 'region' || param == 'location' -%> | ||
<% import_qualifiers.push('getTestRegionFromEnv(t)') -%> | ||
<% end -%> | ||
<% end -%> | ||
func TestAcc<%= resource_name -%>IamBindingGenerated(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"random_suffix": acctest.RandString(10), | ||
"role": "roles/editor", | ||
} | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheck<%= resource_name -%>Destroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAcc<%= resource_name -%>IamBinding_basicGenerated(context), | ||
}, | ||
{ | ||
ResourceName: "<%= terraform_name -%>_iam_binding.foo", | ||
ImportStateId: fmt.Sprintf("<%= import_url -%> roles/editor", <%= import_qualifiers.join(', ') -%>, <%= example.primary_resource_name -%>), | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
{ | ||
// Test Iam Binding update | ||
Config: testAcc<%= resource_name -%>IamBinding_updateGenerated(context), | ||
}, | ||
{ | ||
ResourceName: "<%= terraform_name -%>_iam_binding.foo", | ||
ImportStateId: fmt.Sprintf("<%= import_url -%> roles/editor", <%= import_qualifiers.join(', ') -%>, <%= example.primary_resource_name -%>), | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAcc<%= resource_name -%>IamMemberGenerated(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"random_suffix": acctest.RandString(10), | ||
"role": "roles/editor", | ||
} | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheck<%= resource_name -%>Destroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
// Test Iam Member creation (no update for member, no need to test) | ||
Config: testAcc<%= resource_name -%>IamMember_basicGenerated(context), | ||
}, | ||
{ | ||
ResourceName: "<%= terraform_name -%>_iam_member.foo", | ||
ImportStateId: fmt.Sprintf("<%= import_url -%> roles/editor user:[email protected]", <%= import_qualifiers.join(', ') -%>, <%= example.primary_resource_name -%>), | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAcc<%= resource_name -%>IamPolicyGenerated(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"random_suffix": acctest.RandString(10), | ||
"role": "roles/editor", | ||
} | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheck<%= resource_name -%>Destroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAcc<%= resource_name -%>IamPolicy_basicGenerated(context), | ||
}, | ||
{ | ||
ResourceName: "<%= terraform_name -%>_iam_policy.foo", | ||
ImportStateId: fmt.Sprintf("<%= import_url -%>", <%= import_qualifiers.join(', ') -%>, <%= example.primary_resource_name -%>), | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAcc<%= resource_name -%>IamMember_basicGenerated(context map[string]interface{}) string { | ||
return Nprintf(` | ||
<%= example.config_test_body -%> | ||
|
||
resource "<%= terraform_name -%>_iam_member" "foo" { | ||
<%= object.name.underscore -%> = "${<%= terraform_name -%>.<%= example.primary_resource_id -%>.id}" | ||
role = "%{role}" | ||
member = "user:[email protected]" | ||
} | ||
`, context) | ||
} | ||
|
||
func testAcc<%= resource_name -%>IamPolicy_basicGenerated(context map[string]interface{}) string { | ||
return Nprintf(` | ||
<%= example.config_test_body -%> | ||
|
||
data "google_iam_policy" "foo" { | ||
binding { | ||
role = "%{role}" | ||
members = ["user:[email protected]"] | ||
} | ||
} | ||
|
||
resource "<%= terraform_name -%>_iam_policy" "foo" { | ||
<%= object.name.underscore -%> = "${<%= terraform_name -%>.<%= example.primary_resource_id -%>.id}" | ||
policy_data = "${data.google_iam_policy.foo.policy_data}" | ||
} | ||
`, context) | ||
} | ||
|
||
func testAcc<%= resource_name -%>IamBinding_basicGenerated(context map[string]interface{}) string { | ||
return Nprintf(` | ||
<%= example.config_test_body -%> | ||
|
||
resource "<%= terraform_name -%>_iam_binding" "foo" { | ||
<%= object.name.underscore -%> = "${<%= terraform_name -%>.<%= example.primary_resource_id -%>.id}" | ||
role = "%{role}" | ||
members = ["user:[email protected]"] | ||
} | ||
`, context) | ||
} | ||
|
||
func testAcc<%= resource_name -%>IamBinding_updateGenerated(context map[string]interface{}) string { | ||
return Nprintf(` | ||
<%= example.config_test_body -%> | ||
|
||
resource "<%= terraform_name -%>_iam_binding" "foo" { | ||
<%= object.name.underscore -%> = "${<%= terraform_name -%>.<%= example.primary_resource_id -%>.id}" | ||
role = "%{role}" | ||
members = ["user:[email protected]", "user:[email protected]"] | ||
} | ||
`, context) | ||
} |
Oops, something went wrong.