@@ -127,7 +127,6 @@ func testTenantCommonVariableExists(resourceName string) resource.TestCheckFunc
127127 return fmt .Errorf ("Library variable ID is not set" )
128128 }
129129
130- // Check if this is a V2 ID (no colons) or V1 ID (has colons)
131130 if ! strings .Contains (rs .Primary .ID , ":" ) {
132131 tenantID := rs .Primary .Attributes ["tenant_id" ]
133132 spaceID := rs .Primary .Attributes ["space_id" ]
@@ -144,7 +143,6 @@ func testTenantCommonVariableExists(resourceName string) resource.TestCheckFunc
144143 return fmt .Errorf ("Error retrieving tenant common variables: %s" , err .Error ())
145144 }
146145
147- // Search for the variable by ID
148146 for _ , v := range getResp .Variables {
149147 if v .GetID () == rs .Primary .ID {
150148 return nil
@@ -154,7 +152,6 @@ func testTenantCommonVariableExists(resourceName string) resource.TestCheckFunc
154152 return fmt .Errorf ("Tenant common variable with ID %s not found via V2 API" , rs .Primary .ID )
155153 }
156154
157- // V1 API - use composite ID
158155 importStrings := strings .Split (rs .Primary .ID , ":" )
159156 if len (importStrings ) != 3 {
160157 return fmt .Errorf ("octopusdeploy_tenant_common_variable import must be in the form of TenantID:LibraryVariableSetID:VariableID (e.g. Tenants-123:LibraryVariableSets-456:6c9f2ba3-3ccd-407f-bbdf-6618e4fd0a0c" )
@@ -190,9 +187,7 @@ func testAccTenantCommonVariableCheckDestroy(s *terraform.State) error {
190187 continue
191188 }
192189
193- // Check if this is a V2 ID (no colons) or V1 ID (has colons)
194190 if ! strings .Contains (rs .Primary .ID , ":" ) {
195- // V2 API - use real ID
196191 tenantID := rs .Primary .Attributes ["tenant_id" ]
197192 spaceID := rs .Primary .Attributes ["space_id" ]
198193
@@ -205,11 +200,9 @@ func testAccTenantCommonVariableCheckDestroy(s *terraform.State) error {
205200
206201 getResp , err := tenants .GetCommonVariables (client , query )
207202 if err != nil {
208- // If we can't get the variables, assume they're gone
209203 return nil
210204 }
211205
212- // Search for the variable by ID
213206 for _ , v := range getResp .Variables {
214207 if v .GetID () == rs .Primary .ID {
215208 return fmt .Errorf ("Tenant common variable (%s) still exists" , rs .Primary .ID )
@@ -219,7 +212,6 @@ func testAccTenantCommonVariableCheckDestroy(s *terraform.State) error {
219212 continue
220213 }
221214
222- // V1 API - use composite ID
223215 importStrings := strings .Split (rs .Primary .ID , ":" )
224216 if len (importStrings ) != 3 {
225217 return fmt .Errorf ("octopusdeploy_tenant_common_variable import must be in the form of TenantID:LibraryVariableSetID:VariableID (e.g. Tenants-123:LibraryVariableSets-456:6c9f2ba3-3ccd-407f-bbdf-6618e4fd0a0c" )
@@ -276,7 +268,6 @@ func TestAccTenantCommonVariableMigration(t *testing.T) {
276268 PreCheck : func () { TestAccPreCheck (t ) },
277269 Steps : []resource.TestStep {
278270 {
279- // Step 1: Create with V1 API (force V2 API off)
280271 ProtoV6ProviderFactories : ProtoV6ProviderFactoriesWithFeatureToggleOverrides (map [string ]bool {
281272 "CommonVariableScopingFeatureToggle" : false ,
282273 }),
@@ -286,7 +277,6 @@ func TestAccTenantCommonVariableMigration(t *testing.T) {
286277 resource .TestCheckNoResourceAttr (resourceName , "scope.#" ),
287278 func (s * terraform.State ) error {
288279 rs := s .RootModule ().Resources [resourceName ]
289- // Verify it's a V1 composite ID (has colons)
290280 if ! strings .Contains (rs .Primary .ID , ":" ) {
291281 return fmt .Errorf ("Expected V1 composite ID with colons, got: %s" , rs .Primary .ID )
292282 }
@@ -296,7 +286,6 @@ func TestAccTenantCommonVariableMigration(t *testing.T) {
296286 Config : testAccTenantCommonVariableMigrationV1 (lifecycleLocalName , lifecycleName , projectGroupLocalName , projectGroupName , projectLocalName , projectName , env1LocalName , env1Name , env2LocalName , env2Name , tenantLocalName , tenantName , tenantVariablesLocalName , value ),
297287 },
298288 {
299- // Step 2: Migrate to V2 API by adding scope block (enable V2 API)
300289 ProtoV6ProviderFactories : ProtoV6ProviderFactoriesWithFeatureToggleOverrides (map [string ]bool {
301290 "CommonVariableScopingFeatureToggle" : true ,
302291 }),
@@ -307,7 +296,6 @@ func TestAccTenantCommonVariableMigration(t *testing.T) {
307296 resource .TestCheckResourceAttr (resourceName , "scope.0.environment_ids.#" , "2" ),
308297 func (s * terraform.State ) error {
309298 rs := s .RootModule ().Resources [resourceName ]
310- // Verify it's a V2 real ID (no colons)
311299 if strings .Contains (rs .Primary .ID , ":" ) {
312300 return fmt .Errorf ("Expected V2 real ID without colons, got: %s" , rs .Primary .ID )
313301 }
@@ -317,7 +305,6 @@ func TestAccTenantCommonVariableMigration(t *testing.T) {
317305 Config : testAccTenantCommonVariableMigrationV2 (lifecycleLocalName , lifecycleName , projectGroupLocalName , projectGroupName , projectLocalName , projectName , env1LocalName , env1Name , env2LocalName , env2Name , tenantLocalName , tenantName , tenantVariablesLocalName , newValue ),
318306 },
319307 {
320- // Step 3: Update value again to verify it works after migration
321308 ProtoV6ProviderFactories : ProtoV6ProviderFactoriesWithFeatureToggleOverrides (map [string ]bool {
322309 "CommonVariableScopingFeatureToggle" : true ,
323310 }),
@@ -328,7 +315,6 @@ func TestAccTenantCommonVariableMigration(t *testing.T) {
328315 resource .TestCheckResourceAttr (resourceName , "scope.0.environment_ids.#" , "2" ),
329316 func (s * terraform.State ) error {
330317 rs := s .RootModule ().Resources [resourceName ]
331- // Verify still using V2 ID
332318 if strings .Contains (rs .Primary .ID , ":" ) {
333319 return fmt .Errorf ("Expected V2 real ID without colons, got: %s" , rs .Primary .ID )
334320 }
@@ -476,7 +462,6 @@ func TestAccTenantCommonVariableWithScope(t *testing.T) {
476462 ProtoV6ProviderFactories : ProtoV6ProviderFactories (),
477463 Steps : []resource.TestStep {
478464 {
479- // Create with scope
480465 Check : resource .ComposeTestCheckFunc (
481466 testTenantCommonVariableExistsV2 (resourceName ),
482467 resource .TestCheckResourceAttr (resourceName , "value" , value ),
@@ -486,7 +471,6 @@ func TestAccTenantCommonVariableWithScope(t *testing.T) {
486471 Config : testAccTenantCommonVariableWithScope (lifecycleLocalName , lifecycleName , projectGroupLocalName , projectGroupName , projectLocalName , projectName , env1LocalName , env1Name , env2LocalName , env2Name , tenantLocalName , tenantName , tenantVariablesLocalName , value ),
487472 },
488473 {
489- // Update value
490474 Check : resource .ComposeTestCheckFunc (
491475 testTenantCommonVariableExistsV2 (resourceName ),
492476 resource .TestCheckResourceAttr (resourceName , "value" , newValue ),
@@ -566,12 +550,10 @@ func testTenantCommonVariableExistsV2(resourceName string) resource.TestCheckFun
566550 return fmt .Errorf ("Tenant common variable ID is not set" )
567551 }
568552
569- // V2 uses real IDs (e.g., TenantVariables-123), not composite IDs with colons
570553 if strings .Contains (rs .Primary .ID , ":" ) {
571554 return fmt .Errorf ("Expected V2 ID (e.g., TenantVariables-123) but got V1 composite ID: %s" , rs .Primary .ID )
572555 }
573556
574- // Use V2 API to verify the variable exists
575557 tenantID := rs .Primary .Attributes ["tenant_id" ]
576558 spaceID := rs .Primary .Attributes ["space_id" ]
577559
@@ -587,7 +569,6 @@ func testTenantCommonVariableExistsV2(resourceName string) resource.TestCheckFun
587569 return fmt .Errorf ("Error retrieving tenant common variables: %s" , err .Error ())
588570 }
589571
590- // Search for the variable by ID
591572 for _ , v := range getResp .Variables {
592573 if v .GetID () == rs .Primary .ID {
593574 return nil
@@ -605,9 +586,7 @@ func testAccTenantCommonVariableCheckDestroyV2(s *terraform.State) error {
605586 continue
606587 }
607588
608- // V2 uses real IDs, not composite IDs
609589 if strings .Contains (rs .Primary .ID , ":" ) {
610- // This is a V1 ID, use V1 destroy check
611590 continue
612591 }
613592
@@ -623,11 +602,9 @@ func testAccTenantCommonVariableCheckDestroyV2(s *terraform.State) error {
623602
624603 getResp , err := tenants .GetCommonVariables (client , query )
625604 if err != nil {
626- // If we can't get the variables, assume they're gone
627605 return nil
628606 }
629607
630- // Search for the variable by ID
631608 for _ , v := range getResp .Variables {
632609 if v .GetID () == rs .Primary .ID {
633610 return fmt .Errorf ("Tenant common variable (%s) still exists" , rs .Primary .ID )
0 commit comments