diff --git a/README.md b/README.md index 78b1fe2e..94a126c4 100644 --- a/README.md +++ b/README.md @@ -74,10 +74,10 @@ Use [examples/main.tf](./examples/user/main.tf) to create some test config, such ```hcl provider "minio" { - minio_server = "localhost:9000" - minio_region = "us-east-1" - minio_access_key = "minio" - minio_secret_key = "minio123" + minio_server = "localhost:9000" + minio_region = "us-east-1" + minio_user = "minio" + minio_password = "minio123" } ``` @@ -91,17 +91,17 @@ variable "minio_region" { variable "minio_server" { description = "Default MINIO host and port" - default = "localhost:9000" + default = "localhost:9000" } -variable "minio_access_key" { +variable "minio_user" { description = "MINIO user" - default = "minio" + default = "minio" } -variable "minio_secret_key" { - description = "MINIO secret user" - default = "minio123" +variable "minio_password" { + description = "MINIO password" + default = "minio123" } ``` diff --git a/Taskfile.yml b/Taskfile.yml index 0f23d62d..10af2eb3 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -53,8 +53,8 @@ tasks: env: TF_ACC: 0 MINIO_ENDPOINT: localhost:9000 - MINIO_ACCESS_KEY: minio - MINIO_SECRET_KEY: minio123 + MINIO_USER: minio + MINIO_PASSWORD: minio123 MINIO_ENABLE_HTTPS: false cmds: - go test -v -cover ./minio diff --git a/docker-compose.yml b/docker-compose.yml index 89f16044..09d6418a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,14 @@ version: "3" services: minio: - image: docker.io/minio/minio:RELEASE.2022-03-26T06-49-28Z + image: docker.io/minio/minio:RELEASE.2022-10-21T22-37-48Z ports: - "9000:9000" - "9001:9001" environment: - MINIO_ACCESS_KEY: minio - MINIO_SECRET_KEY: minio123 - MINIO_CI_CD: '1' + MINIO_ROOT_USER: minio + MINIO_ROOT_PASSWORD: minio123 + MINIO_CI_CD: "1" command: server --console-address :9001 /data{0...3} adminio-ui: image: docker.io/rzrbld/adminio-ui:v1.93 diff --git a/docs/index.md b/docs/index.md index 88ba4454..95b1ddd6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -12,9 +12,9 @@ This is a terraform provider plugin for managing [Minio](https://min.io/) S3 buc ```terraform provider minio { // required - minio_server = "..." - minio_access_key = "..." - minio_secret_key = "..." + minio_server = "..." + minio_user = "..." + minio_password = "..." // optional minio_session_token = "..." @@ -35,16 +35,16 @@ authentication, in this order, and explained below: ### Static API Key -Static credentials can be provided by adding the `minio-server`, `minio_access_key` and `minio_secret_key` variables in-line in the +Static credentials can be provided by adding the `minio-server`, `minio_user` and `minio_password` variables in-line in the Minio provider block: Usage: ```hcl provider "minio" { - minio_server = "..." - minio_access_key = "..." - minio_secret_key = "..." + minio_server = "..." + minio_user = "..." + minio_password = "..." } ``` @@ -52,10 +52,10 @@ provider "minio" { You can provide your configuration via the environment variables representing your minio credentials: -```bash +``` export MINIO_ENDPOINT="http://myendpoint" -export MINIO_ACCESS_KEY="244tefewg" -export MINIO_SECRET_KEY="xgwgwqqwv" +export MINIO_ROOT_USER="244tefewg" +export MINIO_ROOT_PASSWORD="xgwgwqqwv" ``` When using this method, you may omit the @@ -74,11 +74,11 @@ The following arguments are supported in the `provider` block: - `minio_server` - (Required) Minio Host and Port. It must be provided, but it can also be sourced from the `MINIO_ENDPOINT` environment variable -- `minio_access_key` - (Required) Minio Access Key. It must be provided, but - it can also be sourced from the `MINIO_ACCESS_KEY` environment variable +- `minio_user` - (Required) Minio User. It must be provided, but + it can also be sourced from the `MINIO_USER` environment variable -- `minio_secret_key` - (Required) Minio Secret Key. It must be provided, but - it can also be sourced from the `MINIO_SECRET_KEY` environment variable +- `minio_password` - (Required) Minio Password. It must be provided, but + it can also be sourced from the `MINIO_PASSWORD` environment variable - `minio_session_token` - (Optional) Minio Session Token. It can also be sourced from the `MINIO_SESSION_TOKEN` environment variable diff --git a/docs/resources/iam_service_account.md b/docs/resources/iam_service_account.md index 454cb78e..083a136e 100644 --- a/docs/resources/iam_service_account.md +++ b/docs/resources/iam_service_account.md @@ -3,13 +3,10 @@ page_title: "minio_iam_service_account Resource - terraform-provider-minio" subcategory: "" description: |- - --- # minio_iam_service_account (Resource) - - ## Example Usage ```terraform @@ -25,17 +22,18 @@ resource "minio_iam_service_account" "test_service_account" { target_user = minio_iam_user.test.name } -output "minio_access_key" { +output "minio_user" { value = minio_iam_service_account.test_service_account.access_key } -output "minio_secret_key" { +output "minio_password" { value = minio_iam_service_account.test_service_account.secret_key sensitive = true } ``` + ## Schema ### Required @@ -53,5 +51,3 @@ output "minio_secret_key" { - `id` (String) The ID of this resource. - `secret_key` (String, Sensitive) - `status` (String) - - diff --git a/examples/bucket/main.tf b/examples/bucket/main.tf index 30c753ea..aca3ea28 100755 --- a/examples/bucket/main.tf +++ b/examples/bucket/main.tf @@ -9,9 +9,9 @@ terraform { } provider "minio" { - minio_server = var.minio_server - minio_region = var.minio_region - minio_access_key = var.minio_access_key - minio_secret_key = var.minio_secret_key + minio_server = var.minio_server + minio_region = var.minio_region + minio_user = var.minio_user + minio_password = var.minio_password } diff --git a/examples/bucket/variables.tf b/examples/bucket/variables.tf index d11bf45c..c44044c2 100755 --- a/examples/bucket/variables.tf +++ b/examples/bucket/variables.tf @@ -5,15 +5,15 @@ variable "minio_region" { variable "minio_server" { description = "Default MINIO host and port" - default = "localhost:9000" + default = "localhost:9000" } -variable "minio_access_key" { +variable "minio_user" { description = "MINIO user" - default = "minio" + default = "minio" } -variable "minio_secret_key" { - description = "MINIO secret user" - default = "minio123" +variable "minio_password" { + description = "MINIO password" + default = "minio123" } \ No newline at end of file diff --git a/examples/group/main.tf b/examples/group/main.tf index 30c753ea..aca3ea28 100755 --- a/examples/group/main.tf +++ b/examples/group/main.tf @@ -9,9 +9,9 @@ terraform { } provider "minio" { - minio_server = var.minio_server - minio_region = var.minio_region - minio_access_key = var.minio_access_key - minio_secret_key = var.minio_secret_key + minio_server = var.minio_server + minio_region = var.minio_region + minio_user = var.minio_user + minio_password = var.minio_password } diff --git a/examples/group/variables.tf b/examples/group/variables.tf index d11bf45c..72c92e39 100755 --- a/examples/group/variables.tf +++ b/examples/group/variables.tf @@ -8,12 +8,12 @@ variable "minio_server" { default = "localhost:9000" } -variable "minio_access_key" { +variable "minio_user" { description = "MINIO user" - default = "minio" + default = "minio" } -variable "minio_secret_key" { - description = "MINIO secret user" - default = "minio123" +variable "minio_password" { + description = "MINIO password" + default = "minio123" } \ No newline at end of file diff --git a/examples/policy/main.tf b/examples/policy/main.tf index 30c753ea..aca3ea28 100755 --- a/examples/policy/main.tf +++ b/examples/policy/main.tf @@ -9,9 +9,9 @@ terraform { } provider "minio" { - minio_server = var.minio_server - minio_region = var.minio_region - minio_access_key = var.minio_access_key - minio_secret_key = var.minio_secret_key + minio_server = var.minio_server + minio_region = var.minio_region + minio_user = var.minio_user + minio_password = var.minio_password } diff --git a/examples/policy/variables.tf b/examples/policy/variables.tf index d11bf45c..c44044c2 100755 --- a/examples/policy/variables.tf +++ b/examples/policy/variables.tf @@ -5,15 +5,15 @@ variable "minio_region" { variable "minio_server" { description = "Default MINIO host and port" - default = "localhost:9000" + default = "localhost:9000" } -variable "minio_access_key" { +variable "minio_user" { description = "MINIO user" - default = "minio" + default = "minio" } -variable "minio_secret_key" { - description = "MINIO secret user" - default = "minio123" +variable "minio_password" { + description = "MINIO password" + default = "minio123" } \ No newline at end of file diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index 90ba5123..bc2d7238 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -1,8 +1,8 @@ provider minio { // required - minio_server = "..." - minio_access_key = "..." - minio_secret_key = "..." + minio_server = "..." + minio_user = "..." + minio_password = "..." // optional minio_region = "..." diff --git a/examples/resources/minio_iam_service_account/resource.tf b/examples/resources/minio_iam_service_account/resource.tf index d593b2c4..ea006026 100644 --- a/examples/resources/minio_iam_service_account/resource.tf +++ b/examples/resources/minio_iam_service_account/resource.tf @@ -1,7 +1,7 @@ resource "minio_iam_user" "test" { - name = "test" - force_destroy = true - tags = { + name = "test" + force_destroy = true + tags = { tag-key = "tag-value" } } @@ -10,11 +10,11 @@ resource "minio_iam_service_account" "test_service_account" { target_user = minio_iam_user.test.name } -output "minio_access_key" { +output "minio_user" { value = minio_iam_service_account.test_service_account.access_key } -output "minio_secret_key" { +output "minio_password" { value = minio_iam_service_account.test_service_account.secret_key sensitive = true } diff --git a/examples/resources/minio_s3_object/main.tf b/examples/resources/minio_s3_object/main.tf index 30c753ea..8e90d23a 100755 --- a/examples/resources/minio_s3_object/main.tf +++ b/examples/resources/minio_s3_object/main.tf @@ -1,7 +1,7 @@ terraform { required_providers { minio = { - source = "aminueza/minio" + source = "aminueza/minio" version = ">= 1.0.0" } } @@ -9,9 +9,9 @@ terraform { } provider "minio" { - minio_server = var.minio_server - minio_region = var.minio_region - minio_access_key = var.minio_access_key - minio_secret_key = var.minio_secret_key + minio_server = var.minio_server + minio_region = var.minio_region + minio_user = var.minio_user + minio_password = var.minio_password } diff --git a/examples/resources/minio_s3_object/variables.tf b/examples/resources/minio_s3_object/variables.tf index d11bf45c..c44044c2 100755 --- a/examples/resources/minio_s3_object/variables.tf +++ b/examples/resources/minio_s3_object/variables.tf @@ -5,15 +5,15 @@ variable "minio_region" { variable "minio_server" { description = "Default MINIO host and port" - default = "localhost:9000" + default = "localhost:9000" } -variable "minio_access_key" { +variable "minio_user" { description = "MINIO user" - default = "minio" + default = "minio" } -variable "minio_secret_key" { - description = "MINIO secret user" - default = "minio123" +variable "minio_password" { + description = "MINIO password" + default = "minio123" } \ No newline at end of file diff --git a/examples/serviceaccount/main.tf b/examples/serviceaccount/main.tf index 30c753ea..8e90d23a 100755 --- a/examples/serviceaccount/main.tf +++ b/examples/serviceaccount/main.tf @@ -1,7 +1,7 @@ terraform { required_providers { minio = { - source = "aminueza/minio" + source = "aminueza/minio" version = ">= 1.0.0" } } @@ -9,9 +9,9 @@ terraform { } provider "minio" { - minio_server = var.minio_server - minio_region = var.minio_region - minio_access_key = var.minio_access_key - minio_secret_key = var.minio_secret_key + minio_server = var.minio_server + minio_region = var.minio_region + minio_user = var.minio_user + minio_password = var.minio_password } diff --git a/examples/serviceaccount/output.tf b/examples/serviceaccount/output.tf index 1472e664..27d88513 100644 --- a/examples/serviceaccount/output.tf +++ b/examples/serviceaccount/output.tf @@ -1,8 +1,8 @@ - output "minio_access_key" { +output "minio_user" { value = minio_iam_service_account.test_service_account.access_key } -output "minio_secret_key" { +output "minio_password" { value = minio_iam_service_account.test_service_account.secret_key sensitive = true } diff --git a/examples/serviceaccount/variables.tf b/examples/serviceaccount/variables.tf index d11bf45c..a0a912af 100755 --- a/examples/serviceaccount/variables.tf +++ b/examples/serviceaccount/variables.tf @@ -5,15 +5,15 @@ variable "minio_region" { variable "minio_server" { description = "Default MINIO host and port" - default = "localhost:9000" + default = "localhost:9000" } -variable "minio_access_key" { +variable "minio_user" { description = "MINIO user" - default = "minio" + default = "minio" } -variable "minio_secret_key" { +variable "minio_password" { description = "MINIO secret user" - default = "minio123" -} \ No newline at end of file + default = "minio123" +} diff --git a/examples/user/main.tf b/examples/user/main.tf index 30c753ea..aca3ea28 100755 --- a/examples/user/main.tf +++ b/examples/user/main.tf @@ -9,9 +9,9 @@ terraform { } provider "minio" { - minio_server = var.minio_server - minio_region = var.minio_region - minio_access_key = var.minio_access_key - minio_secret_key = var.minio_secret_key + minio_server = var.minio_server + minio_region = var.minio_region + minio_user = var.minio_user + minio_password = var.minio_password } diff --git a/examples/user/variables.tf b/examples/user/variables.tf index d11bf45c..c44044c2 100755 --- a/examples/user/variables.tf +++ b/examples/user/variables.tf @@ -5,15 +5,15 @@ variable "minio_region" { variable "minio_server" { description = "Default MINIO host and port" - default = "localhost:9000" + default = "localhost:9000" } -variable "minio_access_key" { +variable "minio_user" { description = "MINIO user" - default = "minio" + default = "minio" } -variable "minio_secret_key" { - description = "MINIO secret user" - default = "minio123" +variable "minio_password" { + description = "MINIO password" + default = "minio123" } \ No newline at end of file diff --git a/minio/check_config.go b/minio/check_config.go index 4ce072c8..b7657848 100644 --- a/minio/check_config.go +++ b/minio/check_config.go @@ -46,11 +46,21 @@ func BucketVersioningConfig(d *schema.ResourceData, meta interface{}) *S3MinioBu // NewConfig creates a new config for minio func NewConfig(d *schema.ResourceData) *S3MinioConfig { + user := d.Get("minio_user").(string) + if user == "" { + user = d.Get("minio_access_key").(string) + } + + password := d.Get("minio_password").(string) + if password == "" { + password = d.Get("minio_secret_key").(string) + } + return &S3MinioConfig{ S3HostPort: d.Get("minio_server").(string), S3Region: d.Get("minio_region").(string), - S3UserAccess: d.Get("minio_access_key").(string), - S3UserSecret: d.Get("minio_secret_key").(string), + S3UserAccess: user, + S3UserSecret: password, S3SessionToken: d.Get("minio_session_token").(string), S3APISignature: d.Get("minio_api_version").(string), S3SSL: d.Get("minio_ssl").(bool), diff --git a/minio/provider.go b/minio/provider.go index 9cc40a58..f4b46939 100644 --- a/minio/provider.go +++ b/minio/provider.go @@ -27,19 +27,39 @@ func Provider() *schema.Provider { }, "minio_access_key": { Type: schema.TypeString, - Required: true, + Optional: true, Description: "Minio Access Key", DefaultFunc: schema.MultiEnvDefaultFunc([]string{ "MINIO_ACCESS_KEY", }, nil), + Deprecated: "use minio_user instead", }, "minio_secret_key": { Type: schema.TypeString, - Required: true, + Optional: true, Description: "Minio Secret Key", DefaultFunc: schema.MultiEnvDefaultFunc([]string{ "MINIO_SECRET_KEY", }, nil), + Deprecated: "use minio_password instead", + }, + "minio_user": { + Type: schema.TypeString, + Optional: true, + Description: "Minio User", + DefaultFunc: schema.MultiEnvDefaultFunc([]string{ + "MINIO_USER", + }, nil), + ConflictsWith: []string{"minio_access_key"}, + }, + "minio_password": { + Type: schema.TypeString, + Optional: true, + Description: "Minio Password", + DefaultFunc: schema.MultiEnvDefaultFunc([]string{ + "MINIO_PASSWORD", + }, nil), + ConflictsWith: []string{"minio_secret_key"}, }, "minio_session_token": { Type: schema.TypeString, diff --git a/minio/provider_test.go b/minio/provider_test.go index 068854e8..2bcd72df 100644 --- a/minio/provider_test.go +++ b/minio/provider_test.go @@ -30,21 +30,26 @@ func TestProvider_impl(t *testing.T) { } func testAccPreCheck(t *testing.T) { - ok := os.Getenv("TF_ACC") == "" + valid := true - if os.Getenv("MINIO_ENDPOINT") != "" { - ok = true + if v, _ := os.LookupEnv("TF_ACC"); v == "" { + valid = false } - if os.Getenv("MINIO_ACCESS_KEY") != "" { - ok = true + + if _, ok := os.LookupEnv("MINIO_ENDPOINT"); !ok { + valid = false + } + if _, ok := os.LookupEnv("MINIO_USER"); !ok { + valid = false } - if os.Getenv("MINIO_SECRET_KEY") != "" { - ok = true + if _, ok := os.LookupEnv("MINIO_PASSWORD"); !ok { + valid = false } - if os.Getenv("MINIO_ENABLE_HTTPS") != "" { - ok = true + if _, ok := os.LookupEnv("MINIO_ENABLE_HTTPS"); !ok { + valid = false } - if !ok { - panic("you must to set env variables for integration tests!") + + if !valid { + t.Fatal("you must to set env variables for integration tests!") } } diff --git a/templates/index.md.tmpl b/templates/index.md.tmpl index 80410fdb..035ddbf6 100644 --- a/templates/index.md.tmpl +++ b/templates/index.md.tmpl @@ -21,7 +21,7 @@ authentication, in this order, and explained below: ### Static API Key -Static credentials can be provided by adding the `minio-server`, `minio_access_key` and `minio_secret_key` variables in-line in the +Static credentials can be provided by adding the `minio-server`, `minio_user` and `minio_password` variables in-line in the Minio provider block: Usage: @@ -29,8 +29,8 @@ Usage: ```hcl provider "minio" { minio_server = "..." - minio_access_key = "..." - minio_secret_key = "..." + minio_user = "..." + minio_password = "..." } ``` @@ -40,8 +40,8 @@ You can provide your configuration via the environment variables representing yo ``` $ export MINIO_ENDPOINT="http://myendpoint" -$ export MINIO_ACCESS_KEY="244tefewg" -$ export MINIO_SECRET_KEY="xgwgwqqwv" +$ export MINIO_USER="244tefewg" +$ export MINIO_PASSWORD="xgwgwqqwv" ``` When using this method, you may omit the @@ -60,11 +60,11 @@ The following arguments are supported in the `provider` block: * `minio_server` - (Required) Minio Host and Port. It must be provided, but it can also be sourced from the `MINIO_ENDPOINT` environment variable -* `minio_access_key` - (Required) Minio Access Key. It must be provided, but - it can also be sourced from the `MINIO_ACCESS_KEY` environment variable +* `minio_user` - (Required) Minio User. It must be provided, but + it can also be sourced from the `MINIO_USER` environment variable -* `minio_secret_key` - (Required) Minio Secret Key. It must be provided, but - it can also be sourced from the `MINIO_SECRET_KEY` environment variable +* `minio_password` - (Required) Minio Password. It must be provided, but + it can also be sourced from the `MINIO_PASSWORD` environment variable * `minio_region` - (Optional) Minio Region (`default: us-east-1`).