Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate secret file credential to Framework #169

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions docs/resources/credential_secret_file.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
# jenkins_credential_secret_file Resource
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "jenkins_credential_secret_file Resource - terraform-provider-jenkins"
subcategory: ""
description: |-
Manages a secret file credential within Jenkins. This secret file may then be referenced within jobs that are created.
---

# jenkins_credential_secret_file (Resource)

Manages a secret file credential within Jenkins. This secret file may then be referenced within jobs that are created.

## Example Usage

```hcl
```terraform
resource "jenkins_credential_secret_file" "example" {
name = "example-secret-file"
filename = "secret-file.txt"
secretbytes = base64encode("My secret file very secret content.")
}
```

## Argument Reference
<!-- schema generated by tfplugindocs -->
## Schema

### Required

The following arguments are supported:
- `filename` (String) The secret file filename on jenkins server side.
- `name` (String) The name of the credentials being created. This maps to the ID property within Jenkins, and cannot be changed once set.
- `secretbytes` (String, Sensitive) The secret file, base64 encoded content. It can be sourced directly from local file with filebase64(path) TF function or given directly.

* `name` - (Required) The name of the credentials being created. This maps to the ID property within Jenkins, and cannot be changed once set.
* `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 to store the credentials in. If not set will default to global Jenkins credentials.
* `scope` - (Optional) The visibility of the credentials to Jenkins agents. This must be set to either "GLOBAL" or "SYSTEM". If not set will default to "GLOBAL".
* `description` - (Optional) A human readable description of the credentials being stored.
* `filename` - (Required) The secret file filename on jenkins server side.
* `secretbytes` - (Required) The secret file, base64 encoded content. It can be sourced directly from local file with filebase64(path) TF function or given directly.
### Optional

- `description` (String) A human readable description of the credentials being stored.
- `domain` (String) The domain store to place the credentials into. If not set will default to the global credentials store.
- `folder` (String) The folder namespace to store the credentials in. If not set will default to global Jenkins credentials.
- `scope` (String) The visibility of the credentials to Jenkins agents. This must be set to either "GLOBAL" or "SYSTEM". If not set will default to "GLOBAL".

## Attribute Reference
### Read-Only

All arguments above are exported.
- `id` (String) The full canonical job path, e.g. `/job/job-name`
5 changes: 5 additions & 0 deletions examples/resources/jenkins_credential_secret_file/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "jenkins_credential_secret_file" "example" {
name = "example-secret-file"
filename = "secret-file.txt"
secretbytes = base64encode("My secret file very secret content.")
}
11 changes: 8 additions & 3 deletions integration/credentials/credentials_secret_file.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
resource "jenkins_credential_secret_file" "global" {
name = "global-secret-file"
name = "global-secret-file"
filename = "secret-file.txt"
// This can also be read directy from file like this:
// filebase64("${path.module}/hello.txt")
secretbytes = base64encode("My secret file content.")
}

output "secret_file" {
value = jenkins_credential_secret_file.global
sensitive = true
}

resource "jenkins_credential_secret_file" "folder" {
name = "folder-secret-file"
folder = jenkins_folder.example.id
name = "folder-secret-file"
folder = jenkins_folder.example.id
filename = "secret-file.txt"
// This can also be read directy from file like this:
// filebase64("${path.module}/hello.txt")
Expand Down
4 changes: 4 additions & 0 deletions integration/main.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ run "credentials" {
condition = output.azure_service_principal.client_id == "123"
error_message = "${nonsensitive(output.azure_service_principal.client_id)} did not contain expected \"123\" value"
}
assert {
condition = output.secret_file.filename == "secret-file.txt"
error_message = "${nonsensitive(output.secret_file.filename)} did not contain expected \"secret-file.txt\" value"
}
assert {
condition = output.username.username == jenkins_credential_username.global.username
error_message = "${output.username.username} data value did not match resource value"
Expand Down
1 change: 0 additions & 1 deletion jenkins/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func Provider() *schema.Provider {
},

ResourcesMap: map[string]*schema.Resource{
"jenkins_credential_secret_file": resourceJenkinsCredentialSecretFile(),
"jenkins_credential_secret_text": resourceJenkinsCredentialSecretText(),
"jenkins_credential_ssh": resourceJenkinsCredentialSSH(),
"jenkins_folder": resourceJenkinsFolder(),
Expand Down
1 change: 1 addition & 0 deletions jenkins/provider_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (p *JenkinsProvider) DataSources(ctx context.Context) []func() datasource.D
func (p *JenkinsProvider) Resources(ctx context.Context) []func() resource.Resource {
return []func() resource.Resource{
newCredentialAzureServicePrincipalResource,
newCredentialSecretFileResource,
newCredentialUsernameResource,
newCredentialVaultAppRoleResource,
}
Expand Down
Loading