INNER CODE UNIT · Go
createCertificate
hashicorp/terraform-provider-tls · internal/provider/common_cert.go:114
func createCertificate(ctx context.Context, template, parent *x509.Certificate, pubKey crypto.PublicKey, prvKey crypto.PrivateKey, plan *tfsdk.Plan) (*commonCertificate, diag.Diagnostics) {
var err error
var diags diag.Diagnostics
// Set not-before and not-after limits on the certificate template
validityPeriodHoursPath := path.Root("validity_period_hours")
var validityPeriodHours int64
diags.Append(plan.GetAttribute(ctx, validityPeriodHoursPath, &validityPeriodHours)...)
if diags.HasError() {
return nil, diags
}
template.NotBefore = overridableTimeFunc()
template.NotAfter = template.NotBefore.Add(time.Duration(validityPeriodHours) * time.Hour)
// Set serial-number on the template
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
template.SerialNumber, err = rand.Int(rand.Reader, serialNumberLimit)
if err != nil {