-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove subnetwork iam from GA provider
- Loading branch information
1 parent
bd86e7a
commit e285514
Showing
2 changed files
with
1 addition
and
248 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
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 |
---|---|---|
@@ -1,247 +1,3 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccComputeSubnetworkIamBinding(t *testing.T) { | ||
t.Parallel() | ||
|
||
account := acctest.RandomWithPrefix("tf-test") | ||
role := "roles/compute.networkUser" | ||
region := getTestRegionFromEnv() | ||
subnetwork := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccComputeSubnetworkIamBinding_basic(account, region, subnetwork, role), | ||
}, | ||
resource.TestStep{ | ||
ResourceName: "google_compute_subnetwork_iam_binding.foo", | ||
ImportStateId: fmt.Sprintf("%s/%s %s", region, subnetwork, role), | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
{ | ||
// Test Iam Binding update | ||
Config: testAccComputeSubnetworkIamBinding_update(account, region, subnetwork, role), | ||
}, | ||
resource.TestStep{ | ||
ResourceName: "google_compute_subnetwork_iam_binding.foo", | ||
ImportStateId: fmt.Sprintf("%s/%s %s", region, subnetwork, role), | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccComputeSubnetworkIamMember(t *testing.T) { | ||
t.Parallel() | ||
|
||
project := getTestProjectFromEnv() | ||
account := acctest.RandomWithPrefix("tf-test") | ||
role := "roles/compute.networkUser" | ||
region := getTestRegionFromEnv() | ||
subnetwork := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
// Test Iam Member creation (no update for member, no need to test) | ||
Config: testAccComputeSubnetworkIamMember_basic(account, region, subnetwork, role), | ||
}, | ||
resource.TestStep{ | ||
ResourceName: "google_compute_subnetwork_iam_member.foo", | ||
ImportStateId: fmt.Sprintf("%s/%s %s serviceAccount:%s@%s.iam.gserviceaccount.com", region, subnetwork, role, account, project), | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccComputeSubnetworkIamPolicy(t *testing.T) { | ||
t.Parallel() | ||
|
||
project := getTestProjectFromEnv() | ||
account := acctest.RandomWithPrefix("tf-test") | ||
role := "roles/compute.networkUser" | ||
region := getTestRegionFromEnv() | ||
subnetwork := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccComputeSubnetworkIamPolicy_basic(account, region, subnetwork, role), | ||
}, | ||
// Test a few import formats | ||
resource.TestStep{ | ||
ResourceName: "google_compute_subnetwork_iam_policy.foo", | ||
ImportStateId: fmt.Sprintf("projects/%s/regions/%s/subnetworks/%s", project, region, subnetwork), | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
resource.TestStep{ | ||
ResourceName: "google_compute_subnetwork_iam_policy.foo", | ||
ImportStateId: fmt.Sprintf("%s/%s/%s", project, region, subnetwork), | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
resource.TestStep{ | ||
ResourceName: "google_compute_subnetwork_iam_policy.foo", | ||
ImportStateId: fmt.Sprintf("%s/%s", region, subnetwork), | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
resource.TestStep{ | ||
ResourceName: "google_compute_subnetwork_iam_policy.foo", | ||
ImportStateId: fmt.Sprintf("%s", subnetwork), | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccComputeSubnetworkIamBinding_basic(account, region, subnetworkName, roleId string) string { | ||
return fmt.Sprintf(` | ||
resource "google_service_account" "test_account" { | ||
account_id = "%s" | ||
display_name = "Iam Testing Account" | ||
} | ||
resource "google_compute_network" "network" { | ||
name = "%s" | ||
auto_create_subnetworks = false | ||
} | ||
resource "google_compute_subnetwork" "subnetwork" { | ||
name = "%s" | ||
region = "%s" | ||
ip_cidr_range = "10.1.0.0/16" | ||
network = "${google_compute_network.network.name}" | ||
} | ||
resource "google_compute_subnetwork_iam_binding" "foo" { | ||
project = "${google_compute_subnetwork.subnetwork.project}" | ||
region = "${google_compute_subnetwork.subnetwork.region}" | ||
subnetwork = "${google_compute_subnetwork.subnetwork.name}" | ||
role = "%s" | ||
members = ["serviceAccount:${google_service_account.test_account.email}"] | ||
} | ||
`, account, subnetworkName, subnetworkName, region, roleId) | ||
} | ||
|
||
func testAccComputeSubnetworkIamBinding_update(account, region, subnetworkName, roleId string) string { | ||
return fmt.Sprintf(` | ||
resource "google_service_account" "test_account" { | ||
account_id = "%s" | ||
display_name = "Iam Testing Account" | ||
} | ||
resource "google_service_account" "test_account_2" { | ||
account_id = "%s-2" | ||
display_name = "Iam Testing Account" | ||
} | ||
resource "google_compute_network" "network" { | ||
name = "%s" | ||
auto_create_subnetworks = false | ||
} | ||
resource "google_compute_subnetwork" "subnetwork" { | ||
name = "%s" | ||
region = "%s" | ||
ip_cidr_range = "10.1.0.0/16" | ||
network = "${google_compute_network.network.name}" | ||
} | ||
resource "google_compute_subnetwork_iam_binding" "foo" { | ||
project = "${google_compute_subnetwork.subnetwork.project}" | ||
region = "${google_compute_subnetwork.subnetwork.region}" | ||
subnetwork = "${google_compute_subnetwork.subnetwork.name}" | ||
role = "%s" | ||
members = [ | ||
"serviceAccount:${google_service_account.test_account.email}", | ||
"serviceAccount:${google_service_account.test_account_2.email}" | ||
] | ||
} | ||
`, account, account, subnetworkName, subnetworkName, region, roleId) | ||
} | ||
|
||
func testAccComputeSubnetworkIamMember_basic(account, region, subnetworkName, roleId string) string { | ||
return fmt.Sprintf(` | ||
resource "google_service_account" "test_account" { | ||
account_id = "%s" | ||
display_name = "Iam Testing Account" | ||
} | ||
resource "google_compute_network" "network" { | ||
name = "%s" | ||
auto_create_subnetworks = false | ||
} | ||
resource "google_compute_subnetwork" "subnetwork" { | ||
name = "%s" | ||
region = "%s" | ||
ip_cidr_range = "10.1.0.0/16" | ||
network = "${google_compute_network.network.name}" | ||
} | ||
resource "google_compute_subnetwork_iam_member" "foo" { | ||
project = "${google_compute_subnetwork.subnetwork.project}" | ||
region = "${google_compute_subnetwork.subnetwork.region}" | ||
subnetwork = "${google_compute_subnetwork.subnetwork.name}" | ||
role = "%s" | ||
member = "serviceAccount:${google_service_account.test_account.email}" | ||
} | ||
`, account, subnetworkName, subnetworkName, region, roleId) | ||
} | ||
|
||
func testAccComputeSubnetworkIamPolicy_basic(account, region, subnetworkName, roleId string) string { | ||
return fmt.Sprintf(` | ||
resource "google_service_account" "test_account" { | ||
account_id = "%s" | ||
display_name = "Iam Testing Account" | ||
} | ||
resource "google_compute_network" "network" { | ||
name = "%s" | ||
auto_create_subnetworks = false | ||
} | ||
resource "google_compute_subnetwork" "subnetwork" { | ||
name = "%s" | ||
region = "%s" | ||
ip_cidr_range = "10.1.0.0/16" | ||
network = "${google_compute_network.network.name}" | ||
} | ||
data "google_iam_policy" "foo" { | ||
binding { | ||
role = "%s" | ||
members = ["serviceAccount:${google_service_account.test_account.email}"] | ||
} | ||
} | ||
resource "google_compute_subnetwork_iam_policy" "foo" { | ||
project = "${google_compute_subnetwork.subnetwork.project}" | ||
region = "${google_compute_subnetwork.subnetwork.region}" | ||
subnetwork = "${google_compute_subnetwork.subnetwork.name}" | ||
policy_data = "${data.google_iam_policy.foo.policy_data}" | ||
} | ||
`, account, subnetworkName, subnetworkName, region, roleId) | ||
} | ||
// Magic Modules doesn't let us remove files - blank out beta-only common-compile files for now. |