func()

in teamcity/provider.go [67:167]


func (p *teamcityProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
	var config teamcityProviderModel
	diags := req.Config.Get(ctx, &config)
	resp.Diagnostics.Append(diags...)
	if resp.Diagnostics.HasError() {
		return
	}

	if config.Host.IsUnknown() {
		resp.Diagnostics.AddAttributeError(
			path.Root("host"),
			"Unknown TeamCity Host",
			"",
		)
	}
	if config.Token.IsUnknown() {
		resp.Diagnostics.AddAttributeError(
			path.Root("token"),
			"Unknown TeamCity API token",
			"",
		)
	}
	if config.Token.IsUnknown() {
		resp.Diagnostics.AddAttributeError(
			path.Root("username"),
			"Unknown TeamCity username",
			"",
		)
	}
	if config.Token.IsUnknown() {
		resp.Diagnostics.AddAttributeError(
			path.Root("password"),
			"Unknown TeamCity password",
			"",
		)
	}
	if resp.Diagnostics.HasError() {
		return
	}

	host := os.Getenv("TEAMCITY_HOST")
	token := os.Getenv("TEAMCITY_TOKEN")
	username := os.Getenv("TEAMCITY_USERNAME")
	password := os.Getenv("TEAMCITY_PASSWORD")
	maxRetries := MaxRetriesDefault

	if !config.Host.IsNull() {
		host = config.Host.ValueString()
	}
	if !config.Token.IsNull() {
		token = config.Token.ValueString()
	}
	if !config.Username.IsNull() {
		username = config.Username.ValueString()
	}
	if !config.Password.IsNull() {
		password = config.Password.ValueString()
	}

	if host == "" {
		resp.Diagnostics.AddAttributeError(
			path.Root("host"),
			"Missing TeamCity Host",
			"",
		)
	}
	if token == "" && username == "" && password == "" {
		resp.Diagnostics.AddAttributeError(
			path.Root("token"),
			"Missing TeamCity API Token",
			"",
		)
	}

	if resp.Diagnostics.HasError() {
		return
	}

	if !config.MaxRetries.IsNull() {
		var bigInt big.Int
		config.MaxRetries.ValueBigFloat().Int(&bigInt)
		maxRetries = int(bigInt.Int64())
	}

	cl := client.NewClient(host, token, username, password, maxRetries)
	_, err := cl.VerifyConnection(ctx)

	if err != nil {
		resp.Diagnostics.AddError(
			"Could not verify connection to server",
			fmt.Sprint(err),
		)
	}

	if resp.Diagnostics.HasError() {
		return
	}

	resp.DataSourceData = &cl
	resp.ResourceData = &cl
}