changing spaces auth to use env vars instead of profile
This commit is contained in:
parent
a3344f41b5
commit
064ec7d018
|
@ -3,6 +3,7 @@ package digitalocean
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
|
@ -37,12 +38,6 @@ func resourceDigitalOceanBucket() *schema.Resource {
|
|||
ForceNew: true,
|
||||
Description: "Bucket region",
|
||||
},
|
||||
"profile": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: false,
|
||||
Description: "Spaces Access Profile",
|
||||
},
|
||||
"acl": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
|
@ -58,7 +53,7 @@ func resourceDigitalOceanBucketCreate(d *schema.ResourceData, meta interface{})
|
|||
endpoint := fmt.Sprintf("https://%s.digitaloceanspaces.com", d.Get("region").(string))
|
||||
sesh, err := session.NewSession(&aws.Config{
|
||||
Region: aws.String("us-east-1"),
|
||||
Credentials: credentials.NewSharedCredentials("", d.Get("profile").(string)),
|
||||
Credentials: credentials.NewStaticCredentials(os.Getenv("DO_ACCESS_KEY_ID"), os.Getenv("DO_SECRET_ACCESS_KEY"), ""),
|
||||
Endpoint: aws.String(endpoint)},
|
||||
)
|
||||
svc := s3.New(sesh)
|
||||
|
@ -103,7 +98,7 @@ func resourceDigitalOceanBucketUpdate(d *schema.ResourceData, meta interface{})
|
|||
endpoint := fmt.Sprintf("https://%s.digitaloceanspaces.com", d.Get("region").(string))
|
||||
sesh, err := session.NewSession(&aws.Config{
|
||||
Region: aws.String("us-east-1"),
|
||||
Credentials: credentials.NewSharedCredentials("", d.Get("profile").(string)),
|
||||
Credentials: credentials.NewStaticCredentials(os.Getenv("DO_ACCESS_KEY_ID"), os.Getenv("DO_SECRET_ACCESS_KEY"), ""),
|
||||
Endpoint: aws.String(endpoint)},
|
||||
)
|
||||
svc := s3.New(sesh)
|
||||
|
@ -125,7 +120,7 @@ func resourceDigitalOceanBucketRead(d *schema.ResourceData, meta interface{}) er
|
|||
endpoint := fmt.Sprintf("https://%s.digitaloceanspaces.com", d.Get("region").(string))
|
||||
sesh, err := session.NewSession(&aws.Config{
|
||||
Region: aws.String("us-east-1"),
|
||||
Credentials: credentials.NewSharedCredentials("", d.Get("profile").(string)),
|
||||
Credentials: credentials.NewStaticCredentials(os.Getenv("DO_ACCESS_KEY_ID"), os.Getenv("DO_SECRET_ACCESS_KEY"), ""),
|
||||
Endpoint: aws.String(endpoint)},
|
||||
)
|
||||
svc := s3.New(sesh)
|
||||
|
@ -189,7 +184,7 @@ func resourceDigitalOceanBucketDelete(d *schema.ResourceData, meta interface{})
|
|||
endpoint := fmt.Sprintf("https://%s.digitaloceanspaces.com", d.Get("region").(string))
|
||||
sesh, err := session.NewSession(&aws.Config{
|
||||
Region: aws.String("us-east-1"),
|
||||
Credentials: credentials.NewSharedCredentials("", d.Get("profile").(string)),
|
||||
Credentials: credentials.NewStaticCredentials(os.Getenv("DO_ACCESS_KEY_ID"), os.Getenv("DO_SECRET_ACCESS_KEY"), ""),
|
||||
Endpoint: aws.String(endpoint)},
|
||||
)
|
||||
svc := s3.New(sesh)
|
||||
|
|
|
@ -3,6 +3,7 @@ package digitalocean
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -124,7 +125,7 @@ func testAccCheckDigitalOceanBucketDestroy(s *terraform.State) error {
|
|||
func testAccCheckDigitalOceanBucketDestroyWithProvider(s *terraform.State, provider *schema.Provider) error {
|
||||
sesh, err := session.NewSession(&aws.Config{
|
||||
Region: aws.String("nyc3"),
|
||||
Credentials: credentials.NewSharedCredentials("", "digitalocean-spaces")},
|
||||
Credentials: credentials.NewStaticCredentials(os.Getenv("DO_ACCESS_KEY_ID"), os.Getenv("DO_SECRET_ACCESS_KEY"), "")},
|
||||
)
|
||||
svc := s3.New(sesh, &aws.Config{
|
||||
Endpoint: aws.String("https://nyc3.digitaloceanspaces.com")},
|
||||
|
@ -168,7 +169,7 @@ func testAccCheckDigitalOceanBucketExistsWithProvider(n string, providerF func()
|
|||
|
||||
sesh, err := session.NewSession(&aws.Config{
|
||||
Region: aws.String("nyc3"),
|
||||
Credentials: credentials.NewSharedCredentials("", "digitalocean-spaces")},
|
||||
Credentials: credentials.NewStaticCredentials(os.Getenv("DO_ACCESS_KEY_ID"), os.Getenv("DO_SECRET_ACCESS_KEY"), "")},
|
||||
)
|
||||
svc := s3.New(sesh, &aws.Config{
|
||||
Endpoint: aws.String("https://nyc3.digitaloceanspaces.com")},
|
||||
|
@ -206,7 +207,7 @@ func testAccCheckDigitalOceanDestroyBucket(n string) resource.TestCheckFunc {
|
|||
|
||||
sesh, err := session.NewSession(&aws.Config{
|
||||
Region: aws.String("nyc3"),
|
||||
Credentials: credentials.NewSharedCredentials("", "digitalocean-spaces")},
|
||||
Credentials: credentials.NewStaticCredentials(os.Getenv("DO_ACCESS_KEY_ID"), os.Getenv("DO_SECRET_ACCESS_KEY"), "")},
|
||||
)
|
||||
svc := s3.New(sesh, &aws.Config{
|
||||
Endpoint: aws.String("https://nyc3.digitaloceanspaces.com")},
|
||||
|
|
|
@ -14,15 +14,8 @@ S3 service (even using their terminology). This allows users to reuse code writt
|
|||
for S3 usage with Spaces without much tweaking. Spaces mirrors S3's authentication
|
||||
framework and requests to Spaces require a key pair similar to Amazon's Access ID
|
||||
and Secret Key. Due to these similarities, this functionality uses the AWS Go SDK to make these calls.
|
||||
The authentication requirement can be met by installing `awscli` and adding a
|
||||
DigitalOcean profile to your credentials file (usually found in`~/.aws/credentials`).
|
||||
This should look like:
|
||||
|
||||
```
|
||||
[digitalocean-spaces]
|
||||
aws_access_key_id = QAZWSXRFVTGBYHNUJMIK
|
||||
aws_secret_access_key = 1QAZ2WSX3EDC4RFV5TGB6YHN7UJM8IK9OL0P1QAZ2WS
|
||||
```
|
||||
The authentication requirement can be met by setting the `DO_ACCESS_KEY_ID` and `DO_SECRET_ACCESS_KEY`
|
||||
environment variables to the access ID and secret you generate in the Digital Ocean control panel.
|
||||
|
||||
For more information, See [An Introduction to DigitalOcean Spaces](https://www.digitalocean.com/community/tutorials/an-introduction-to-digitalocean-spaces)
|
||||
|
||||
|
@ -33,7 +26,6 @@ For more information, See [An Introduction to DigitalOcean Spaces](https://www.d
|
|||
resource "digitalocean_bucket" "foobar" {
|
||||
name = "foobar"
|
||||
region = "nyc3"
|
||||
profile = "digitalocean-spaces"
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -43,7 +35,6 @@ The following arguments are supported:
|
|||
|
||||
* `name` - (Required) The name of the bucket
|
||||
* `region` - (Required) The region where the bucket resides
|
||||
* `profile` - (Required) Spaces Access Profile (defined in your AWS Credentials file)
|
||||
* `acl` - Canned ACL applied on bucket creation (`private` or `public-read`)
|
||||
|
||||
## Attributes Reference
|
||||
|
|
Loading…
Reference in New Issue