@@ -275,6 +275,86 @@ func TestAccArgoCDRepositoryCredentials_GitHubAppConsistency(t *testing.T) {
275275 })
276276}
277277
278+ func TestAccArgoCDRepositoryCredentials_GitHubAppWithRepositoryInheritance (t * testing.T ) {
279+ sshPrivateKey , err := generateSSHPrivateKey ()
280+ assert .NoError (t , err )
281+
282+ // Use the local test repository infrastructure to avoid external dependencies
283+ // while still testing GitHub App credential inheritance
284+ config := testAccArgoCDRepositoryCredentialsGitHubAppWithRepository (
285+ 286+ "[email protected] :~/project-1.git" ,
287+ "123456" ,
288+ "987654321" ,
289+ "https://ghe.example.com/api/v3" ,
290+ sshPrivateKey ,
291+ )
292+
293+ resource .Test (t , resource.TestCase {
294+ PreCheck : func () { testAccPreCheck (t ) },
295+ ProtoV6ProviderFactories : testAccProtoV6ProviderFactories ,
296+ Steps : []resource.TestStep {
297+ {
298+ Config : config ,
299+ Check : resource .ComposeAggregateTestCheckFunc (
300+ // Check repository credentials - verify GitHub App fields are set
301+ resource .
TestCheckResourceAttr (
"argocd_repository_credentials.githubapp" ,
"url" ,
"[email protected] " ),
302+ resource .TestCheckResourceAttr ("argocd_repository_credentials.githubapp" , "githubapp_id" , "123456" ),
303+ resource .TestCheckResourceAttr ("argocd_repository_credentials.githubapp" , "githubapp_installation_id" , "987654321" ),
304+ //resource.TestCheckResourceAttr("argocd_repository_credentials.githubapp", "githubapp_enterprise_base_url", "https://ghe.example.com/api/v3"),
305+ // Check repository that inherits credentials
306+ resource .
TestCheckResourceAttr (
"argocd_repository.repo" ,
"repo" ,
"[email protected] :~/project-1.git" ),
307+ ),
308+ },
309+ {
310+ // Apply the same configuration again to test for consistency (Issue #697)
311+ // This should NOT produce "inconsistent result after apply" errors
312+ // This is the key test - without the updateFromAPI fix, this step would fail
313+ Config : config ,
314+ Check : resource .ComposeAggregateTestCheckFunc (
315+ // Verify repository credentials fields remain stable across applies
316+ resource .
TestCheckResourceAttr (
"argocd_repository_credentials.githubapp" ,
"url" ,
"[email protected] " ),
317+ resource .TestCheckResourceAttr ("argocd_repository_credentials.githubapp" , "githubapp_id" , "123456" ),
318+ resource .TestCheckResourceAttr ("argocd_repository_credentials.githubapp" , "githubapp_installation_id" , "987654321" ),
319+ //resource.TestCheckResourceAttr("argocd_repository_credentials.githubapp", "githubapp_enterprise_base_url", "https://ghe.example.com/api/v3"),
320+ // Verify repository remains stable
321+ resource .
TestCheckResourceAttr (
"argocd_repository.repo" ,
"repo" ,
"[email protected] :~/project-1.git" ),
322+ ),
323+ },
324+ {
325+ // Apply a third time to ensure continued consistency
326+ Config : config ,
327+ Check : resource .ComposeAggregateTestCheckFunc (
328+ resource .
TestCheckResourceAttr (
"argocd_repository_credentials.githubapp" ,
"url" ,
"[email protected] " ),
329+ resource .TestCheckResourceAttr ("argocd_repository_credentials.githubapp" , "githubapp_id" , "123456" ),
330+ resource .TestCheckResourceAttr ("argocd_repository_credentials.githubapp" , "githubapp_installation_id" , "987654321" ),
331+ //resource.TestCheckResourceAttr("argocd_repository_credentials.githubapp", "githubapp_enterprise_base_url", "https://ghe.example.com/api/v3"),
332+ resource .
TestCheckResourceAttr (
"argocd_repository.repo" ,
"repo" ,
"[email protected] :~/project-1.git" ),
333+ ),
334+ },
335+ },
336+ })
337+ }
338+
339+ func testAccArgoCDRepositoryCredentialsGitHubAppWithRepository (credsUrl , repoUrl , id , installID , enterpriseBaseURL , _ string ) string {
340+ return fmt .Sprintf (`
341+ resource "argocd_repository_credentials" "githubapp" {
342+ url = "%s"
343+ githubapp_id = "%s"
344+ githubapp_installation_id = "%s"
345+ #githubapp_enterprise_base_url = "%s"
346+ ssh_private_key = "-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW\nQyNTUxOQAAACCGe6Vx0gbKqKCI0wIplfgK5JBjCDO3bhtU3sZfLoeUZgAAAJB9cNEifXDR\nIgAAAAtzc2gtZWQyNTUxOQAAACCGe6Vx0gbKqKCI0wIplfgK5JBjCDO3bhtU3sZfLoeUZg\nAAAEAJeUrObjoTbGO1Sq4TXHl/j4RJ5aKMC1OemWuHmLK7XYZ7pXHSBsqooIjTAimV+Ark\nkGMIM7duG1Texl8uh5RmAAAAC3Rlc3RAYXJnb2NkAQI=\n-----END OPENSSH PRIVATE KEY-----"
347+ }
348+
349+ resource "argocd_repository" "repo" {
350+ repo = "%s"
351+ type = "git"
352+ insecure = true
353+ depends_on = [argocd_repository_credentials.githubapp]
354+ }
355+ ` , credsUrl , id , installID , enterpriseBaseURL , repoUrl )
356+ }
357+
278358func testCheckMultipleResourceAttr (name , key , value string , count int ) resource.TestCheckFunc {
279359 return func (s * terraform.State ) error {
280360 for i := 0 ; i < count ; i ++ {
0 commit comments