|
6 | 6 |
|
7 | 7 | "github.com/hashicorp/terraform-plugin-testing/helper/acctest" |
8 | 8 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 9 | + "github.com/hashicorp/terraform-plugin-testing/terraform" |
9 | 10 | ) |
10 | 11 |
|
11 | 12 | func TestAccGithubRepositoryCustomProperty(t *testing.T) { |
@@ -135,6 +136,79 @@ func TestAccGithubRepositoryCustomProperty(t *testing.T) { |
135 | 136 | }) |
136 | 137 | }) |
137 | 138 |
|
| 139 | + t.Run("updates custom property value in place without replacement", func(t *testing.T) { |
| 140 | + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) |
| 141 | + repoName := fmt.Sprintf("%srepo-custom-prop-%s", testResourcePrefix, randomID) |
| 142 | + propertyName := fmt.Sprintf("tf-acc-test-property-%s", randomID) |
| 143 | + |
| 144 | + configTemplate := ` |
| 145 | + resource "github_organization_custom_properties" "test" { |
| 146 | + allowed_values = ["alpha", "beta"] |
| 147 | + description = "Test Description" |
| 148 | + property_name = "%s" |
| 149 | + value_type = "single_select" |
| 150 | + } |
| 151 | + resource "github_repository" "test" { |
| 152 | + name = "%s" |
| 153 | + auto_init = true |
| 154 | + } |
| 155 | + resource "github_repository_custom_property" "test" { |
| 156 | + repository = github_repository.test.name |
| 157 | + property_name = github_organization_custom_properties.test.property_name |
| 158 | + property_type = github_organization_custom_properties.test.value_type |
| 159 | + property_value = ["%s"] |
| 160 | + } |
| 161 | + ` |
| 162 | + |
| 163 | + configAlpha := fmt.Sprintf(configTemplate, propertyName, repoName, "alpha") |
| 164 | + configBeta := fmt.Sprintf(configTemplate, propertyName, repoName, "beta") |
| 165 | + |
| 166 | + var firstID string |
| 167 | + |
| 168 | + resource.Test(t, resource.TestCase{ |
| 169 | + PreCheck: func() { skipUnlessHasOrgs(t) }, |
| 170 | + ProviderFactories: providerFactories, |
| 171 | + Steps: []resource.TestStep{ |
| 172 | + { |
| 173 | + Config: configAlpha, |
| 174 | + Check: resource.ComposeTestCheckFunc( |
| 175 | + resource.TestCheckResourceAttr("github_repository_custom_property.test", "property_value.#", "1"), |
| 176 | + resource.TestCheckResourceAttr("github_repository_custom_property.test", "property_value.0", "alpha"), |
| 177 | + func(s *terraform.State) error { |
| 178 | + rs, ok := s.RootModule().Resources["github_repository_custom_property.test"] |
| 179 | + if !ok { |
| 180 | + return fmt.Errorf("resource not found in state") |
| 181 | + } |
| 182 | + firstID = rs.Primary.ID |
| 183 | + return nil |
| 184 | + }, |
| 185 | + ), |
| 186 | + }, |
| 187 | + { |
| 188 | + Config: configBeta, |
| 189 | + Check: resource.ComposeTestCheckFunc( |
| 190 | + resource.TestCheckResourceAttr("github_repository_custom_property.test", "property_value.#", "1"), |
| 191 | + resource.TestCheckResourceAttr("github_repository_custom_property.test", "property_value.0", "beta"), |
| 192 | + func(s *terraform.State) error { |
| 193 | + rs, ok := s.RootModule().Resources["github_repository_custom_property.test"] |
| 194 | + if !ok { |
| 195 | + return fmt.Errorf("resource not found in state") |
| 196 | + } |
| 197 | + if rs.Primary.ID != firstID { |
| 198 | + return fmt.Errorf("resource ID changed across update: %q -> %q (expected in-place update)", firstID, rs.Primary.ID) |
| 199 | + } |
| 200 | + return nil |
| 201 | + }, |
| 202 | + ), |
| 203 | + }, |
| 204 | + { |
| 205 | + Config: configBeta, |
| 206 | + PlanOnly: true, |
| 207 | + }, |
| 208 | + }, |
| 209 | + }) |
| 210 | + }) |
| 211 | + |
138 | 212 | t.Run("creates custom property of type string without error", func(t *testing.T) { |
139 | 213 | randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) |
140 | 214 | repoName := fmt.Sprintf("%srepo-custom-prop-%s", testResourcePrefix, randomID) |
|
0 commit comments