Skip to content

Commit 3d0f1ce

Browse files
committed
resolve preconditino errors
1 parent dbe4395 commit 3d0f1ce

File tree

2 files changed

+16
-39
lines changed

2 files changed

+16
-39
lines changed

mmv1/third_party/terraform/services/resourcemanager/ephemeral_google_service_account_key.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,15 @@ func (p *googleEphemeralServiceAccountKey) Close(ctx context.Context, req epheme
276276
}
277277
var data ServiceAccountKeyPrivateData
278278
json.Unmarshal(dataBytes, &data)
279-
log.Printf("[DEBUG] Deleting Service Account Key %q\n", data.Name)
280-
_, err := p.providerConfig.NewIamClient(p.providerConfig.UserAgent).Projects.ServiceAccounts.Keys.Delete(data.Name).Do()
281-
if err != nil {
282-
resp.Diagnostics.AddError(
283-
"Error deleting Service Account Key",
284-
fmt.Sprintf("Error deleting Service Account Key %q: %s", data.Name, err.Error()),
285-
)
286-
return
279+
if data.Name != "" {
280+
log.Printf("[DEBUG] Deleting Service Account Key %q\n", data.Name)
281+
_, err := p.providerConfig.NewIamClient(p.providerConfig.UserAgent).Projects.ServiceAccounts.Keys.Delete(data.Name).Do()
282+
if err != nil {
283+
resp.Diagnostics.AddError(
284+
"Error deleting Service Account Key",
285+
fmt.Sprintf("Error deleting Service Account Key %q: %s", data.Name, err.Error()),
286+
)
287+
return
288+
}
287289
}
288290
}

mmv1/third_party/terraform/services/resourcemanager/ephemeral_google_service_account_key_test.go

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ func TestAccEphemeralServiceAccountKey_create(t *testing.T) {
1818
resource.Test(t, resource.TestCase{
1919
PreCheck: func() { acctest.AccTestPreCheck(t) },
2020
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
21-
ExternalProviders: map[string]resource.ExternalProvider{
22-
"time": {},
23-
},
2421
Steps: []resource.TestStep{
2522
{
2623
Config: testAccEphemeralServiceAccountKey_create_setup(accountID, displayName),
@@ -39,10 +36,6 @@ resource "google_service_account" "service_account" {
3936
display_name = "%s"
4037
}
4138
42-
resource "time_sleep" "wait_10_seconds" {
43-
create_duration = "10s"
44-
depends_on = [google_service_account.service_account]
45-
}
4639
`, accountID, displayName)
4740
}
4841

@@ -53,11 +46,6 @@ resource "google_service_account" "service_account" {
5346
display_name = "%s"
5447
}
5548
56-
resource "time_sleep" "wait_10_seconds" {
57-
create_duration = "10s"
58-
depends_on = [google_service_account.service_account]
59-
}
60-
6149
ephemeral "google_service_account_key" "key" {
6250
service_account_id = google_service_account.service_account.email
6351
public_key_type = "TYPE_X509_PEM_FILE"
@@ -68,8 +56,8 @@ ephemeral "google_service_account_key" "key" {
6856
func TestAccEphemeralServiceAccountKey_upload(t *testing.T) {
6957
t.Parallel()
7058

71-
accountID := "a" + acctest.RandString(t, 10)
72-
displayName := "Terraform Test"
59+
accountID := "b" + acctest.RandString(t, 10)
60+
displayName := "Terraform Test Two"
7361
resource.Test(t, resource.TestCase{
7462
PreCheck: func() { acctest.AccTestPreCheck(t) },
7563
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
@@ -93,8 +81,8 @@ resource "google_service_account" "service_account" {
9381
account_id = "%s"
9482
display_name = "%s"
9583
}
96-
resource "time_sleep" "wait_10_seconds" {
97-
create_duration = "10s"
84+
resource "time_sleep" "wait_30_seconds" {
85+
create_duration = "30s"
9886
depends_on = [google_service_account.service_account]
9987
}
10088
`, accountID, displayName)
@@ -106,8 +94,8 @@ resource "google_service_account" "service_account" {
10694
account_id = "%s"
10795
display_name = "%s"
10896
}
109-
resource "time_sleep" "wait_10_seconds" {
110-
create_duration = "10s"
97+
resource "time_sleep" "wait_30_seconds" {
98+
create_duration = "30s"
11199
depends_on = [google_service_account.service_account]
112100
}
113101
@@ -126,9 +114,6 @@ func TestAccEphemeralServiceAccountKey_fetch(t *testing.T) {
126114
resource.Test(t, resource.TestCase{
127115
PreCheck: func() { acctest.AccTestPreCheck(t) },
128116
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
129-
ExternalProviders: map[string]resource.ExternalProvider{
130-
"time": {},
131-
},
132117
Steps: []resource.TestStep{
133118
{
134119
Config: testAccEphemeralServiceAccountKey_fetch_setup(targetServiceAccountEmail),
@@ -146,11 +131,6 @@ resource "google_service_account_key" "acceptance" {
146131
service_account_id = "%s"
147132
public_key_type = "TYPE_X509_PEM_FILE"
148133
}
149-
150-
resource "time_sleep" "wait_10_seconds" {
151-
create_duration = "10s"
152-
depends_on = [google_service_account_key.acceptance]
153-
}
154134
`, accountID)
155135
}
156136

@@ -161,11 +141,6 @@ resource "google_service_account_key" "acceptance" {
161141
public_key_type = "TYPE_X509_PEM_FILE"
162142
}
163143
164-
resource "time_sleep" "wait_10_seconds" {
165-
create_duration = "10s"
166-
depends_on = [google_service_account_key.acceptance]
167-
}
168-
169144
ephemeral "google_service_account_key" "key" {
170145
name = google_service_account_key.acceptance.name
171146
fetch_key = true

0 commit comments

Comments
 (0)