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

ENG-3504: Add version to provider binaries #21

Merged
merged 10 commits into from
Feb 24, 2021
Merged

Conversation

wcmjunior
Copy link
Contributor

@wcmjunior wcmjunior commented Feb 22, 2021

Description of the change

  • Added version to provider binaries;
  • Added support for docker build;
  • Added support for Terraform 0.13 and 0.14.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • Jira issue referenced in commit message and/or PR title

Testing

Deploy new repositories using Cyral Terraform Provider using Terraform v0.12, v0.13 and v0.14.

@wcmjunior wcmjunior marked this pull request as draft February 22, 2021 20:45
@wcmjunior wcmjunior marked this pull request as ready for review February 23, 2021 19:16
The `go mod vendor` command was executed.
The tf-sdk-migrator CLI tool was used to do this by rewriting import
paths.
@lorenaleao
Copy link
Member

I changed the golang image from golang:1.14-alpine to golang:1.14 pretty much because of the description bellow and because when building the project with that image I was not able to run terraform plan and terraform apply. I think @wcmjunior was experiencing the same issue, right?

golang:<version>-alpine

This image is based on the popular Alpine Linux project, available in the alpine official image. Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general.

This variant is highly experimental, and not officially supported by the Go project (see golang/go#19938 for details).

The main caveat to note is that it does use musl libc instead of glibc and friends, which can lead to unexpected behavior. See this Hacker News comment thread for more discussion of the issues that might arise and some pro/con comparisons of using Alpine-based images.

To minimize image size, additional related tools (such as git, gcc, or bash) are not included in Alpine-based images. Using this image as a base, add the things you need in your own Dockerfile (see the alpine image description for examples of how to install packages if you are unfamiliar). See also docker-library/golang#250 (comment) for a longer explanation.

Source: https://hub.docker.com/_/golang

@lorenaleao
Copy link
Member

When trying to migrate the SDK from v1 to v2 for the first time, I got this error:

$GOBIN/tf-sdk-migrator v2upgrade

Rewriting provider go.mod file...
Rewriting SDK package imports...
Running `go mod tidy`...
Success! Provider is upgraded to github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.3.
Failed to check vendor folder: stat /home/lleao/go/src/github.com/cyralinc/terraform-provider-cyral/vendor: no such file or directory

I found some information about this vendor folder here: https://blogs.cisco.com/developer/347-terraformaci-05

Terraform File Structure

As we previously saw, Terraform is split into two main components, Core and Plugins. All Providers and Provisioners used in Terraform configurations are plugins. ​​​​

(...)

There are a number of files in the root directory of this repo how the ones we are concerned with are “main.go“, the “vendor” folder, and the “aci” folder.

  • main.go: This file creates a valid, executable Go binary that Terraform Core can consume.
  • vendor: This folder contains all of the Go modules which will be imported and used by the provider plugin. The key module for this provider is the ACI Go SDK which is responsible for making the HTTP requests to APIC and returning the response.
  • aci: This is the important directory where all the resources for the provider exist.

There is a go command (go mod vendor) that constructs a directory named vendor in the main module's root directory that contains copies of all packages needed to support builds and tests of packages in the main module.: https://golang.org/ref/mod#go-mod-vendor. So I built this folder and the error didn't show up anymore:

Rewriting provider go.mod file...
Rewriting SDK package imports...
Running `go mod tidy`...
Success! Provider is upgraded to github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.3.

It looks like this provider vendors dependencies. Don't forget to run `go mod vendor`.
Make sure to review all changes and run all tests.

@lorenaleao
Copy link
Member

The terraform.ResourceProvider interface was removed in the v2. You can see the PR here. They recommend providers update to using *schema.Provider directly, so that's why I updated the main.go file here.

The tests pass and I was able to create a repository in the CP as expected.

@lorenaleao
Copy link
Member

Regarding the terraform 0.13 and 0.14 upgrades, I just found these commands and guides:

Base automatically changed from develop to main February 24, 2021 19:36
@lorenaleao
Copy link
Member

Tested it again with the new changes using Terraform v0.12.30, v0.13.6 and v0.14.7. Worked as expected.

Copy link
Contributor

@tyrannosaurus-becks tyrannosaurus-becks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I tested this thru terraform init with version 14 on a Mac and it worked well.

Since we're currently on version 0.1.0, per this doc, we have two choices for the type of release we cut. Because there are no schema changes, it could be 0.1.1. However, because a new feature is added, it could be 0.2.0. Your choice!

The reason it matters is because of the version constraints people use to automatically pull in some updates but not others.

@wcmjunior wcmjunior merged commit e20863b into main Feb 24, 2021
@wcmjunior wcmjunior deleted the feature/ENG-3504 branch February 24, 2021 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants