-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consistent IAM resource imports. #835
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
13209a1
Initial commit for IAM imports.
nat-henderson d7baa90
Add crypto key, organization, and key ring.
nat-henderson 8dde04a
Add tests for all the IAM imports.
nat-henderson 0b79663
Import documentation for IAM resources.
nat-henderson 8f26fb6
Move IAM imports to their own files.
nat-henderson 8835209
Fix imports.
nat-henderson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,75 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccKmsCryptoKeyIamMember_importBasic(t *testing.T) { | ||
t.Parallel() | ||
|
||
orgId := getTestOrgFromEnv(t) | ||
projectId := acctest.RandomWithPrefix("tf-test") | ||
billingAccount := getTestBillingAccountFromEnv(t) | ||
account := acctest.RandomWithPrefix("tf-test") | ||
roleId := "roles/cloudkms.cryptoKeyEncrypter" | ||
keyRingName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) | ||
keyRingId := &kmsKeyRingId{ | ||
Project: projectId, | ||
Location: DEFAULT_KMS_TEST_LOCATION, | ||
Name: keyRingName, | ||
} | ||
cryptoKeyName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccGoogleKmsCryptoKeyIamMember_basic(projectId, orgId, billingAccount, account, keyRingName, cryptoKeyName, roleId), | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: "google_kms_crypto_key_iam_member.foo", | ||
ImportStateId: fmt.Sprintf("%s/%s %s serviceAccount:%s@%s.iam.gserviceaccount.com", keyRingId.terraformId(), cryptoKeyName, roleId, account, projectId), | ||
ImportState: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccKmsCryptoKeyIamBinding_importBasic(t *testing.T) { | ||
t.Parallel() | ||
|
||
orgId := getTestOrgFromEnv(t) | ||
projectId := acctest.RandomWithPrefix("tf-test") | ||
billingAccount := getTestBillingAccountFromEnv(t) | ||
account := acctest.RandomWithPrefix("tf-test") | ||
roleId := "roles/cloudkms.cryptoKeyEncrypter" | ||
keyRingName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) | ||
keyRingId := &kmsKeyRingId{ | ||
Project: projectId, | ||
Location: DEFAULT_KMS_TEST_LOCATION, | ||
Name: keyRingName, | ||
} | ||
cryptoKeyName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccGoogleKmsCryptoKeyIamBinding_basic(projectId, orgId, billingAccount, account, keyRingName, cryptoKeyName, roleId), | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: "google_kms_crypto_key_iam_binding.foo", | ||
ImportStateId: fmt.Sprintf("%s/%s %s", keyRingId.terraformId(), cryptoKeyName, roleId), | ||
ImportState: true, | ||
}, | ||
}, | ||
}) | ||
} |
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,104 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccKmsKeyRingIamMember_importBasic(t *testing.T) { | ||
t.Parallel() | ||
|
||
orgId := getTestOrgFromEnv(t) | ||
projectId := acctest.RandomWithPrefix("tf-test") | ||
billingAccount := getTestBillingAccountFromEnv(t) | ||
account := acctest.RandomWithPrefix("tf-test") | ||
roleId := "roles/cloudkms.cryptoKeyEncrypter" | ||
keyRingName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) | ||
keyRingId := &kmsKeyRingId{ | ||
Project: projectId, | ||
Location: DEFAULT_KMS_TEST_LOCATION, | ||
Name: keyRingName, | ||
} | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccGoogleKmsKeyRingIamMember_basic(projectId, orgId, billingAccount, account, keyRingName, roleId), | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: "google_kms_key_ring_iam_member.foo", | ||
ImportStateId: fmt.Sprintf("%s %s serviceAccount:%s@%s.iam.gserviceaccount.com", keyRingId.terraformId(), roleId, account, projectId), | ||
ImportState: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccKmsKeyRingIamPolicy_importBasic(t *testing.T) { | ||
t.Parallel() | ||
|
||
orgId := getTestOrgFromEnv(t) | ||
projectId := acctest.RandomWithPrefix("tf-test") | ||
billingAccount := getTestBillingAccountFromEnv(t) | ||
account := acctest.RandomWithPrefix("tf-test") | ||
roleId := "roles/cloudkms.cryptoKeyEncrypter" | ||
keyRingName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) | ||
keyRingId := &kmsKeyRingId{ | ||
Project: projectId, | ||
Location: DEFAULT_KMS_TEST_LOCATION, | ||
Name: keyRingName, | ||
} | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccGoogleKmsKeyRingIamPolicy_basic(projectId, orgId, billingAccount, account, keyRingName, roleId), | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: "google_kms_key_ring_iam_policy.foo", | ||
ImportStateId: keyRingId.terraformId(), | ||
ImportState: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccKmsKeyRingIamBinding_importBasic(t *testing.T) { | ||
t.Parallel() | ||
|
||
orgId := getTestOrgFromEnv(t) | ||
projectId := acctest.RandomWithPrefix("tf-test") | ||
billingAccount := getTestBillingAccountFromEnv(t) | ||
account := acctest.RandomWithPrefix("tf-test") | ||
roleId := "roles/cloudkms.cryptoKeyEncrypter" | ||
keyRingName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) | ||
keyRingId := &kmsKeyRingId{ | ||
Project: projectId, | ||
Location: DEFAULT_KMS_TEST_LOCATION, | ||
Name: keyRingName, | ||
} | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccGoogleKmsKeyRingIamBinding_basic(projectId, orgId, billingAccount, account, keyRingName, roleId), | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: "google_kms_key_ring_iam_binding.foo", | ||
ImportStateId: fmt.Sprintf("%s %s", keyRingId.terraformId(), roleId), | ||
ImportState: true, | ||
}, | ||
}, | ||
}) | ||
} |
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,57 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccGoogleOrganizationIamMember_importBasic(t *testing.T) { | ||
t.Parallel() | ||
|
||
orgId := getTestOrgFromEnv(t) | ||
account := acctest.RandomWithPrefix("tf-test") | ||
projectId := getTestProjectFromEnv() | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccGoogleOrganizationIamMember_basic(account, orgId), | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: "google_organization_iam_member.foo", | ||
ImportStateId: fmt.Sprintf("%s roles/browser serviceAccount:%s@%s.iam.gserviceaccount.com", orgId, account, projectId), | ||
ImportState: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccGoogleOrganizationIamBinding_importBasic(t *testing.T) { | ||
t.Parallel() | ||
|
||
orgId := getTestOrgFromEnv(t) | ||
account := acctest.RandomWithPrefix("tf-test") | ||
roleId := "tfIamTest" + acctest.RandString(10) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccGoogleOrganizationIamBinding_basic(account, roleId, orgId), | ||
}, | ||
|
||
resource.TestStep{ | ||
ResourceName: "google_organization_iam_binding.foo", | ||
ImportStateId: fmt.Sprintf("%s organizations/%s/roles/%s", orgId, orgId, roleId), | ||
ImportState: true, | ||
}, | ||
}, | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider moving the
iamPolicyImport
,iamPolicyBinding
andiamPolicyMember
functions into their respectiveresource_iam_*
file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! Done.