forked from taiidani/terraform-provider-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
jenkins_plugins
data resource (#2)
- Loading branch information
1 parent
e5f661b
commit f3f44e1
Showing
5 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# jenkins_plugin Data Source | ||
|
||
Get the information of plugins within Jenkins. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "jenkins_plugins" "example" {} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - Fixed value: `jenkins-data-source-plugins-id`. | ||
* `plugins` - The list of the Jenkins plugins. | ||
* `name` - The name of plugin. | ||
* `version` - The version of plugin. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package jenkins | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceJenkinsPlugins() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourcePluginsRead, | ||
Schema: map[string]*schema.Schema{ | ||
"plugins": { | ||
Type: schema.TypeList, | ||
Description: "The list of the Jenkins plugins.", | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"version": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourcePluginsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client := meta.(*jenkinsAdapter) | ||
|
||
p, err := client.GetPlugins(ctx, 1) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
var plugins []map[string]string | ||
for _, v := range p.Raw.Plugins { | ||
p := make(map[string]string) | ||
p["name"] = v.ShortName | ||
p["version"] = v.Version | ||
plugins = append(plugins, p) | ||
} | ||
|
||
if err := d.Set("plugins", plugins); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId("jenkins-data-source-plugins-id") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package jenkins | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccJenkinsPluginsDataSource_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: "data jenkins_plugins foo {}", | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.jenkins_plugins.foo", "id", "jenkins-data-source-plugins-id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters