func dataSourceGitlabProjectRead()

in internal/provider/sdk/data_source_gitlab_project.go [554:666]


func dataSourceGitlabProjectRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
	client := meta.(*gitlab.Client)

	tflog.Debug(ctx, "[INFO] Reading Gitlab project")

	var pid any
	if v, ok := d.GetOk("id"); ok {
		pid = v
	} else if v, ok := d.GetOk("path_with_namespace"); ok {
		pid = v
	} else {
		return diag.Errorf("Must specify either id or path_with_namespace")
	}

	found, _, err := client.Projects.GetProject(pid, nil, gitlab.WithContext(ctx))
	if err != nil {
		return diag.FromErr(err)
	}

	d.SetId(fmt.Sprintf("%d", found.ID))
	d.Set("name", found.Name)
	d.Set("path", found.Path)
	d.Set("path_with_namespace", found.PathWithNamespace)
	d.Set("description", found.Description)
	d.Set("default_branch", found.DefaultBranch)
	d.Set("request_access_enabled", found.RequestAccessEnabled)
	d.Set("issues_enabled", found.IssuesEnabled)                //nolint:staticcheck
	d.Set("merge_requests_enabled", found.MergeRequestsEnabled) //nolint:staticcheck
	d.Set("pipelines_enabled", found.JobsEnabled)               //nolint:staticcheck
	d.Set("wiki_enabled", found.WikiEnabled)                    //nolint:staticcheck
	d.Set("snippets_enabled", found.SnippetsEnabled)            //nolint:staticcheck
	d.Set("visibility_level", string(found.Visibility))
	d.Set("namespace_id", found.Namespace.ID)
	d.Set("ssh_url_to_repo", found.SSHURLToRepo)
	d.Set("http_url_to_repo", found.HTTPURLToRepo)
	d.Set("web_url", found.WebURL)
	d.Set("runners_token", found.RunnersToken)
	d.Set("empty_repo", found.EmptyRepo)
	d.Set("archived", found.Archived)
	d.Set("remove_source_branch_after_merge", found.RemoveSourceBranchAfterMerge)
	d.Set("restrict_user_defined_variables", found.RestrictUserDefinedVariables) //nolint:staticcheck
	d.Set("merge_pipelines_enabled", found.MergePipelinesEnabled)
	d.Set("merge_trains_enabled", found.MergeTrainsEnabled)
	d.Set("resolve_outdated_diff_discussions", found.ResolveOutdatedDiffDiscussions)
	d.Set("analytics_access_level", string(found.AnalyticsAccessLevel))
	d.Set("auto_cancel_pending_pipelines", found.AutoCancelPendingPipelines)
	d.Set("auto_devops_deploy_strategy", found.AutoDevopsDeployStrategy)
	d.Set("auto_devops_enabled", found.AutoDevopsEnabled)
	d.Set("autoclose_referenced_issues", found.AutocloseReferencedIssues)
	d.Set("build_git_strategy", found.BuildGitStrategy)
	d.Set("build_timeout", found.BuildTimeout)
	d.Set("builds_access_level", string(found.BuildsAccessLevel))
	if err := d.Set("container_expiration_policy", flattenContainerExpirationPolicy(found.ContainerExpirationPolicy)); err != nil {
		return diag.Errorf("error setting container_expiration_policy: %v", err)
	}
	d.Set("container_registry_access_level", string(found.ContainerRegistryAccessLevel))
	d.Set("external_authorization_classification_label", found.ExternalAuthorizationClassificationLabel)
	d.Set("forking_access_level", string(found.ForkingAccessLevel))
	d.Set("issues_access_level", string(found.IssuesAccessLevel))
	d.Set("merge_requests_access_level", string(found.MergeRequestsAccessLevel))
	d.Set("emails_enabled", found.EmailsEnabled)

	// Map PublicJobs -> PublicBuild until we have a breaking version.
	d.Set("public_builds", found.PublicJobs)
	d.Set("repository_access_level", string(found.RepositoryAccessLevel))
	d.Set("repository_storage", found.RepositoryStorage)
	d.Set("requirements_access_level", string(found.RequirementsAccessLevel))
	d.Set("security_and_compliance_access_level", string(found.SecurityAndComplianceAccessLevel))
	d.Set("snippets_access_level", string(found.SnippetsAccessLevel))
	d.Set("suggestion_commit_message", found.SuggestionCommitMessage)
	if err := d.Set("topics", found.Topics); err != nil {
		return diag.Errorf("error setting topics: %v", err)
	}
	d.Set("wiki_access_level", string(found.WikiAccessLevel))
	d.Set("squash_commit_template", found.SquashCommitTemplate)
	d.Set("merge_commit_template", found.MergeCommitTemplate)
	d.Set("allow_pipeline_trigger_approve_deployment", found.AllowPipelineTriggerApproveDeployment)
	d.Set("ci_default_git_depth", found.CIDefaultGitDepth)
	d.Set("ci_delete_pipelines_in_seconds", found.CIDeletePipelinesInSeconds)
	d.Set("ci_config_path", found.CIConfigPath)
	d.Set("ci_separated_caches", found.CISeperateCache)
	if err := d.Set("ci_id_token_sub_claim_components", found.CIIdTokenSubClaimComponents); err != nil {
		return diag.Errorf("error setting ci_id_token_sub_claim_components: %v", err)
	}
	d.Set("ci_restrict_pipeline_cancellation_role", found.CIRestrictPipelineCancellationRole)
	d.Set("ci_pipeline_variables_minimum_override_role", found.CIPipelineVariablesMinimumOverrideRole)
	d.Set("keep_latest_artifact", found.KeepLatestArtifact)
	d.Set("import_url", found.ImportURL)
	d.Set("releases_access_level", string(found.ReleasesAccessLevel))
	d.Set("environments_access_level", string(found.EnvironmentsAccessLevel))
	d.Set("feature_flags_access_level", string(found.FeatureFlagsAccessLevel))
	d.Set("infrastructure_access_level", string(found.InfrastructureAccessLevel))
	d.Set("monitor_access_level", string(found.MonitorAccessLevel))
	d.Set("model_experiments_access_level", string(found.ModelExperimentsAccessLevel))
	d.Set("model_registry_access_level", string(found.ModelRegistryAccessLevel))
	d.Set("prevent_merge_without_jira_issue", found.PreventMergeWithoutJiraIssue)

	tflog.Debug(ctx, fmt.Sprintf("[DEBUG] Reading Gitlab project %q push rules", d.Id()))

	pushRules, _, err := client.Projects.GetProjectPushRules(d.Id(), gitlab.WithContext(ctx))
	if api.Is404(err) || api.Is403(err) {
		tflog.Debug(ctx, fmt.Sprintf("[DEBUG] Failed to get push rules for project %q: %v", d.Id(), err))
	} else if err != nil {
		return diag.Errorf("Failed to get push rules for project %q: %v", d.Id(), err)
	}

	d.Set("push_rules", flattenProjectPushRules(pushRules)) // lintignore: XR004 // TODO: Resolve this tfproviderlint issue

	if err := d.Set("shared_with_groups", flattenProjectSharedWithGroups(found)); err != nil {
		return diag.FromErr(err)
	}
	return nil
}