@@ -844,6 +844,13 @@ resource "gitlab_project" "foo" {
844
844
},
845
845
),
846
846
},
847
+ // Verify Import
848
+ {
849
+ ResourceName : "gitlab_project.foo" ,
850
+ ImportState : true ,
851
+ ImportStateVerify : true ,
852
+ ImportStateVerifyIgnore : []string {"initialize_with_readme" },
853
+ },
847
854
},
848
855
})
849
856
}
@@ -883,6 +890,99 @@ func TestAccGitlabProject_CreateProjectInUserNamespace(t *testing.T) {
883
890
})
884
891
}
885
892
893
+ func TestAccGitlabProject_InstanceBranchProtectionDisabled (t * testing.T ) {
894
+ rInt := acctest .RandInt ()
895
+
896
+ resource .Test (t , resource.TestCase {
897
+ ProviderFactories : providerFactories ,
898
+ CheckDestroy : testAccCheckGitlabProjectDestroy ,
899
+ Steps : []resource.TestStep {
900
+ {
901
+ PreConfig : func () {
902
+ settings , _ , err := testGitlabClient .Settings .GetSettings ()
903
+ if err != nil {
904
+ t .Fatalf ("failed to get settings: %v" , err )
905
+ }
906
+ t .Cleanup (func () {
907
+ if _ , _ , err := testGitlabClient .Settings .UpdateSettings (& gitlab.UpdateSettingsOptions {DefaultBranchProtection : gitlab .Int (settings .DefaultBranchProtection )}); err != nil {
908
+ t .Fatalf ("failed to update instance-wide default branch protection setting to default: %v" , err )
909
+ }
910
+ })
911
+
912
+ if _ , _ , err := testGitlabClient .Settings .UpdateSettings (& gitlab.UpdateSettingsOptions {DefaultBranchProtection : gitlab .Int (0 )}); err != nil {
913
+ t .Fatalf ("failed to update instance-wide default branch protection setting: %v" , err )
914
+ }
915
+ },
916
+ Config : ` ` , // requires a space for empty config
917
+ },
918
+ // Without explicit default branch
919
+ {
920
+ Config : fmt .Sprintf (`
921
+ resource "gitlab_project" "foo" {
922
+ name = "foo-%d"
923
+ description = "Terraform acceptance tests"
924
+ visibility_level = "public"
925
+ initialize_with_readme = true
926
+ }
927
+ ` , rInt ),
928
+ },
929
+ // Verify Import
930
+ {
931
+ ResourceName : "gitlab_project.foo" ,
932
+ ImportState : true ,
933
+ ImportStateVerify : true ,
934
+ ImportStateVerifyIgnore : []string {"initialize_with_readme" },
935
+ },
936
+ // Force a destroy for the project so that it can be recreated as the same resource
937
+ {
938
+ Config : ` ` , // requires a space for empty config
939
+ },
940
+ // With explicit default branch set to instance-wide default
941
+ {
942
+ Config : fmt .Sprintf (`
943
+ resource "gitlab_project" "foo" {
944
+ name = "foo-%d"
945
+ description = "Terraform acceptance tests"
946
+ visibility_level = "public"
947
+ default_branch = "main"
948
+ initialize_with_readme = true
949
+ }
950
+ ` , rInt ),
951
+ },
952
+ // Verify Import
953
+ {
954
+ ResourceName : "gitlab_project.foo" ,
955
+ ImportState : true ,
956
+ ImportStateVerify : true ,
957
+ ImportStateVerifyIgnore : []string {"initialize_with_readme" },
958
+ },
959
+ // Force a destroy for the project so that it can be recreated as the same resource
960
+ {
961
+ Config : ` ` , // requires a space for empty config
962
+ },
963
+ // With custom default branch
964
+ {
965
+ Config : fmt .Sprintf (`
966
+ resource "gitlab_project" "foo" {
967
+ name = "foo-%d-custom-default-branch"
968
+ description = "Terraform acceptance tests"
969
+ visibility_level = "public"
970
+ default_branch = "foobar-non-default-branch"
971
+ initialize_with_readme = true
972
+ }
973
+ ` , rInt ),
974
+ },
975
+ // Verify Import
976
+ {
977
+ ResourceName : "gitlab_project.foo" ,
978
+ ImportState : true ,
979
+ ImportStateVerify : true ,
980
+ ImportStateVerifyIgnore : []string {"initialize_with_readme" },
981
+ },
982
+ },
983
+ })
984
+ }
985
+
886
986
type testAccGitlabProjectMirroredExpectedAttributes struct {
887
987
Mirror bool
888
988
MirrorTriggerBuilds bool
0 commit comments