Not all plugins are compatible with the Configurations as Code plugin, the Logstash plugin can be enabled via CasC but the indexer type cannot be configured. This groovy-hook can be used as a workaround, in this example i've configured the indexer type as Elasticsearch.
Compatibility with CasC can be tracked here.
This script can be added to the init.groovy.d/
directory within Jenkins, scripts added to this directory will be executed in the very end of the Jenkins initialization.
Remember that the URI is hardcoded in the example below, if you have some experience running Jenkins as Code you might already have a property file that you read through for each groovy-script to configure different parts of Jenkins aswell as plugins.
import jenkins.model.Jenkins
import jenkins.plugins.logstash.configuration.*
import jenkins.plugins.logstash.*
import org.apache.http.client.utils.URIBuilder
def inst = Jenkins.getInstance()
def desc = inst.getDescriptor("jenkins.plugins.logstash.LogstashConfiguration")
if(! desc.isEnabled()) {
desc.setEnabled(true)
}
uri = (new URIBuilder("http://elasticsearch:9200/jenkins/jobs").build())
ElasticSearch es = new ElasticSearch()
es.setUri(uri)
desc.setLogstashIndexer(es)
desc.save()