func()

in teamcity/vcsroot.go [212:355]


func (r *vcsRootResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
	var plan vcsRootResourceModel
	diags := req.Plan.Get(ctx, &plan)
	resp.Diagnostics.Append(diags...)
	if resp.Diagnostics.HasError() {
		return
	}

	var id *string
	if plan.Id.IsUnknown() {
		id = nil
	} else {
		val := plan.Id.ValueString()
		id = &val
	}

	root := client.VcsRoot{
		Name:    plan.Name.ValueString(),
		Id:      id,
		VcsName: "jetbrains.git",
		Project: client.ProjectLocator{
			Id: plan.ProjectId.ValueString(),
		},
	}

	props := []models.Property{
		{Name: "url", Value: plan.Git.Url.ValueString()},
		{Name: "branch", Value: plan.Git.Branch.ValueString()},
	}

	if plan.Git.PushUrl.IsNull() != true {
		props = append(props, models.Property{Name: "push_url", Value: plan.Git.PushUrl.ValueString()})
	}

	if plan.Git.BranchSpec.IsNull() != true {
		props = append(props, models.Property{Name: "teamcity:branchSpec", Value: plan.Git.BranchSpec.ValueString()})
	}

	if plan.Git.TagsAsBranches.IsNull() != true {
		val := strconv.FormatBool(plan.Git.TagsAsBranches.ValueBool())
		props = append(props, models.Property{Name: "reportTagRevisions", Value: val})
	}

	if plan.Git.UsernameStyle.IsNull() != true {
		props = append(props, models.Property{Name: "usernameStyle", Value: plan.Git.UsernameStyle.ValueString()})
	}

	if plan.Git.Submodules.IsNull() != true {
		props = append(props, models.Property{Name: "submoduleCheckout", Value: plan.Git.Submodules.ValueString()})
	}

	if plan.Git.UsernameForTags.IsNull() != true {
		props = append(props, models.Property{Name: "userForTags", Value: plan.Git.UsernameForTags.ValueString()})
	}

	if plan.Git.AuthMethod.IsNull() != true {
		props = append(props, models.Property{Name: "authMethod", Value: plan.Git.AuthMethod.ValueString()})
	}

	if plan.Git.Username.IsNull() != true {
		props = append(props, models.Property{Name: "username", Value: plan.Git.Username.ValueString()})
	}

	if plan.Git.Password.IsNull() != true {
		props = append(props, models.Property{Name: "secure:password", Value: plan.Git.Password.ValueString()})
	}

	if plan.Git.UploadedKey.IsNull() != true {
		props = append(props, models.Property{Name: "teamcitySshKey", Value: plan.Git.UploadedKey.ValueString()})
	}

	if plan.Git.PrivateKeyPath.IsNull() != true {
		props = append(props, models.Property{Name: "privateKeyPath", Value: plan.Git.PrivateKeyPath.ValueString()})
	}

	if plan.Git.Passphrase.IsNull() != true {
		props = append(props, models.Property{Name: "secure:passphrase", Value: plan.Git.Passphrase.ValueString()})
	}

	if plan.Git.IgnoreKnownHosts.IsNull() != true {
		val := strconv.FormatBool(plan.Git.IgnoreKnownHosts.ValueBool())
		props = append(props, models.Property{Name: "ignoreKnownHosts", Value: val})
	}

	if plan.Git.ConvertCrlf.IsNull() != true {
		val := strconv.FormatBool(plan.Git.ConvertCrlf.ValueBool())
		props = append(props, models.Property{Name: "serverSideAutoCrlf", Value: val})
	}

	if plan.Git.PathToGit.IsNull() != true {
		props = append(props, models.Property{Name: "agentGitPath", Value: plan.Git.PathToGit.ValueString()})
	}

	if plan.Git.CheckoutPolicy.IsNull() != true {
		props = append(props, models.Property{Name: "useAlternates", Value: plan.Git.CheckoutPolicy.ValueString()})
	}

	if plan.Git.CleanPolicy.IsNull() != true {
		props = append(props, models.Property{Name: "agentCleanPolicy", Value: plan.Git.CleanPolicy.ValueString()})
	}

	if plan.Git.CleanFilesPolicy.IsNull() != true {
		props = append(props, models.Property{Name: "agentCleanFilesPolicy", Value: plan.Git.CleanFilesPolicy.ValueString()})
	}

	if plan.Git.TokenId.IsNull() != true {
		props = append(props, models.Property{Name: "tokenId", Value: plan.Git.TokenId.ValueString()})
	}

	root.Properties = models.Properties{
		Property: props,
	}

	if plan.PollingInterval.IsNull() != true {
		val := int(plan.PollingInterval.ValueInt64())
		root.PollingInterval = &val
	}

	actual, err := r.client.NewVcsRoot(root)
	if err != nil {
		resp.Diagnostics.AddError(
			"Error setting VCS root",
			err.Error(),
		)
		return
	}

	newState, err := r.readState(actual)
	if err != nil {
		resp.Diagnostics.AddError(
			"REST returned invalid value: ",
			err.Error(),
		)
		return
	}
	newState.Git.Password = plan.Git.Password
	newState.Git.Passphrase = plan.Git.Passphrase

	diags = resp.State.Set(ctx, newState)
	resp.Diagnostics.Append(diags...)
	if resp.Diagnostics.HasError() {
		return
	}
}