Giter VIP home page Giter VIP logo

terraform-provider-gdrive's Introduction

terraform-provider-gdrive

A Terraform Provider for Google Drive

Go Report Card

View on Terraform Registry.

The Terraform provider for Google Drive can be used to manage Google Drive objects like files and folders, Shared Drives and Labels.

It can also be used to manage permissions to any of these objects, as well as import and export files to and from Google Drive.

Using Terraform and a source code management solution to manage your Google Drive environment can help you estabilsh secure processes that require approval from multiple people before changes are deployed to production. You can also build your own modules to estabilsh standards across your orgnization like naming conventions, default permissions or Label assignments.

Features

  • Manage Shared Drives and organize them into organizational units
  • Manage Google Drive files (including file uploads, downloads and exports)
  • Manage Google Drive permissions
  • Manage Google Drive Labels, fields, assignments to files and permissions

Installation

To install this provider, copy and paste this code into your Terraform configuration. Then, run terraform init.

terraform {
  required_providers {
    gdrive = {
      source = "hanneshayashi/gdrive"
      version = "~> 1.0"
    }
  }
}

Upgrade from 0.x

Please see the Upgrade Guide and make sure you have a backup of your state file before upgrading.

Setup

  1. Create GCP Project (or use an existing one)
  2. Enable the following APIs:
    • Drive API
    • Drive Labels API
    • Cloud Identity API
  3. Create a Service Account + Enable Domain Wide Delegation
  4. Enter the Client ID of the Service Account with the following scopes in your Admin Console:
    • https://www.googleapis.com/auth/drive
    • https://www.googleapis.com/auth/drive.labels
    • https://www.googleapis.com/auth/drive.admin.labels
    • https://www.googleapis.com/auth/cloud-identity.orgunits

You can authenticate in one of two ways:

  1. Use Application Default Credentials (recommended): Activate the IAM Service Account Credentials API in the project where the Service Account is located

    a) Use a Google Compute Engine instance or any service that supports attaching a Service Account in GCP

    or

    b) Use gcloud auth application-default login --impersonate-service-account on your local workstation

In both cases, the account needs the Service Account Token Creator role for the Service Account you set up for DWD (even if your GCP service is using the same account).

You can then configure the provider like so:

provider "gdrive" {
  service_account     = "[email protected]"  # This is the email address of your Service Account. You can leave this empty on GCP, if you want to use the service's account
  subject             = "[email protected]"                         # This is the user you want to impersonate with Domain Wide Delegation
}
  1. Create a Service Account Key and configure the provider like so:
provider "gdrive" {
  service_account_key = "/path/to/sa.json"  # This is the path to your Service Account Key file or its content in JSON format
  subject             = "[email protected]" # This is the user you want to impersonate with Domain Wide Delegation
}

You can also set the SERVICE_ACCOUNT_KEY environment variable to store either the path to the Key file or the JSON contents directly.

This provider uses GSM for authentication and API access. You can take a look at the GSM Setup Guide, if you need help.

terraform-provider-gdrive's People

Contributors

hanneshayashi avatar michael-richard-3r avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

terraform-provider-gdrive's Issues

cannot upload csv as a spreadsheet

a csv cant be uploaded as a spreadheet to drive e.g.

resource "gdrive_file" "sheet_example" {
  mime_type = "application/vnd.google-apps.spreadsheet"
  name      = "test"
  parent    = gdrive_file.folder.id
  content   = "example.csv"
}

^ will not work.

The solution (via the API) is to set the filetype

  
const fileMetadata = {
    'title': 'My Report',
    'mimeType': 'application/vnd.google-apps.spreadsheet',
  };
  const media = {
    mimeType: 'text/csv', // THIS ONE
    body: fs.createReadStream('files/report.csv'),
  };

link to working example api call:
https://developers.google.com/drive/api/guides/manage-uploads#import_to_google_docs_types

so the module needs to expose setting (or autodetect) the filetype and add it to the api-call

Publish to Terraform registry ?

Hi,

this provider seems interesting, and is the only one available to handle Google Drives. Do you intent to publish it to Terraform Registry ?

Thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.