Skip to content

Commit 37783e2

Browse files
KenSpurkfcampbell
andauthored
[Bug]: Renaming github_repository doesn't taint full_name attribute (#1756)
* set full_name new computed on name change & add tests * Run go fmt ./... --------- Co-authored-by: Keegan Campbell <me@kfcampbell.com>
1 parent db1c41c commit 37783e2

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

github/resource_github_repository.go

+8
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ func resourceGithubRepository() *schema.Resource {
394394
Description: " Set to 'true' to always suggest updating pull request branches.",
395395
},
396396
},
397+
CustomizeDiff: customDiffFunction,
397398
}
398399
}
399400

@@ -969,3 +970,10 @@ func resourceGithubParseFullName(resourceDataLike interface {
969970
}
970971
return parts[0], parts[1], true
971972
}
973+
974+
func customDiffFunction(diff *schema.ResourceDiff, v interface{}) error {
975+
if diff.HasChange("name") {
976+
diff.SetNewComputed("full_name")
977+
}
978+
return nil
979+
}

github/resource_github_repository_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010

1111
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
12+
"github.com/hashicorp/terraform-plugin-sdk/terraform"
1213

1314
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
1415
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
@@ -105,12 +106,20 @@ func TestAccGithubRepositories(t *testing.T) {
105106
"github_repository.test", "name",
106107
oldName,
107108
),
109+
resource.ComposeTestCheckFunc(
110+
testCheckResourceAttrContains("github_repository.test", "full_name",
111+
oldName),
112+
),
108113
),
109114
"after": resource.ComposeTestCheckFunc(
110115
resource.TestCheckResourceAttr(
111116
"github_repository.test", "name",
112117
newName,
113118
),
119+
resource.ComposeTestCheckFunc(
120+
testCheckResourceAttrContains("github_repository.test", "full_name",
121+
newName),
122+
),
114123
),
115124
}
116125

@@ -1426,3 +1435,23 @@ func TestResourceGithubParseFullName(t *testing.T) {
14261435
_, _, ok = resourceGithubParseFullName(resourceDataLike(map[string]interface{}{"full_name": "malformed"}))
14271436
assert.False(t, ok)
14281437
}
1438+
1439+
func testCheckResourceAttrContains(resourceName, attributeName, substring string) resource.TestCheckFunc {
1440+
return func(s *terraform.State) error {
1441+
rs, ok := s.RootModule().Resources[resourceName]
1442+
if !ok {
1443+
return fmt.Errorf("Resource not found: %s", resourceName)
1444+
}
1445+
1446+
value, ok := rs.Primary.Attributes[attributeName]
1447+
if !ok {
1448+
return fmt.Errorf("Attribute not found: %s", attributeName)
1449+
}
1450+
1451+
if !strings.Contains(value, substring) {
1452+
return fmt.Errorf("Attribute '%s' does not contain '%s'", value, substring)
1453+
}
1454+
1455+
return nil
1456+
}
1457+
}

0 commit comments

Comments
 (0)