Skip to content

Commit d866b8e

Browse files
feat: Update security and analysis (#2935)
* Update repository settings to include new API fields * correct naming of code scanning to code security to match API --------- Co-authored-by: Nick Floyd <[email protected]>
1 parent e86cb17 commit d866b8e

File tree

3 files changed

+322
-235
lines changed

3 files changed

+322
-235
lines changed

github/resource_github_repository.go

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,23 @@ func resourceGithubRepository() *schema.Resource {
100100
Type: schema.TypeString,
101101
Required: true,
102102
ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false), "status"),
103-
Description: "Set to 'enabled' to enable advanced security features on the repository. Can be 'enabled' or 'disabled'.",
103+
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.",
104+
},
105+
},
106+
},
107+
},
108+
"code_security": {
109+
Type: schema.TypeList,
110+
Optional: true,
111+
MaxItems: 1,
112+
Description: "The code security configuration for the repository.",
113+
Elem: &schema.Resource{
114+
Schema: map[string]*schema.Schema{
115+
"status": {
116+
Type: schema.TypeString,
117+
Required: true,
118+
ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false), "code_security"),
119+
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.",
104120
},
105121
},
106122
},
@@ -116,7 +132,7 @@ func resourceGithubRepository() *schema.Resource {
116132
Type: schema.TypeString,
117133
Required: true,
118134
ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false), "secret_scanning"),
119-
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' or 'security_and_analysis[0].advanced_security[0].status' must also be set to 'enabled'.",
135+
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.",
120136
},
121137
},
122138
},
@@ -132,7 +148,39 @@ func resourceGithubRepository() *schema.Resource {
132148
Type: schema.TypeString,
133149
Required: true,
134150
ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false), "secret_scanning_push_protection"),
135-
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' or 'security_and_analysis[0].advanced_security[0].status' must also be set to 'enabled'.",
151+
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.",
152+
},
153+
},
154+
},
155+
},
156+
"secret_scanning_ai_detection": {
157+
Type: schema.TypeList,
158+
Optional: true,
159+
MaxItems: 1,
160+
Description: "The secret scanning AI detection configuration for this repository.",
161+
Elem: &schema.Resource{
162+
Schema: map[string]*schema.Schema{
163+
"status": {
164+
Type: schema.TypeString,
165+
Required: true,
166+
ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false), "secret_scanning_ai_detection"),
167+
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.",
168+
},
169+
},
170+
},
171+
},
172+
"secret_scanning_non_provider_patterns": {
173+
Type: schema.TypeList,
174+
Optional: true,
175+
MaxItems: 1,
176+
Description: "The secret scanning non-provider patterns configuration for this repository.",
177+
Elem: &schema.Resource{
178+
Schema: map[string]*schema.Schema{
179+
"status": {
180+
Type: schema.TypeString,
181+
Required: true,
182+
ValidateDiagFunc: toDiagFunc(validation.StringInSlice([]string{"enabled", "disabled"}, false), "secret_scanning_non_provider_patterns"),
183+
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.",
136184
},
137185
},
138186
},

github/resource_github_repository_test.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,12 +1110,21 @@ func TestAccGithubRepositorySecurity(t *testing.T) {
11101110
advanced_security {
11111111
status = "enabled"
11121112
}
1113-
secret_scanning {
1113+
code_security {
1114+
status = "enabled"
1115+
}
1116+
secret_scanning {
11141117
status = "enabled"
11151118
}
11161119
secret_scanning_push_protection {
11171120
status = "enabled"
11181121
}
1122+
secret_scanning_ai_detection {
1123+
status = "enabled"
1124+
}
1125+
secret_scanning_non_provider_patterns {
1126+
status = "enabled"
1127+
}
11191128
}
11201129
}
11211130
`, randomID)
@@ -1125,13 +1134,25 @@ func TestAccGithubRepositorySecurity(t *testing.T) {
11251134
"github_repository.test", "security_and_analysis.0.advanced_security.0.status",
11261135
"enabled",
11271136
),
1137+
resource.TestCheckResourceAttr(
1138+
"github_repository.test", "security_and_analysis.0.code_security.0.status",
1139+
"enabled",
1140+
),
11281141
resource.TestCheckResourceAttr(
11291142
"github_repository.test", "security_and_analysis.0.secret_scanning.0.status",
11301143
"enabled",
11311144
),
11321145
resource.TestCheckResourceAttr(
11331146
"github_repository.test", "security_and_analysis.0.secret_scanning_push_protection.0.status",
1134-
"disabled",
1147+
"enabled",
1148+
),
1149+
resource.TestCheckResourceAttr(
1150+
"github_repository.test", "security_and_analysis.0.secret_scanning_ai_detection.0.status",
1151+
"enabled",
1152+
),
1153+
resource.TestCheckResourceAttr(
1154+
"github_repository.test", "security_and_analysis.0.secret_scanning_non_provider_patterns.0.status",
1155+
"enabled",
11351156
),
11361157
)
11371158
testCase := func(t *testing.T, mode string) {

0 commit comments

Comments
 (0)