diff --git a/github/data_source_github_collaborators.go b/github/data_source_github_collaborators.go index caa14d6e14..6f7f83dbc8 100644 --- a/github/data_source_github_collaborators.go +++ b/github/data_source_github_collaborators.go @@ -24,23 +24,23 @@ func dataSourceGithubCollaborators() *schema.Resource { }, "affiliation": { Type: schema.TypeString, - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{ + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{ "all", "direct", "outside", - }, false), "affiliation"), + }, false)), Optional: true, Default: "all", }, "permission": { Type: schema.TypeString, - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{ + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{ "pull", "triage", "push", "maintain", "admin", - }, false), "permission"), + }, false)), Optional: true, Default: "", }, diff --git a/github/data_source_github_organization_teams.go b/github/data_source_github_organization_teams.go index 3fc86ffc42..43d06ee1d5 100644 --- a/github/data_source_github_organization_teams.go +++ b/github/data_source_github_organization_teams.go @@ -29,7 +29,7 @@ func dataSourceGithubOrganizationTeams() *schema.Resource { Type: schema.TypeInt, Optional: true, Default: 100, - ValidateDiagFunc: toDiagFunc(validation.IntBetween(0, 100), "results_per_page"), + ValidateDiagFunc: validation.ToDiagFunc(validation.IntBetween(0, 100)), }, "teams": { Type: schema.TypeList, diff --git a/github/data_source_github_release.go b/github/data_source_github_release.go index 092e33a4d2..d01169675b 100644 --- a/github/data_source_github_release.go +++ b/github/data_source_github_release.go @@ -31,11 +31,11 @@ func dataSourceGithubRelease() *schema.Resource { Type: schema.TypeString, Required: true, Description: "Describes how to fetch the release. Valid values are `id`, `tag`, `latest`.", - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{ + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{ "latest", "id", "tag", - }, false), "retrieve_by"), + }, false)), }, "release_tag": { Type: schema.TypeString, diff --git a/github/data_source_github_repositories.go b/github/data_source_github_repositories.go index abfbf7fc63..460ee5d05b 100644 --- a/github/data_source_github_repositories.go +++ b/github/data_source_github_repositories.go @@ -21,7 +21,7 @@ func dataSourceGithubRepositories() *schema.Resource { Type: schema.TypeString, Default: "updated", Optional: true, - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"stars", "fork", "updated"}, false), "sort"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"stars", "fork", "updated"}, false)), }, "include_repo_id": { Type: schema.TypeBool, @@ -32,7 +32,7 @@ func dataSourceGithubRepositories() *schema.Resource { Type: schema.TypeInt, Optional: true, Default: 100, - ValidateDiagFunc: toDiagFunc(validation.IntBetween(0, 1000), "results_per_page"), + ValidateDiagFunc: validation.ToDiagFunc(validation.IntBetween(0, 1000)), }, "full_names": { Type: schema.TypeList, diff --git a/github/data_source_github_repository_pull_requests.go b/github/data_source_github_repository_pull_requests.go index f330461364..0d27fe112e 100644 --- a/github/data_source_github_repository_pull_requests.go +++ b/github/data_source_github_repository_pull_requests.go @@ -34,19 +34,19 @@ func dataSourceGithubRepositoryPullRequests() *schema.Resource { Type: schema.TypeString, Optional: true, Default: "created", - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"created", "updated", "popularity", "long-running"}, false), "sort_by"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"created", "updated", "popularity", "long-running"}, false)), }, "sort_direction": { Type: schema.TypeString, Optional: true, Default: "asc", - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"asc", "desc"}, false), "sort_direction"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"asc", "desc"}, false)), }, "state": { Type: schema.TypeString, Default: "open", Optional: true, - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"open", "closed", "all"}, false), "state"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"open", "closed", "all"}, false)), }, "results": { Type: schema.TypeList, diff --git a/github/data_source_github_team.go b/github/data_source_github_team.go index 7472867c59..f0f9970cd1 100644 --- a/github/data_source_github_team.go +++ b/github/data_source_github_team.go @@ -82,7 +82,7 @@ func dataSourceGithubTeam() *schema.Resource { Type: schema.TypeString, Default: "all", Optional: true, - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"all", "immediate"}, false), "membership_type"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"all", "immediate"}, false)), }, "summary_only": { Type: schema.TypeBool, @@ -93,7 +93,7 @@ func dataSourceGithubTeam() *schema.Resource { Type: schema.TypeInt, Optional: true, Default: 100, - ValidateDiagFunc: toDiagFunc(validation.IntBetween(0, 100), "results_per_page"), + ValidateDiagFunc: validation.ToDiagFunc(validation.IntBetween(0, 100)), Deprecated: "This is deprecated and will be removed in a future release.", }, }, diff --git a/github/data_source_github_team_test.go b/github/data_source_github_team_test.go index 09c1da4a9c..debdd19b82 100644 --- a/github/data_source_github_team_test.go +++ b/github/data_source_github_team_test.go @@ -170,6 +170,7 @@ func TestAccGithubTeamDataSource(t *testing.T) { resource "github_team" "test" { name = "%s" + description = "test" } resource "github_team_repository" "test" { diff --git a/github/resource_github_actions_environment_secret_migration.go b/github/resource_github_actions_environment_secret_migration.go index bedebc9e36..7ede4c0fb9 100644 --- a/github/resource_github_actions_environment_secret_migration.go +++ b/github/resource_github_actions_environment_secret_migration.go @@ -38,7 +38,7 @@ func resourceGithubActionsEnvironmentSecretV0() *schema.Resource { ForceNew: true, Description: "Encrypted value of the secret using the GitHub public key in Base64 format.", ConflictsWith: []string{"plaintext_value"}, - ValidateDiagFunc: toDiagFunc(validation.StringIsBase64, "encrypted_value"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsBase64), }, "plaintext_value": { Type: schema.TypeString, diff --git a/github/resource_github_actions_hosted_runner.go b/github/resource_github_actions_hosted_runner.go index 1629c5c97c..01f387c187 100644 --- a/github/resource_github_actions_hosted_runner.go +++ b/github/resource_github_actions_hosted_runner.go @@ -34,13 +34,13 @@ func resourceGithubActionsHostedRunner() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: validation.All( + ValidateDiagFunc: validation.ToDiagFunc(validation.All( validation.StringLenBetween(1, 64), validation.StringMatch( regexp.MustCompile(`^[a-zA-Z0-9._-]+$`), "name may only contain alphanumeric characters, '.', '-', and '_'", ), - ), + )), Description: "Name of the hosted runner. Must be between 1 and 64 characters and may only contain upper and lowercase letters a-z, numbers 0-9, '.', '-', and '_'.", }, "image": { @@ -56,11 +56,11 @@ func resourceGithubActionsHostedRunner() *schema.Resource { Description: "The image ID.", }, "source": { - Type: schema.TypeString, - Optional: true, - Default: "github", - ValidateFunc: validation.StringInSlice([]string{"github", "partner", "custom"}, false), - Description: "The image source (github, partner, or custom).", + Type: schema.TypeString, + Optional: true, + Default: "github", + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"github", "partner", "custom"}, false)), + Description: "The image source (github, partner, or custom).", }, "size_gb": { Type: schema.TypeInt, @@ -82,11 +82,11 @@ func resourceGithubActionsHostedRunner() *schema.Resource { Description: "The runner group ID.", }, "maximum_runners": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - ValidateFunc: validation.IntAtLeast(1), - Description: "Maximum number of runners to scale up to.", + Type: schema.TypeInt, + Optional: true, + Computed: true, + ValidateDiagFunc: validation.ToDiagFunc(validation.IntAtLeast(1)), + Description: "Maximum number of runners to scale up to.", }, "public_ip_enabled": { Type: schema.TypeBool, diff --git a/github/resource_github_actions_organization_permissions.go b/github/resource_github_actions_organization_permissions.go index 5106fec01a..d40976d088 100644 --- a/github/resource_github_actions_organization_permissions.go +++ b/github/resource_github_actions_organization_permissions.go @@ -25,13 +25,13 @@ func resourceGithubActionsOrganizationPermissions() *schema.Resource { Type: schema.TypeString, Optional: true, Description: "The permissions policy that controls the actions that are allowed to run. Can be one of: 'all', 'local_only', or 'selected'.", - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"all", "local_only", "selected"}, false), "allowed_actions"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"all", "local_only", "selected"}, false)), }, "enabled_repositories": { Type: schema.TypeString, Required: true, Description: "The policy that controls the repositories in the organization that are allowed to run GitHub Actions. Can be one of: 'all', 'none', or 'selected'.", - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"all", "none", "selected"}, false), "enabled_repositories"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"all", "none", "selected"}, false)), }, "allowed_actions_config": { Type: schema.TypeList, diff --git a/github/resource_github_actions_organization_secret_migration.go b/github/resource_github_actions_organization_secret_migration.go index 940880d164..7ad34dd2a7 100644 --- a/github/resource_github_actions_organization_secret_migration.go +++ b/github/resource_github_actions_organization_secret_migration.go @@ -27,7 +27,7 @@ func resourceGithubActionsOrganizationSecretV0() *schema.Resource { Sensitive: true, ConflictsWith: []string{"plaintext_value"}, Description: "Encrypted value of the secret using the GitHub public key in Base64 format.", - ValidateDiagFunc: toDiagFunc(validation.StringIsBase64, "encrypted_value"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsBase64), }, "plaintext_value": { Type: schema.TypeString, diff --git a/github/resource_github_actions_organization_workflow_permissions.go b/github/resource_github_actions_organization_workflow_permissions.go index 0ef2118b38..e27e15eb8e 100644 --- a/github/resource_github_actions_organization_workflow_permissions.go +++ b/github/resource_github_actions_organization_workflow_permissions.go @@ -41,11 +41,11 @@ func resourceGithubActionsOrganizationWorkflowPermissions() *schema.Resource { Description: "The slug of the Organization.", }, "default_workflow_permissions": { - Type: schema.TypeString, - Optional: true, - Default: "read", - Description: "The default workflow permissions granted to the GITHUB_TOKEN when running workflows in any repository in the organization. Can be 'read' or 'write'.", - ValidateFunc: validation.StringInSlice([]string{"read", "write"}, false), + Type: schema.TypeString, + Optional: true, + Default: "read", + Description: "The default workflow permissions granted to the GITHUB_TOKEN when running workflows in any repository in the organization. Can be 'read' or 'write'.", + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"read", "write"}, false)), }, "can_approve_pull_request_reviews": { Type: schema.TypeBool, diff --git a/github/resource_github_actions_repository_access_level.go b/github/resource_github_actions_repository_access_level.go index b31f9ad136..bf38fcae5a 100644 --- a/github/resource_github_actions_repository_access_level.go +++ b/github/resource_github_actions_repository_access_level.go @@ -23,13 +23,13 @@ func resourceGithubActionsRepositoryAccessLevel() *schema.Resource { Type: schema.TypeString, Required: true, Description: "Where the actions or reusable workflows of the repository may be used. Possible values are 'none', 'user', 'organization', or 'enterprise'.", - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"none", "user", "organization", "enterprise"}, false), "access_level"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"none", "user", "organization", "enterprise"}, false)), }, "repository": { Type: schema.TypeString, Required: true, Description: "The GitHub repository.", - ValidateDiagFunc: toDiagFunc(validation.StringLenBetween(1, 100), "repository"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringLenBetween(1, 100)), }, }, } diff --git a/github/resource_github_actions_repository_oidc_subject_claim_customization_template.go b/github/resource_github_actions_repository_oidc_subject_claim_customization_template.go index c973ca03bd..20bd364a3c 100644 --- a/github/resource_github_actions_repository_oidc_subject_claim_customization_template.go +++ b/github/resource_github_actions_repository_oidc_subject_claim_customization_template.go @@ -23,7 +23,7 @@ func resourceGithubActionsRepositoryOIDCSubjectClaimCustomizationTemplate() *sch Type: schema.TypeString, Required: true, Description: "The name of the repository.", - ValidateDiagFunc: toDiagFunc(validation.StringLenBetween(1, 100), "repository"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringLenBetween(1, 100)), }, "use_default": { Type: schema.TypeBool, diff --git a/github/resource_github_actions_repository_permissions.go b/github/resource_github_actions_repository_permissions.go index 57cbace461..90d6b192d3 100644 --- a/github/resource_github_actions_repository_permissions.go +++ b/github/resource_github_actions_repository_permissions.go @@ -24,7 +24,7 @@ func resourceGithubActionsRepositoryPermissions() *schema.Resource { Type: schema.TypeString, Optional: true, Description: "The permissions policy that controls the actions that are allowed to run. Can be one of: 'all', 'local_only', or 'selected'.", - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"all", "local_only", "selected"}, false), "allowed_actions"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"all", "local_only", "selected"}, false)), }, "allowed_actions_config": { Type: schema.TypeList, @@ -63,7 +63,7 @@ func resourceGithubActionsRepositoryPermissions() *schema.Resource { Type: schema.TypeString, Required: true, Description: "The GitHub repository.", - ValidateDiagFunc: toDiagFunc(validation.StringLenBetween(1, 100), "repository"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringLenBetween(1, 100)), }, "sha_pinning_required": { Type: schema.TypeBool, diff --git a/github/resource_github_actions_runner_group.go b/github/resource_github_actions_runner_group.go index 394ff56a1c..95f66f24bb 100644 --- a/github/resource_github_actions_runner_group.go +++ b/github/resource_github_actions_runner_group.go @@ -78,7 +78,7 @@ func resourceGithubActionsRunnerGroup() *schema.Resource { Type: schema.TypeString, Required: true, Description: "The visibility of the runner group.", - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"all", "selected", "private"}, false), "visibility"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"all", "selected", "private"}, false)), }, "restricted_to_workflows": { Type: schema.TypeBool, diff --git a/github/resource_github_branch_protection.go b/github/resource_github_branch_protection.go index 8d4bbc2b2b..8dc5bbcbcc 100644 --- a/github/resource_github_branch_protection.go +++ b/github/resource_github_branch_protection.go @@ -81,7 +81,7 @@ func resourceGithubBranchProtection() *schema.Resource { Optional: true, Default: 1, Description: "Require 'x' number of approvals to satisfy branch protection requirements. If this is specified it must be a number between 0-6.", - ValidateDiagFunc: toDiagFunc(validation.IntBetween(0, 6), PROTECTION_REQUIRED_APPROVING_REVIEW_COUNT), + ValidateDiagFunc: validation.ToDiagFunc(validation.IntBetween(0, 6)), }, PROTECTION_REQUIRES_CODE_OWNER_REVIEWS: { Type: schema.TypeBool, diff --git a/github/resource_github_branch_protection_v3.go b/github/resource_github_branch_protection_v3.go index e238def1fd..c43f161ddc 100644 --- a/github/resource_github_branch_protection_v3.go +++ b/github/resource_github_branch_protection_v3.go @@ -130,7 +130,7 @@ func resourceGithubBranchProtectionV3() *schema.Resource { Optional: true, Default: 1, Description: "Require 'x' number of approvals to satisfy branch protection requirements. If this is specified it must be a number between 0-6.", - ValidateDiagFunc: toDiagFunc(validation.IntBetween(0, 6), "required_approving_review_count"), + ValidateDiagFunc: validation.ToDiagFunc(validation.IntBetween(0, 6)), }, "require_last_push_approval": { Type: schema.TypeBool, diff --git a/github/resource_github_codespaces_organization_secret.go b/github/resource_github_codespaces_organization_secret.go index 89b428b361..30a6388cae 100644 --- a/github/resource_github_codespaces_organization_secret.go +++ b/github/resource_github_codespaces_organization_secret.go @@ -42,7 +42,7 @@ func resourceGithubCodespacesOrganizationSecret() *schema.Resource { Sensitive: true, ConflictsWith: []string{"plaintext_value"}, Description: "Encrypted value of the secret using the GitHub public key in Base64 format.", - ValidateDiagFunc: toDiagFunc(validation.StringIsBase64, "encrypted_value"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsBase64), }, "plaintext_value": { Type: schema.TypeString, diff --git a/github/resource_github_codespaces_user_secret.go b/github/resource_github_codespaces_user_secret.go index 446ecc73d4..9dace8a32e 100644 --- a/github/resource_github_codespaces_user_secret.go +++ b/github/resource_github_codespaces_user_secret.go @@ -41,7 +41,7 @@ func resourceGithubCodespacesUserSecret() *schema.Resource { Sensitive: true, ConflictsWith: []string{"plaintext_value"}, Description: "Encrypted value of the secret using the GitHub public key in Base64 format.", - ValidateDiagFunc: toDiagFunc(validation.StringIsBase64, "encrypted_value"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsBase64), }, "plaintext_value": { Type: schema.TypeString, diff --git a/github/resource_github_enterprise_actions_permissions.go b/github/resource_github_enterprise_actions_permissions.go index f5470afa65..c2cc12b9d6 100644 --- a/github/resource_github_enterprise_actions_permissions.go +++ b/github/resource_github_enterprise_actions_permissions.go @@ -30,13 +30,13 @@ func resourceGithubActionsEnterprisePermissions() *schema.Resource { Type: schema.TypeString, Optional: true, Description: "The permissions policy that controls the actions that are allowed to run. Can be one of: 'all', 'local_only', or 'selected'.", - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"all", "local_only", "selected"}, false), "allowed_actions"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"all", "local_only", "selected"}, false)), }, "enabled_organizations": { Type: schema.TypeString, Required: true, Description: "The policy that controls the organizations in the enterprise that are allowed to run GitHub Actions. Can be one of: 'all', 'none', or 'selected'.", - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"all", "none", "selected"}, false), "enabled_organizations"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"all", "none", "selected"}, false)), }, "allowed_actions_config": { Type: schema.TypeList, diff --git a/github/resource_github_enterprise_actions_runner_group.go b/github/resource_github_enterprise_actions_runner_group.go index c37ebd8bef..45850283ba 100644 --- a/github/resource_github_enterprise_actions_runner_group.go +++ b/github/resource_github_enterprise_actions_runner_group.go @@ -60,7 +60,7 @@ func resourceGithubActionsEnterpriseRunnerGroup() *schema.Resource { Type: schema.TypeString, Required: true, Description: "The visibility of the runner group.", - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"all", "selected"}, false), "visibility"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"all", "selected"}, false)), }, "restricted_to_workflows": { Type: schema.TypeBool, diff --git a/github/resource_github_enterprise_actions_workflow_permissions.go b/github/resource_github_enterprise_actions_workflow_permissions.go index 5419bb0896..e848378c14 100644 --- a/github/resource_github_enterprise_actions_workflow_permissions.go +++ b/github/resource_github_enterprise_actions_workflow_permissions.go @@ -28,11 +28,11 @@ func resourceGithubEnterpriseActionsWorkflowPermissions() *schema.Resource { Description: "The slug of the enterprise.", }, "default_workflow_permissions": { - Type: schema.TypeString, - Optional: true, - Default: "read", - Description: "The default workflow permissions granted to the GITHUB_TOKEN when running workflows. Can be 'read' or 'write'.", - ValidateFunc: validation.StringInSlice([]string{"read", "write"}, false), + Type: schema.TypeString, + Optional: true, + Default: "read", + Description: "The default workflow permissions granted to the GITHUB_TOKEN when running workflows. Can be 'read' or 'write'.", + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"read", "write"}, false)), }, "can_approve_pull_request_reviews": { Type: schema.TypeBool, diff --git a/github/resource_github_organization_ruleset.go b/github/resource_github_organization_ruleset.go index 8624250883..07fa00dfc9 100644 --- a/github/resource_github_organization_ruleset.go +++ b/github/resource_github_organization_ruleset.go @@ -270,7 +270,7 @@ func resourceGithubOrganizationRuleset() *schema.Resource { "type": { Type: schema.TypeString, Required: true, - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"Team"}, false), "type"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"Team"}, false)), Description: "The type of reviewer. Currently only `Team` is supported.", }, }, diff --git a/github/resource_github_organization_settings.go b/github/resource_github_organization_settings.go index c5ae0bd5b4..084a105efd 100644 --- a/github/resource_github_organization_settings.go +++ b/github/resource_github_organization_settings.go @@ -73,7 +73,7 @@ func resourceGithubOrganizationSettings() *schema.Resource { Optional: true, Default: "read", Description: "The default permission for organization members to create new repositories. Can be one of 'read', 'write', 'admin' or 'none'.", - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"read", "write", "admin", "none"}, false), "default_repository_permission"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"read", "write", "admin", "none"}, false)), }, "members_can_create_repositories": { Type: schema.TypeBool, diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 9d756ac6c9..82304d9e1b 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -39,7 +39,7 @@ func resourceGithubRepository() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateDiagFunc: toDiagFunc(validation.StringMatch(regexp.MustCompile(`^[-a-zA-Z0-9_.]{1,100}$`), "must include only alphanumeric characters, underscores or hyphens and consist of 100 characters or less"), "name"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringMatch(regexp.MustCompile(`^[-a-zA-Z0-9_.]{1,100}$`), "must include only alphanumeric characters, underscores or hyphens and consist of 100 characters or less")), Description: "The name of the repository.", }, "description": { @@ -63,7 +63,7 @@ func resourceGithubRepository() *schema.Resource { Type: schema.TypeString, Optional: true, Computed: true, // is affected by "private" - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"public", "private", "internal"}, false), "visibility"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"public", "private", "internal"}, false)), Description: "Can be 'public' or 'private'. If your organization is associated with an enterprise account using GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+, visibility can also be 'internal'.", }, // terraform-sdk-provider doesn't properly support tristate booleans: https://github.com/hashicorp/terraform-plugin-sdk/issues/817 @@ -104,7 +104,7 @@ func resourceGithubRepository() *schema.Resource { "status": { Type: schema.TypeString, Required: true, - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false), "status"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false)), Description: "Set to 'enabled' to enable advanced security features on the repository. Can be 'enabled' or 'disabled', This value being present when split licensing is enabled will error out.", }, }, @@ -120,7 +120,7 @@ func resourceGithubRepository() *schema.Resource { "status": { Type: schema.TypeString, Required: true, - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false), "code_security"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false)), Description: "Set to 'enabled' to enable code security on the repository. Can be 'enabled' or 'disabled'. If set to 'enabled', the repository's visibility must be 'public', 'security_and_analysis[0].advanced_security[0].status' must also be set to 'enabled', or your Organization must have split licensing for Advanced security.", }, }, @@ -136,7 +136,7 @@ func resourceGithubRepository() *schema.Resource { "status": { Type: schema.TypeString, Required: true, - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false), "secret_scanning"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false)), Description: "Set to 'enabled' to enable secret scanning on the repository. Can be 'enabled' or 'disabled'. If set to 'enabled', the repository's visibility must be 'public', 'security_and_analysis[0].advanced_security[0].status' must also be set to 'enabled', or your Organization must have split licensing for Advanced security.", }, }, @@ -152,7 +152,7 @@ func resourceGithubRepository() *schema.Resource { "status": { Type: schema.TypeString, Required: true, - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false), "secret_scanning_push_protection"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false)), Description: "Set to 'enabled' to enable secret scanning push protection on the repository. Can be 'enabled' or 'disabled'. If set to 'enabled', the repository's visibility must be 'public', 'security_and_analysis[0].advanced_security[0].status' must also be set to 'enabled', or your Organization must have split licensing for Advanced security.", }, }, @@ -168,7 +168,7 @@ func resourceGithubRepository() *schema.Resource { "status": { Type: schema.TypeString, Required: true, - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false), "secret_scanning_ai_detection"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false)), Description: "Set to 'enabled' to enable secret scanning AI detection on the repository. Can be 'enabled' or 'disabled'. If set to 'enabled', the repository's visibility must be 'public', 'security_and_analysis[0].advanced_security[0].status' must also be set to 'enabled', or your Organization must have split licensing for Advanced security.", }, }, @@ -184,7 +184,7 @@ func resourceGithubRepository() *schema.Resource { "status": { Type: schema.TypeString, Required: true, - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false), "secret_scanning_non_provider_patterns"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false)), Description: "Set to 'enabled' to enable secret scanning non-provider patterns on the repository. Can be 'enabled' or 'disabled'. If set to 'enabled', the repository's visibility must be 'public', 'security_and_analysis[0].advanced_security[0].status' must also be set to 'enabled', or your Organization must have split licensing for Advanced security.", }, }, @@ -392,7 +392,7 @@ func resourceGithubRepository() *schema.Resource { Description: "The list of topics of the repository.", Elem: &schema.Schema{ Type: schema.TypeString, - ValidateDiagFunc: toDiagFunc(validation.StringMatch(regexp.MustCompile(`^[a-z0-9][a-z0-9-]{0,49}$`), "must include only lowercase alphanumeric characters or hyphens and cannot start with a hyphen and consist of 50 characters or less"), "topics"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringMatch(regexp.MustCompile(`^[a-z0-9][a-z0-9-]{0,49}$`), "must include only lowercase alphanumeric characters or hyphens and cannot start with a hyphen and consist of 50 characters or less")), }, }, "vulnerability_alerts": { diff --git a/github/resource_github_repository_autolink_reference.go b/github/resource_github_repository_autolink_reference.go index 9ee8c90eee..e4beac1818 100644 --- a/github/resource_github_repository_autolink_reference.go +++ b/github/resource_github_repository_autolink_reference.go @@ -75,7 +75,7 @@ func resourceGithubRepositoryAutolinkReference() *schema.Resource { Required: true, ForceNew: true, Description: "The template of the target URL used for the links; must be a valid URL and contain `` for the reference number", - ValidateDiagFunc: toDiagFunc(validation.StringMatch(regexp.MustCompile(`^http[s]?:\/\/[a-z0-9-.]*(:[0-9]+)?\/.*?.*?$`), "must be a valid URL and contain token"), "target_url_template"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringMatch(regexp.MustCompile(`^http[s]?:\/\/[a-z0-9-.]*(:[0-9]+)?\/.*?.*?$`), "must be a valid URL and contain token")), }, "is_alphanumeric": { Type: schema.TypeBool, diff --git a/github/resource_github_repository_environment.go b/github/resource_github_repository_environment.go index 6eefc5a478..38bee4efb4 100644 --- a/github/resource_github_repository_environment.go +++ b/github/resource_github_repository_environment.go @@ -50,7 +50,7 @@ func resourceGithubRepositoryEnvironment() *schema.Resource { "wait_timer": { Type: schema.TypeInt, Optional: true, - ValidateDiagFunc: toDiagFunc(validation.IntBetween(0, 43200), "wait_timer"), + ValidateDiagFunc: validation.ToDiagFunc(validation.IntBetween(0, 43200)), Description: "Amount of time to delay a job after the job is initially triggered.", }, "reviewers": { diff --git a/github/resource_github_repository_milestone.go b/github/resource_github_repository_milestone.go index 680db860e0..6b1d110b1f 100644 --- a/github/resource_github_repository_milestone.go +++ b/github/resource_github_repository_milestone.go @@ -75,9 +75,9 @@ func resourceGithubRepositoryMilestone() *schema.Resource { "state": { Type: schema.TypeString, Optional: true, - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{ + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{ "open", "closed", - }, true), "state"), + }, false)), Default: "open", Description: "The state of the milestone. Either 'open' or 'closed'. Default: 'open'.", }, diff --git a/github/resource_github_repository_ruleset.go b/github/resource_github_repository_ruleset.go index 460473e857..4e9b3ec119 100644 --- a/github/resource_github_repository_ruleset.go +++ b/github/resource_github_repository_ruleset.go @@ -257,7 +257,7 @@ func resourceGithubRepositoryRuleset() *schema.Resource { "type": { Type: schema.TypeString, Required: true, - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"Team"}, false), "type"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"Team"}, false)), Description: "The type of reviewer. Currently only `Team` is supported.", }, }, diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 1589c84bf1..7726a58479 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -2,7 +2,6 @@ package github import ( "fmt" - "regexp" "strings" "testing" @@ -704,7 +703,7 @@ resource "github_repository" "test" { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("github_repository.test", "vulnerability_alerts"), + resource.TestCheckNoResourceAttr("github_repository.test", "vulnerability_alerts"), ), }, }, @@ -1119,40 +1118,29 @@ resource "github_repository" "test" { t.Run("updates repos to private visibility", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) testRepoName := fmt.Sprintf("%svisibility-public-%s", testResourcePrefix, randomID) - config := fmt.Sprintf(` + config := ` resource "github_repository" "public" { name = "%s" - visibility = "public" + visibility = "%s" vulnerability_alerts = false } - `, testRepoName) - - checks := map[string]resource.TestCheckFunc{ - "before": resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "github_repository.public", "visibility", - "public", - ), - ), - "after": resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "github_repository.public", "visibility", - "private", - ), - ), - } + ` resource.Test(t, resource.TestCase{ PreCheck: func() { skipUnauthenticated(t) }, ProviderFactories: providerFactories, Steps: []resource.TestStep{ { - Config: config, - Check: checks["before"], + Config: fmt.Sprintf(config, testRepoName, "public"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("github_repository.public", "visibility", "public"), + ), }, { - Config: reconfigureVisibility(config, "private"), - Check: checks["after"], + Config: fmt.Sprintf(config, testRepoName, "private"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("github_repository.public", "visibility", "private"), + ), }, }, }) @@ -1170,9 +1158,8 @@ resource "github_repository" "test" { checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( + resource.TestCheckNoResourceAttr( "github_repository.test", "vulnerability_alerts", - "false", ), ), "after": resource.ComposeTestCheckFunc( @@ -1217,20 +1204,11 @@ resource "github_repository" "test" { checks := map[string]resource.TestCheckFunc{ "before": resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "github_repository.test", "vulnerability_alerts", - "false", - ), + resource.TestCheckNoResourceAttr("github_repository.test", "vulnerability_alerts"), ), "after": resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "github_repository.test", "vulnerability_alerts", - "true", - ), - resource.TestCheckResourceAttr( - "github_repository.test", "visibility", - "private", - ), + resource.TestCheckResourceAttr("github_repository.test", "vulnerability_alerts", "true"), + resource.TestCheckResourceAttr("github_repository.test", "visibility", "private"), ), } @@ -1552,9 +1530,9 @@ func Test_expandPages(t *testing.T) { func TestGithubRepositoryTopicPassesValidation(t *testing.T) { resource := resourceGithubRepository() schema := resource.Schema["topics"].Elem.(*schema.Schema) - diags := schema.ValidateDiagFunc("ef69e1a3-66be-40ca-bb62-4f36186aa292", cty.Path{cty.GetAttrStep{Name: "topic"}}) + diags := schema.ValidateDiagFunc("ef69e1a3-66be-40ca-bb62-4f36186aa292", cty.Path{cty.GetAttrStep{Name: "topics"}}) if diags.HasError() { - t.Error(fmt.Errorf("unexpected topic validation failure: %s", diags[0].Summary)) + t.Error(fmt.Errorf("unexpected topics validation failure: %s", diags[0].Summary)) } } @@ -1562,7 +1540,7 @@ func TestGithubRepositoryTopicFailsValidationWhenOverMaxCharacters(t *testing.T) resource := resourceGithubRepository() schema := resource.Schema["topics"].Elem.(*schema.Schema) - diags := schema.ValidateDiagFunc(strings.Repeat("a", 51), cty.Path{cty.GetAttrStep{Name: "topic"}}) + diags := schema.ValidateDiagFunc(strings.Repeat("a", 51), cty.Path{cty.GetAttrStep{Name: "topics"}}) if len(diags) != 1 { t.Error(fmt.Errorf("unexpected number of topic validation failures; expected=1; actual=%d", len(diags))) } @@ -1573,15 +1551,6 @@ func TestGithubRepositoryTopicFailsValidationWhenOverMaxCharacters(t *testing.T) } } -func reconfigureVisibility(config, visibility string) string { - re := regexp.MustCompile(`visibility = "(.*)"`) - newConfig := re.ReplaceAllString( - config, - fmt.Sprintf(`visibility = "%s"`, visibility), - ) - return newConfig -} - type resourceDataLike map[string]any func (d resourceDataLike) GetOk(key string) (any, bool) { diff --git a/github/resource_github_repository_topics.go b/github/resource_github_repository_topics.go index 3c5d5a5113..41e177fb83 100644 --- a/github/resource_github_repository_topics.go +++ b/github/resource_github_repository_topics.go @@ -26,18 +26,18 @@ func resourceGithubRepositoryTopics() *schema.Resource { }, Schema: map[string]*schema.Schema{ "repository": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[-a-zA-Z0-9_.]{1,100}$`), "must include only alphanumeric characters, underscores or hyphens and consist of 100 characters or less"), - Description: "The name of the repository. The name is not case sensitive.", + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: validation.ToDiagFunc(validation.StringMatch(regexp.MustCompile(`^[-a-zA-Z0-9_.]{1,100}$`), "must include only alphanumeric characters, underscores or hyphens and consist of 100 characters or less")), + Description: "The name of the repository. The name is not case sensitive.", }, "topics": { Type: schema.TypeSet, Required: true, Description: "An array of topics to add to the repository. Pass one or more topics to replace the set of existing topics. Send an empty array ([]) to clear all topics from the repository. Note: Topic names cannot contain uppercase letters.", Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-z0-9][a-z0-9-]{0,49}$`), "must include only lowercase alphanumeric characters or hyphens and cannot start with a hyphen and consist of 50 characters or less"), + Type: schema.TypeString, + ValidateDiagFunc: validation.ToDiagFunc(validation.StringMatch(regexp.MustCompile(`^[a-z0-9][a-z0-9-]{0,49}$`), "must include only lowercase alphanumeric characters or hyphens and cannot start with a hyphen and consist of 50 characters or less")), }, }, }, diff --git a/github/resource_github_team_settings.go b/github/resource_github_team_settings.go index 38841d3e80..c6f36ce2a5 100644 --- a/github/resource_github_team_settings.go +++ b/github/resource_github_team_settings.go @@ -3,10 +3,10 @@ package github import ( "context" "errors" - "fmt" "strconv" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/shurcooL/githubv4" ) @@ -44,38 +44,20 @@ func resourceGithubTeamSettings() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "algorithm": { - Type: schema.TypeString, - Optional: true, - Description: "The algorithm to use when assigning pull requests to team members. Supported values are 'ROUND_ROBIN' and 'LOAD_BALANCE'.", - Default: "ROUND_ROBIN", - ValidateDiagFunc: toDiagFunc(func(v any, key string) (we []string, errs []error) { - algorithm, ok := v.(string) - if !ok { - return nil, []error{fmt.Errorf("expected type of %s to be string", key)} - } - - if algorithm != "ROUND_ROBIN" && algorithm != "LOAD_BALANCE" { - errs = append(errs, errors.New("review request delegation algorithm must be one of [\"ROUND_ROBIN\", \"LOAD_BALANCE\"]")) - } - - return we, errs - }, "algorithm"), + Type: schema.TypeString, + Optional: true, + Description: "The algorithm to use when assigning pull requests to team members. Supported values are 'ROUND_ROBIN' and 'LOAD_BALANCE'.", + Default: "ROUND_ROBIN", + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"ROUND_ROBIN", "LOAD_BALANCE"}, false)), }, "member_count": { Type: schema.TypeInt, Optional: true, RequiredWith: []string{"review_request_delegation"}, Description: "The number of team members to assign to a pull request.", - ValidateDiagFunc: toDiagFunc(func(v any, key string) (we []string, errs []error) { - count, ok := v.(int) - if !ok { - return nil, []error{fmt.Errorf("expected type of %s to be an integer", key)} - } - if count <= 0 { - errs = append(errs, errors.New("review request delegation reviewer count must be a positive number")) - } - return we, errs - }, "member_count"), + ValidateDiagFunc: validation.ToDiagFunc(validation.All( + validation.IntAtLeast(1), + )), }, "notify": { Type: schema.TypeBool, diff --git a/github/resource_github_team_settings_test.go b/github/resource_github_team_settings_test.go index 09b46a0711..e75caaac45 100644 --- a/github/resource_github_team_settings_test.go +++ b/github/resource_github_team_settings_test.go @@ -150,7 +150,7 @@ func TestAccGithubTeamSettings(t *testing.T) { Config: strings.Replace(config, `algorithm = "ROUND_ROBIN"`, `algorithm = "invalid"`, 1), - ExpectError: regexp.MustCompile(`review request delegation algorithm must be one of \[.*\]`), + ExpectError: regexp.MustCompile(`expected algorithm to be one of \[.*\]`), }, }, }) diff --git a/github/resource_github_workflow_repository_permissions.go b/github/resource_github_workflow_repository_permissions.go index ca35e34183..ffd30509df 100644 --- a/github/resource_github_workflow_repository_permissions.go +++ b/github/resource_github_workflow_repository_permissions.go @@ -23,7 +23,7 @@ func resourceGithubWorkflowRepositoryPermissions() *schema.Resource { Type: schema.TypeString, Optional: true, Description: "The default workflow permissions granted to the GITHUB_TOKEN when running workflows.", - ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"read", "write"}, false), "default_workflow_permissions"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"read", "write"}, false)), }, "can_approve_pull_request_reviews": { Type: schema.TypeBool, @@ -35,7 +35,7 @@ func resourceGithubWorkflowRepositoryPermissions() *schema.Resource { Type: schema.TypeString, Required: true, Description: "The GitHub repository.", - ValidateDiagFunc: toDiagFunc(validation.StringLenBetween(1, 100), "repository"), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringLenBetween(1, 100)), }, }, } diff --git a/github/util.go b/github/util.go index 559f999e80..a7d6ee63ca 100644 --- a/github/util.go +++ b/github/util.go @@ -128,33 +128,6 @@ func wrapErrors(errs []error) diag.Diagnostics { return diags } -// toDiagFunc is a helper that operates on Hashicorp's helper/validation functions -// and converts them to the diag.Diagnostic format -// --> nolint: oldFunc needs to be schema.SchemaValidateFunc to keep compatibility with -// the old code until all uses of schema.SchemaValidateFunc are gone. -func toDiagFunc(oldFunc schema.SchemaValidateFunc, keyName string) schema.SchemaValidateDiagFunc { //nolint:staticcheck - return func(i any, path cty.Path) diag.Diagnostics { - warnings, errors := oldFunc(i, keyName) - var diags diag.Diagnostics - - for _, err := range errors { - diags = append(diags, diag.Diagnostic{ - Severity: diag.Error, - Summary: err.Error(), - }) - } - - for _, warn := range warnings { - diags = append(diags, diag.Diagnostic{ - Severity: diag.Warning, - Summary: warn, - }) - } - - return diags - } -} - func validateValueFunc(values []string) schema.SchemaValidateDiagFunc { return func(v any, k cty.Path) diag.Diagnostics { errs := make([]error, 0)