@@ -1198,6 +1198,156 @@ func TestRegistryModulesCreateMonorepoTagBasedWithVCSConnection(t *testing.T) {
11981198 })
11991199}
12001200
1201+ func TestRegistryModulesCreateMonorepoNonStandardName (t * testing.T ) {
1202+ t .Parallel ()
1203+ skipUnlessBeta (t )
1204+
1205+ // This test uses a repository like "private-modules" or "monorepo" that doesn't
1206+ // follow the terraform-<provider>-<name> pattern, which would previously fail
1207+ // with "Name is invalid" error.
1208+ githubIdentifier := os .Getenv ("GITHUB_REGISTRY_MODULE_IDENTIFIER" )
1209+ if githubIdentifier == "" {
1210+ t .Skip ("Export a valid GITHUB_REGISTRY_MODULE_IDENTIFIER before running this test" )
1211+ }
1212+
1213+ githubBranch := os .Getenv ("GITHUB_REGISTRY_MODULE_BRANCH" )
1214+ if githubBranch == "" {
1215+ githubBranch = "main"
1216+ }
1217+
1218+ client := testClient (t )
1219+ ctx := context .Background ()
1220+
1221+ orgTest , orgTestCleanup := createOrganization (t , client )
1222+ t .Cleanup (orgTestCleanup )
1223+
1224+ oauthTokenTest , oauthTokenTestCleanup := createOAuthToken (t , client , orgTest )
1225+ t .Cleanup (oauthTokenTestCleanup )
1226+
1227+ t .Run ("with explicit name and provider for monorepo with tags" , func (t * testing.T ) {
1228+ sourceDirectory := "modules/nestedA"
1229+ moduleName := "nestedA"
1230+ moduleProvider := "aws"
1231+
1232+ options := RegistryModuleCreateWithVCSConnectionOptions {
1233+ Name : String (moduleName ),
1234+ Provider : String (moduleProvider ),
1235+ VCSRepo : & RegistryModuleVCSRepoOptions {
1236+ OrganizationName : String (orgTest .Name ),
1237+ Identifier : String (githubIdentifier ),
1238+ OAuthTokenID : String (oauthTokenTest .ID ),
1239+ DisplayIdentifier : String (githubIdentifier ),
1240+ SourceDirectory : String (sourceDirectory ),
1241+ Tags : Bool (true ),
1242+ },
1243+ }
1244+ rm , err := client .RegistryModules .CreateWithVCSConnection (ctx , options )
1245+ require .NoError (t , err )
1246+ assert .NotEmpty (t , rm .ID )
1247+ assert .Equal (t , moduleName , rm .Name )
1248+ assert .Equal (t , moduleProvider , rm .Provider )
1249+ assert .Equal (t , sourceDirectory , rm .VCSRepo .SourceDirectory )
1250+ assert .Equal (t , true , rm .VCSRepo .Tags )
1251+ })
1252+
1253+ t .Run ("with explicit name and provider for monorepo with branch" , func (t * testing.T ) {
1254+ sourceDirectory := "modules/nestedB"
1255+ moduleName := "nestedB"
1256+ moduleProvider := "gcp"
1257+
1258+ options := RegistryModuleCreateWithVCSConnectionOptions {
1259+ Name : String (moduleName ),
1260+ Provider : String (moduleProvider ),
1261+ VCSRepo : & RegistryModuleVCSRepoOptions {
1262+ OrganizationName : String (orgTest .Name ),
1263+ Identifier : String (githubIdentifier ),
1264+ OAuthTokenID : String (oauthTokenTest .ID ),
1265+ DisplayIdentifier : String (githubIdentifier ),
1266+ Branch : String (githubBranch ),
1267+ SourceDirectory : String (sourceDirectory ),
1268+ },
1269+ }
1270+ rm , err := client .RegistryModules .CreateWithVCSConnection (ctx , options )
1271+ require .NoError (t , err )
1272+ assert .NotEmpty (t , rm .ID )
1273+ assert .Equal (t , moduleName , rm .Name )
1274+ assert .Equal (t , moduleProvider , rm .Provider )
1275+ assert .Equal (t , sourceDirectory , rm .VCSRepo .SourceDirectory )
1276+ assert .Equal (t , githubBranch , rm .VCSRepo .Branch )
1277+ assert .Equal (t , false , rm .VCSRepo .Tags )
1278+ })
1279+
1280+ t .Run ("with explicit name and provider for deeply nested path" , func (t * testing.T ) {
1281+ sourceDirectory := "terraform/modules/aws/compute"
1282+ moduleName := "compute"
1283+ moduleProvider := "aws"
1284+
1285+ options := RegistryModuleCreateWithVCSConnectionOptions {
1286+ Name : String (moduleName ),
1287+ Provider : String (moduleProvider ),
1288+ VCSRepo : & RegistryModuleVCSRepoOptions {
1289+ OrganizationName : String (orgTest .Name ),
1290+ Identifier : String (githubIdentifier ),
1291+ OAuthTokenID : String (oauthTokenTest .ID ),
1292+ DisplayIdentifier : String (githubIdentifier ),
1293+ Branch : String (githubBranch ),
1294+ SourceDirectory : String (sourceDirectory ),
1295+ },
1296+ }
1297+ rm , err := client .RegistryModules .CreateWithVCSConnection (ctx , options )
1298+ require .NoError (t , err )
1299+ assert .NotEmpty (t , rm .ID )
1300+ assert .Equal (t , moduleName , rm .Name )
1301+ assert .Equal (t , moduleProvider , rm .Provider )
1302+ assert .Equal (t , sourceDirectory , rm .VCSRepo .SourceDirectory )
1303+ })
1304+
1305+ t .Run ("with explicit name and provider for various providers" , func (t * testing.T ) {
1306+ testCases := []struct {
1307+ name string
1308+ moduleName string
1309+ moduleProvider string
1310+ sourceDirectory string
1311+ }{
1312+ {
1313+ name : "azurerm provider" ,
1314+ moduleName : "vnet" ,
1315+ moduleProvider : "azurerm" ,
1316+ sourceDirectory : "modules/azure-vnet" ,
1317+ },
1318+ {
1319+ name : "random provider" ,
1320+ moduleName : "pet" ,
1321+ moduleProvider : "random" ,
1322+ sourceDirectory : "modules/random-pet" ,
1323+ },
1324+ }
1325+
1326+ for _ , tc := range testCases {
1327+ t .Run (tc .name , func (t * testing.T ) {
1328+ options := RegistryModuleCreateWithVCSConnectionOptions {
1329+ Name : String (tc .moduleName ),
1330+ Provider : String (tc .moduleProvider ),
1331+ VCSRepo : & RegistryModuleVCSRepoOptions {
1332+ OrganizationName : String (orgTest .Name ),
1333+ Identifier : String (githubIdentifier ),
1334+ OAuthTokenID : String (oauthTokenTest .ID ),
1335+ DisplayIdentifier : String (githubIdentifier ),
1336+ Branch : String (githubBranch ),
1337+ SourceDirectory : String (tc .sourceDirectory ),
1338+ },
1339+ }
1340+ rm , err := client .RegistryModules .CreateWithVCSConnection (ctx , options )
1341+ require .NoError (t , err )
1342+ assert .NotEmpty (t , rm .ID )
1343+ assert .Equal (t , tc .moduleName , rm .Name )
1344+ assert .Equal (t , tc .moduleProvider , rm .Provider )
1345+ assert .Equal (t , tc .sourceDirectory , rm .VCSRepo .SourceDirectory )
1346+ })
1347+ }
1348+ })
1349+ }
1350+
12011351func TestRegistryModulesCreateBranchBasedWithVCSConnectionWithTesting (t * testing.T ) {
12021352 t .Parallel ()
12031353 skipUnlessBeta (t )
0 commit comments