Skip to content

Commit e1df955

Browse files
authored
Merge branch 'main' into fix/enterprise-org-saml-create-taint
2 parents 6775995 + e3a3c6c commit e1df955

7 files changed

Lines changed: 109 additions & 15 deletions

github/data_source_github_repository.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ func dataSourceGithubRepository() *schema.Resource {
6161
Computed: true,
6262
},
6363
"has_downloads": {
64-
Type: schema.TypeBool,
65-
Computed: true,
64+
Type: schema.TypeBool,
65+
Computed: true,
66+
Deprecated: "This attribute is no longer in use, but it hasn't been removed yet. It will be removed in a future version. See https://github.com/orgs/community/discussions/102145#discussioncomment-8351756",
6667
},
6768
"has_wiki": {
6869
Type: schema.TypeBool,

github/resource_github_actions_organization_secret_test.go

Lines changed: 100 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import (
66
"strings"
77
"testing"
88

9+
"github.com/google/go-github/v81/github"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
911
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1012
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
13+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1114
)
1215

1316
func TestAccGithubActionsOrganizationSecret(t *testing.T) {
@@ -17,16 +20,16 @@ func TestAccGithubActionsOrganizationSecret(t *testing.T) {
1720

1821
config := fmt.Sprintf(`
1922
resource "github_actions_organization_secret" "plaintext_secret" {
20-
secret_name = "test_plaintext_secret"
21-
plaintext_value = "%s"
22-
visibility = "private"
23+
secret_name = "test_plaintext_secret"
24+
plaintext_value = "%s"
25+
visibility = "private"
2326
}
2427
2528
resource "github_actions_organization_secret" "encrypted_secret" {
26-
secret_name = "test_encrypted_secret"
27-
encrypted_value = "%s"
28-
visibility = "private"
29-
destroy_on_drift = false
29+
secret_name = "test_encrypted_secret"
30+
encrypted_value = "%s"
31+
visibility = "private"
32+
destroy_on_drift = false
3033
}
3134
`, secretValue, secretValue)
3235

@@ -143,8 +146,79 @@ func TestAccGithubActionsOrganizationSecret(t *testing.T) {
143146
},
144147
})
145148
})
149+
}
150+
151+
func TestAccGithubActionsOrganizationSecret_DestroyOnDrift(t *testing.T) {
152+
t.Run("destroyOnDrift false", func(t *testing.T) {
153+
destroyOnDrift := false
154+
t.Run("should ignore drift when ignore_changes lifecycle is configured", func(t *testing.T) {
155+
// Verify https://github.com/integrations/terraform-provider-github/issues/2614
156+
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
157+
config := fmt.Sprintf(`
158+
resource "github_actions_organization_secret" "test_secret" {
159+
secret_name = "test_secret_%s"
160+
plaintext_value = "test_value"
161+
visibility = "private"
162+
163+
destroy_on_drift = %t
164+
lifecycle {
165+
ignore_changes = [plaintext_value]
166+
}
167+
}
168+
`, randomID, destroyOnDrift)
169+
170+
resource.Test(t, resource.TestCase{
171+
PreCheck: func() { skipUnlessHasOrgs(t) },
172+
Providers: testAccProviders,
173+
Steps: []resource.TestStep{
174+
{
175+
Config: config,
176+
},
177+
{
178+
Config: config,
179+
Check: resource.ComposeTestCheckFunc(
180+
func(s *terraform.State) error {
181+
rs, ok := s.RootModule().Resources["github_actions_organization_secret.test_secret"]
182+
if !ok {
183+
t.Errorf("not found: github_actions_organization_secret.test_secret")
184+
}
185+
// Now that the secret is created, update it to trigger a drift.
186+
client := testAccProvider.Meta().(*Owner).v3client
187+
owner := testAccProvider.Meta().(*Owner).name
188+
ctx := t.Context()
189+
190+
keyId, publicKey, err := getOrganizationPublicKeyDetails(owner, testAccProvider.Meta().(*Owner))
191+
if err != nil {
192+
t.Errorf("Failed to get organization public key details: %v", err)
193+
}
146194

147-
// Unit tests for drift detection behavior
195+
encryptedSecret, err := createEncryptedSecret(rs.Primary, "foo", keyId, publicKey)
196+
if err != nil {
197+
t.Errorf("Failed to create encrypted secret: %v", err)
198+
}
199+
_, err = client.Actions.CreateOrUpdateOrgSecret(ctx, owner, encryptedSecret)
200+
if err != nil {
201+
t.Errorf("Failed to create or update organization secret: %v", err)
202+
}
203+
return err
204+
},
205+
),
206+
},
207+
{
208+
Config: config,
209+
PlanOnly: true,
210+
ExpectNonEmptyPlan: false,
211+
},
212+
},
213+
})
214+
})
215+
})
216+
// t.Run("destroyOnDrift true", func(t *testing.T) {
217+
// destroyOnDrift := true
218+
// })
219+
}
220+
221+
func TestGithubActionsOrganizationSecret_DestroyOnDrift(t *testing.T) {
148222
t.Run("destroyOnDrift false clears sensitive values instead of recreating", func(t *testing.T) {
149223
originalTimestamp := "2023-01-01T00:00:00Z"
150224
newTimestamp := "2023-01-02T00:00:00Z"
@@ -248,3 +322,21 @@ func TestAccGithubActionsOrganizationSecret(t *testing.T) {
248322
}
249323
})
250324
}
325+
326+
func createEncryptedSecret(is *terraform.InstanceState, plaintextValue, keyId, publicKey string) (*github.EncryptedSecret, error) {
327+
secretName := is.Attributes["secret_name"]
328+
visibility := is.Attributes["visibility"]
329+
330+
encryptedBytes, err := encryptPlaintext(plaintextValue, publicKey)
331+
if err != nil {
332+
return nil, err
333+
}
334+
encryptedValue := base64.StdEncoding.EncodeToString(encryptedBytes)
335+
336+
return &github.EncryptedSecret{
337+
Name: secretName,
338+
KeyID: keyId,
339+
Visibility: visibility,
340+
EncryptedValue: encryptedValue,
341+
}, nil
342+
}

github/resource_github_organization_ruleset_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1010
)
1111

12-
func TestGithubOrganizationRulesets(t *testing.T) {
12+
func TestAccGithubOrganizationRuleset(t *testing.T) {
1313
t.Run("create_branch_ruleset", func(t *testing.T) {
1414
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
1515

github/resource_github_repository.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ func resourceGithubRepository() *schema.Resource {
211211
Type: schema.TypeBool,
212212
Optional: true,
213213
Description: "Set to 'true' to enable the (deprecated) downloads features on the repository.",
214+
Deprecated: "This attribute is no longer in use, but it hasn't been removed yet. It will be removed in a future version. See https://github.com/orgs/community/discussions/102145#discussioncomment-8351756",
214215
},
215216
"has_wiki": {
216217
Type: schema.TypeBool,

github/resource_github_repository_ruleset_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1313
)
1414

15-
func TestGithubRepositoryRulesets(t *testing.T) {
15+
func TestAccGithubRepositoryRuleset(t *testing.T) {
1616
t.Run("create_branch_ruleset", func(t *testing.T) {
1717
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
1818

@@ -501,7 +501,7 @@ resource "github_repository_ruleset" "test" {
501501
})
502502
}
503503

504-
func TestGithubRepositoryRulesetArchived(t *testing.T) {
504+
func TestAccGithubRepositoryRulesetArchived(t *testing.T) {
505505
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
506506

507507
t.Run("skips update and delete on archived repository", func(t *testing.T) {

website/docs/d/repository.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The following arguments are supported:
6767

6868
* `merge_commit_message` - The default value for a merge commit message.
6969

70-
* `has_downloads` - Whether the repository has Downloads feature enabled.
70+
* `has_downloads` - (**DEPRECATED**) Whether the repository has Downloads feature enabled. This attribute is no longer in use, but it hasn't been removed yet. It will be removed in a future version. See [this discussion](https://github.com/orgs/community/discussions/102145#discussioncomment-8351756).
7171

7272
* `default_branch` - The name of the default branch of the repository.
7373

website/docs/r/repository.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ The following arguments are supported:
114114

115115
* `web_commit_signoff_required` - (Optional) Require contributors to sign off on web-based commits. See more [here](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/managing-repository-settings/managing-the-commit-signoff-policy-for-your-repository). Defaults to `false`.
116116

117-
* `has_downloads` - (Optional) Set to `true` to enable the (deprecated) downloads features on the repository.
117+
* `has_downloads` - (**DEPRECATED**) (Optional) Set to `true` to enable the (deprecated) downloads features on the repository. This attribute is no longer in use, but it hasn't been removed yet. It will be removed in a future version. See [this discussion](https://github.com/orgs/community/discussions/102145#discussioncomment-8351756).
118118

119119
* `auto_init` - (Optional) Set to `true` to produce an initial commit in the repository.
120120

0 commit comments

Comments
 (0)