func()

in teamcity/ssh_key.go [88:126]


func (r *sshKeyResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
	var state sshKeyResourceModel
	diags := req.State.Get(ctx, &state)
	resp.Diagnostics.Append(diags...)
	if resp.Diagnostics.HasError() {
		return
	}

	actual, err := r.client.GetSshKeys(state.Project.ValueString())
	if err != nil {
		resp.Diagnostics.AddError(
			"Error Reading SSH keys",
			err.Error(),
		)
		return
	}

	if actual == nil {
		resp.State.RemoveResource(ctx)
		return
	}

	if !contains2(actual, state.Name.ValueString()) {
		resp.State.RemoveResource(ctx)
		return
	}

	newState := sshKeyResourceModel{
		Project: state.Project,
		Name:    state.Name,
		Key:     state.Key,
	}

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