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 remaining data resources (taiidani#28)
* Add data sources for remaining resources * Test fix * Fix the test fix
- Loading branch information
Showing
12 changed files
with
488 additions
and
9 deletions.
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,28 @@ | ||
# jenkins_credential_username Data Source | ||
|
||
Get the attributes of a username credential within Jenkins. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data jenkins_credential_username example { | ||
name = "job-name" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name of the resource being read. | ||
* `domain` - (Optional) The domain store to place the credentials into. If not set will default to the global credentials store. | ||
* `folder` - (Optional) The folder namespace containing this resource. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The full canonical job path, E.G. `/job/job-name`. | ||
* `description` - A human readable description of the credentials being stored. | ||
* `scope` - The visibility of the credentials to Jenkins agents. This must be set to either "GLOBAL" or "SYSTEM". | ||
* `username` - The username to be associated with the credentials. |
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,31 @@ | ||
# jenkins_credential_vault_approle Data Source | ||
|
||
Get the attributes of a Vault AppRole credential within Jenkins. | ||
|
||
~> The Jenkins installation that uses this resource is expected to have the [Hashicorp Vault Plugin](https://plugins.jenkins.io/hashicorp-vault-plugin/) installed in their system. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data jenkins_credential_vault_approle example { | ||
name = "job-name" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name of the resource being read. | ||
* `domain` - (Optional) The domain store to place the credentials into. If not set will default to the global credentials store. | ||
* `folder` - (Optional) The folder namespace containing this resource. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The full canonical job path, E.G. `/job/job-name`. | ||
* `description` - A human readable description of the credentials being stored. | ||
* `scope` - The visibility of the credentials to Jenkins agents. This must be set to either "GLOBAL" or "SYSTEM". | ||
* `path` - The unique name of the approle auth backend. Defaults to `approle`. | ||
* `role_id` - The role_id to be associated with the credentials. |
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,26 @@ | ||
# jenkins_job Data Source | ||
|
||
Get the attributes of a job within Jenkins. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data jenkins_job example { | ||
name = "job-name" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name of the job being read. | ||
* `folder` - (Optional) The folder namespace containing this job. | ||
|
||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The full canonical job path, E.G. `/job/job-name`. | ||
* `template` - A Jenkins-compatible XML template to describe the job. |
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,54 @@ | ||
package jenkins | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceJenkinsCredentialUsername() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceJenkinsCredentialUsernameRead, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Description: "The identifier assigned to the credentials.", | ||
Required: true, | ||
}, | ||
"domain": { | ||
Type: schema.TypeString, | ||
Description: "The domain namespace that the credentials will be added to.", | ||
Optional: true, | ||
}, | ||
"folder": { | ||
Type: schema.TypeString, | ||
Description: "The folder namespace that the credentials will be added to.", | ||
Optional: true, | ||
}, | ||
"scope": { | ||
Type: schema.TypeString, | ||
Description: "The Jenkins scope assigned to the credentials.", | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Description: "The credentials descriptive text.", | ||
Computed: true, | ||
}, | ||
"username": { | ||
Type: schema.TypeString, | ||
Description: "The credentials user username.", | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceJenkinsCredentialUsernameRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
name := d.Get("name").(string) | ||
folderName := d.Get("folder").(string) | ||
d.SetId(formatFolderName(folderName + "/" + name)) | ||
|
||
return resourceJenkinsCredentialUsernameRead(ctx, d, meta) | ||
} |
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,80 @@ | ||
package jenkins | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccJenkinsCredentialUsernameDataSource_basic(t *testing.T) { | ||
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: fmt.Sprintf(` | ||
resource jenkins_credential_username foo { | ||
name = "tf-acc-test-%s" | ||
description = "Terraform acceptance tests %s" | ||
username = "foo" | ||
password = "bar" | ||
} | ||
data jenkins_credential_username foo { | ||
name = jenkins_credential_username.foo.name | ||
domain = "_" | ||
}`, randString, randString), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("jenkins_credential_username.foo", "id", "/tf-acc-test-"+randString), | ||
resource.TestCheckResourceAttr("data.jenkins_credential_username.foo", "id", "/tf-acc-test-"+randString), | ||
resource.TestCheckResourceAttr("data.jenkins_credential_username.foo", "name", "tf-acc-test-"+randString), | ||
resource.TestCheckResourceAttr("data.jenkins_credential_username.foo", "description", "Terraform acceptance tests "+randString), | ||
resource.TestCheckResourceAttr("data.jenkins_credential_username.foo", "username", "foo"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccJenkinsCredentialUsernameDataSource_nested(t *testing.T) { | ||
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: fmt.Sprintf(` | ||
resource jenkins_folder foo { | ||
name = "tf-acc-test-%s" | ||
} | ||
resource jenkins_credential_username sub { | ||
name = "subfolder" | ||
folder = jenkins_folder.foo.id | ||
description = "Terraform acceptance tests %s" | ||
username = "foo" | ||
password = "bar" | ||
} | ||
data jenkins_credential_username sub { | ||
name = jenkins_credential_username.sub.name | ||
domain = "_" | ||
folder = jenkins_credential_username.sub.folder | ||
}`, randString, randString), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("jenkins_folder.foo", "id", "/job/tf-acc-test-"+randString), | ||
resource.TestCheckResourceAttr("jenkins_credential_username.sub", "id", "/job/tf-acc-test-"+randString+"/subfolder"), | ||
resource.TestCheckResourceAttr("data.jenkins_credential_username.sub", "name", "subfolder"), | ||
resource.TestCheckResourceAttr("data.jenkins_credential_username.sub", "folder", "/job/tf-acc-test-"+randString), | ||
resource.TestCheckResourceAttr("data.jenkins_credential_username.sub", "description", "Terraform acceptance tests "+randString), | ||
resource.TestCheckResourceAttr("data.jenkins_credential_username.sub", "username", "foo"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
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,59 @@ | ||
package jenkins | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceJenkinsCredentialVaultAppRole() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceJenkinsCredentialVaultAppRoleRead, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Description: "The identifier assigned to the credentials.", | ||
Required: true, | ||
}, | ||
"domain": { | ||
Type: schema.TypeString, | ||
Description: "The domain namespace that the credentials will be added to.", | ||
Optional: true, | ||
}, | ||
"folder": { | ||
Type: schema.TypeString, | ||
Description: "The folder namespace that the credentials will be added to.", | ||
Optional: true, | ||
}, | ||
"scope": { | ||
Type: schema.TypeString, | ||
Description: "The Jenkins scope assigned to the credentials.", | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Description: "The credentials descriptive text.", | ||
Computed: true, | ||
}, | ||
"path": { | ||
Type: schema.TypeString, | ||
Description: "Path of the roles approle backend.", | ||
Computed: true, | ||
}, | ||
"role_id": { | ||
Type: schema.TypeString, | ||
Description: "The roles role_id.", | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceJenkinsCredentialVaultAppRoleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
name := d.Get("name").(string) | ||
folderName := d.Get("folder").(string) | ||
d.SetId(formatFolderName(folderName + "/" + name)) | ||
|
||
return resourceJenkinsCredentialVaultAppRoleRead(ctx, d, meta) | ||
} |
80 changes: 80 additions & 0 deletions
80
jenkins/data_source_jenkins_credential_vault_approle_test.go
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,80 @@ | ||
package jenkins | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccJenkinsCredentialVaultAppRoleDataSource_basic(t *testing.T) { | ||
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: fmt.Sprintf(` | ||
resource jenkins_credential_vault_approle foo { | ||
name = "tf-acc-test-%s" | ||
description = "Terraform acceptance tests %s" | ||
role_id = "foo" | ||
secret_id = "bar" | ||
} | ||
data jenkins_credential_vault_approle foo { | ||
name = jenkins_credential_vault_approle.foo.name | ||
domain = "_" | ||
}`, randString, randString), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("jenkins_credential_vault_approle.foo", "id", "/tf-acc-test-"+randString), | ||
resource.TestCheckResourceAttr("data.jenkins_credential_vault_approle.foo", "id", "/tf-acc-test-"+randString), | ||
resource.TestCheckResourceAttr("data.jenkins_credential_vault_approle.foo", "name", "tf-acc-test-"+randString), | ||
resource.TestCheckResourceAttr("data.jenkins_credential_vault_approle.foo", "description", "Terraform acceptance tests "+randString), | ||
resource.TestCheckResourceAttr("data.jenkins_credential_vault_approle.foo", "role_id", "foo"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccJenkinsCredentialVaultAppRoleDataSource_nested(t *testing.T) { | ||
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: fmt.Sprintf(` | ||
resource jenkins_folder foo { | ||
name = "tf-acc-test-%s" | ||
} | ||
resource jenkins_credential_vault_approle sub { | ||
name = "subfolder" | ||
folder = jenkins_folder.foo.id | ||
description = "Terraform acceptance tests %s" | ||
role_id = "foo" | ||
secret_id = "bar" | ||
} | ||
data jenkins_credential_vault_approle sub { | ||
name = jenkins_credential_vault_approle.sub.name | ||
domain = "_" | ||
folder = jenkins_credential_vault_approle.sub.folder | ||
}`, randString, randString), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("jenkins_folder.foo", "id", "/job/tf-acc-test-"+randString), | ||
resource.TestCheckResourceAttr("jenkins_credential_vault_approle.sub", "id", "/job/tf-acc-test-"+randString+"/subfolder"), | ||
resource.TestCheckResourceAttr("data.jenkins_credential_vault_approle.sub", "name", "subfolder"), | ||
resource.TestCheckResourceAttr("data.jenkins_credential_vault_approle.sub", "folder", "/job/tf-acc-test-"+randString), | ||
resource.TestCheckResourceAttr("data.jenkins_credential_vault_approle.sub", "description", "Terraform acceptance tests "+randString), | ||
resource.TestCheckResourceAttr("data.jenkins_credential_vault_approle.sub", "role_id", "foo"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
File renamed without changes.
Oops, something went wrong.