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

[BugFix: Issue #293] fix docker file to install providers based on Terraform 0.13 installation specs #294

Merged
merged 3 commits into from
May 27, 2021

Conversation

dikhan
Copy link
Owner

@dikhan dikhan commented May 18, 2021

What problem does this Pull Request solve?

This PR fixes the examples docker file to make it work with Terraform 013 or greater. In addition, the base has been updated to alpine to make the container lighter.

Please link to the issue number here (issue will be closed when PR is merged): Closes #293

Summary of the changes:

  • Updates the example docker file to use the alpine:3.13 reducing the size of the container and also installing Terraform 0.13 and the example OpenAPI providers as per Terraform 0.13 installation specs.
  • Travis pipeline to use a specific version of Terraform not relying on Travis Nodes to have it already installed fixing the issue: cannot run Terraform provider tests: unexpected error: openpgp: signature made by unknown entity

How was this tested?

  • Example container starts up successfully and running terraform init/plan in both examples works as expected:
➜  terraform-provider-openapi git:(293-fix-docker-examples) make examples-container
[INFO] Running gofmt on the current directory
gofmt -s -w $(find . -name '*.go' | grep -v 'examples\|vendor')
[INFO] Bringing up local environment
Creating network "build_example" with the default driver
Building swaggercodegen-service-provider-api
Step 1/9 : FROM golang:latest
 ---> 861b1afd1d13
Step 2/9 : ENV WORK_DIR "$GOPATH/src/github.com/dikhan/terraform-provider-openapi/examples/swaggercodegen/api"
 ---> Using cache
 ---> 4dcbf3a43e87
Step 3/9 : RUN mkdir -p $WORK_DIR
 ---> Using cache
 ---> 79a09cddc019
Step 4/9 : ADD . $WORK_DIR
 ---> Using cache
 ---> 2c1c79112d92
Step 5/9 : WORKDIR $WORK_DIR
 ---> Using cache
 ---> db1aa1a8534b
Step 6/9 : RUN go build -o cdn-service-provider-api .
 ---> Using cache
 ---> 1b7f45d09d70
Step 7/9 : EXPOSE 80
 ---> Using cache
 ---> d9fdd9b81cad
Step 8/9 : EXPOSE 443
 ---> Using cache
 ---> 8d60d1e287e9
Step 9/9 : CMD ["./cdn-service-provider-api"]
 ---> Using cache
 ---> 9249f9561220

Successfully built 9249f9561220
Successfully tagged swaggercodegen-service-provider-api:latest
Building goa-service-provider-api
Step 1/12 : FROM golang:latest
 ---> 861b1afd1d13
Step 2/12 : ENV WORK_DIR "$GOPATH/src/github.com/dikhan/terraform-provider-openapi/examples/goa/api"
 ---> Using cache
 ---> e6f212258acb
Step 3/12 : RUN mkdir -p $WORK_DIR
 ---> Using cache
 ---> e453980d8128
Step 4/12 : ADD . $WORK_DIR
 ---> Using cache
 ---> 874f22cf8750
Step 5/12 : WORKDIR $WORK_DIR
 ---> Using cache
 ---> 44d3a6fff4e3
Step 6/12 : COPY swagger/swagger.json /opt/goa/swagger/
 ---> Using cache
 ---> 16b584bf3b47
Step 7/12 : COPY swagger/swagger.yaml /opt/goa/swagger/
 ---> Using cache
 ---> a92ad6616f9e
Step 8/12 : RUN git clone --branch v1 https://github.com/goadesign/goa.git $GOPATH/src/github.com/goadesign/goa
 ---> Using cache
 ---> bf1b9df87e02
Step 9/12 : RUN go get
 ---> Using cache
 ---> 34e1055fdb54
Step 10/12 : RUN go build -o goa-service-provider .
 ---> Using cache
 ---> c21e679fb5ad
Step 11/12 : EXPOSE 9090
 ---> Using cache
 ---> e56fc2d14bd9
Step 12/12 : CMD ["./goa-service-provider"]
 ---> Using cache
 ---> 96157a629e3d

Successfully built 96157a629e3d
Successfully tagged goa-service-provider-api:latest
Creating goa-service-provider-api            ... done
Creating swagger-ui-swaggercodegen           ... done
Creating swaggercodegen-service-provider-api ... done
[INFO] Bringing up container with OpenAPI providers examples
Building terraform-provider-openapi-examples
Step 1/10 : FROM alpine:3.13
 ---> 28f6e2705743
Step 2/10 : WORKDIR /openapi
 ---> Running in 33dab4c4abcb
Removing intermediate container 33dab4c4abcb
 ---> 83f7cac3efe6
Step 3/10 : ENV TERRAFORM_VERSION=0.13.7
 ---> Running in 4f8b7fbf4e79
Removing intermediate container 4f8b7fbf4e79
 ---> 078832fe0d8a
Step 4/10 : RUN apk update &&     apk add curl jq python3 bash ca-certificates git openssl unzip wget &&     cd /tmp &&     wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip &&     unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/bin &&     rm -rf /tmp/* &&     rm -rf /var/cache/apk/* &&     rm -rf /var/tmp/*
 ---> Running in 1189c5e3805b
...
--2021-05-27 01:30:45--  https://releases.hashicorp.com/terraform/0.13.7/terraform_0.13.7_linux_amd64.zip
Resolving releases.hashicorp.com (releases.hashicorp.com)... 151.101.53.183, 2a04:4e42:d::439
Connecting to releases.hashicorp.com (releases.hashicorp.com)|151.101.53.183|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 34884519 (33M) [application/zip]
Saving to: 'terraform_0.13.7_linux_amd64.zip'
...
 34050K .......... ......                                     100% 61.5M=3.6s

2021-05-27 01:30:49 (9.30 MB/s) - 'terraform_0.13.7_linux_amd64.zip' saved [34884519/34884519]

Archive:  terraform_0.13.7_linux_amd64.zip
  inflating: /usr/bin/terraform      
Removing intermediate container 1189c5e3805b
 ---> 1b78b8d9c506
Step 5/10 : ENV PROVIDER_SOURCE_ADDRESS="terraform.example.com/examplecorp"
 ---> Running in 699802f0a6b8
Removing intermediate container 699802f0a6b8
 ---> 5296e100a9f8
Step 6/10 : RUN export PROVIDER_NAME=goa && curl -fsSL https://raw.githubusercontent.com/dikhan/terraform-provider-openapi/master/scripts/install.sh | bash -s -- --provider-name $PROVIDER_NAME --provider-source-address ${PROVIDER_SOURCE_ADDRESS}
 ---> Running in 60b70bfbdfb8
Terraform provider successfully installed!
 |--> Installation Path: /root/.terraform.d/plugins/terraform.example.com/examplecorp/goa/2.0.5/linux_amd64/terraform-provider-goa
 |--> Important Note: As of Terraform >=0.13 each Terraform module must declare which providers it requires, so that Terraform can install and use them. You can copy into your .tf file the following snippet was autogenerated for your convenience based on the input provided:

terraform {
  required_providers {
    goa = {
      source  = "terraform.example.com/examplecorp/goa"
      version = ">= 2.0.5"
    }
  }
}
Removing intermediate container 60b70bfbdfb8
 ---> 34acf75915bc
Step 7/10 : RUN export PROVIDER_NAME=swaggercodegen && curl -fsSL https://raw.githubusercontent.com/dikhan/terraform-provider-openapi/master/scripts/install.sh | bash -s -- --provider-name $PROVIDER_NAME --provider-source-address ${PROVIDER_SOURCE_ADDRESS}
 ---> Running in cdf76d2f9ecf
Terraform provider successfully installed!
 |--> Installation Path: /root/.terraform.d/plugins/terraform.example.com/examplecorp/swaggercodegen/2.0.5/linux_amd64/terraform-provider-swaggercodegen
 |--> Important Note: As of Terraform >=0.13 each Terraform module must declare which providers it requires, so that Terraform can install and use them. You can copy into your .tf file the following snippet was autogenerated for your convenience based on the input provided:

terraform {
  required_providers {
    swaggercodegen = {
      source  = "terraform.example.com/examplecorp/swaggercodegen"
      version = ">= 2.0.5"
    }
  }
}
Removing intermediate container cdf76d2f9ecf
 ---> 57337384f1ab
Step 8/10 : COPY examples/ .
 ---> da18ffa8cdb8
Step 9/10 : RUN mv terraform-provider-openapi.yaml /root/.terraform.d/plugins/
 ---> Running in 9a1d5df417d0
Removing intermediate container 9a1d5df417d0
 ---> 291b7a8ceb8d
Step 10/10 : CMD ["bash"]
 ---> Running in 3b5bd0b7db9b
Removing intermediate container 3b5bd0b7db9b
 ---> 5e9f1f641b07

Successfully built 5e9f1f641b07
Successfully tagged terraform-provider-openapi-examples:latest
Creating build_terraform-provider-openapi-examples_run ... done
bash-5.1# cd 
goa/            swaggercodegen/ 
bash-5.1# cd swaggercodegen/
bash-5.1# terraform init

Initializing the backend...

Initializing provider plugins...
- Finding terraform.example.com/examplecorp/swaggercodegen versions matching ">= 2.0.0"...
- Installing terraform.example.com/examplecorp/swaggercodegen v2.0.5...
- Installed terraform.example.com/examplecorp/swaggercodegen v2.0.5 (unauthenticated)

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
bash-5.1# terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # swaggercodegen_cdn_v1.my_cdn will be created
  + resource "swaggercodegen_cdn_v1" "my_cdn" {
      + better_example_number_field_name = 15.78
      + computed                         = (known after apply)
      + computed_with_default            = (known after apply)
      + example_boolean                  = true
      + example_int                      = 25
      + hostnames                        = [
          + "origin.com",
        ]
      + id                               = (known after apply)
      + ips                              = [
          + "127.0.0.1",
        ]
      + label                            = "label"
      + optional_computed                = "optional_computed value"
      + optional_computed_with_default   = "optional_computed_with_default value"
      + optional_property                = "optional_property value"

      + array_of_objects_example {
          + origin_port = 81
          + protocol    = "http"
        }
      + array_of_objects_example {
          + origin_port = 443
          + protocol    = "https"
        }

      + object_nested_scheme_property {
          + name = (known after apply)

          + object_property {
              + account = (known after apply)
            }
        }

      + object_property {
          + detailed_message = "some message news with details"
          + example_boolean  = true
          + example_int      = 11
          + example_number   = 12.23
          + message          = "some message news2"
        }
    }

  # swaggercodegen_cdn_v1.my_cdn2 will be created
  + resource "swaggercodegen_cdn_v1" "my_cdn2" {
      + better_example_number_field_name = 12.23
      + computed                         = (known after apply)
      + computed_with_default            = (known after apply)
      + example_boolean                  = true
      + example_int                      = 11
      + hostnames                        = [
          + "origin.com",
        ]
      + id                               = (known after apply)
      + ips                              = [
          + "127.0.0.2",
        ]
      + label                            = "label"
      + optional_computed                = (known after apply)
      + optional_computed_with_default   = "some computed value known at runtime"

      + array_of_objects_example {
          + origin_port = 81
          + protocol    = "http"
        }
      + array_of_objects_example {
          + origin_port = 443
          + protocol    = "https"
        }

      + object_nested_scheme_property {
          + name = (known after apply)

          + object_property {
              + account = (known after apply)
            }
        }

      + object_property {
          + detailed_message = "some message news with details"
          + example_boolean  = true
          + example_int      = 11
          + example_number   = 12.23
          + message          = "some message news2"
        }
    }

  # swaggercodegen_cdn_v1_firewalls_v1.my_cdn_firewall_v1 will be created
  + resource "swaggercodegen_cdn_v1_firewalls_v1" "my_cdn_firewall_v1" {
      + cdn_v1_id = (known after apply)
      + id        = (known after apply)
      + name      = "my firewall fancy name"
    }

  # swaggercodegen_lbs_v1.my_lb will be created
  + resource "swaggercodegen_lbs_v1" "my_lb" {
      + backends         = [
          + "backend.com",
        ]
      + id               = (known after apply)
      + name             = "some_name"
      + simulate_failure = false
      + status           = (known after apply)
      + time_to_process  = 1

      + new_status {
          + message = (known after apply)
          + status  = (known after apply)
        }
    }

Plan: 4 to add, 0 to change, 0 to destroy.

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

bash-5.1# cd ..
bash-5.1# cd goa/
bash-5.1# terraform init

Initializing the backend...

Initializing provider plugins...
- Finding terraform.example.com/examplecorp/goa versions matching ">= 2.0.0"...
- Installing terraform.example.com/examplecorp/goa v2.0.5...
- Installed terraform.example.com/examplecorp/goa v2.0.5 (unauthenticated)

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
bash-5.1# terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # goa_bottles.my_bottle will be created
  + resource "goa_bottles" "my_bottle" {
      + id      = (known after apply)
      + name    = "Name of bottle"
      + rating  = 3
      + vintage = 2653
    }

Plan: 1 to add, 0 to change, 0 to destroy.

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

bash-5.1# exit
exit

Type of change

What type of change does your code introduce to the provider? Please put an x (w/o heading/trailing white spaces) in the boxes that apply:

  • New feature (change that adds new functionality)
  • Bug-fix (change that fixes current functionality)
  • Tech debt (enhances the current functionality)
  • New release (pumps the version)

Checklist

Please put an x (w/o heading/trailing white spaces) in the boxes that apply:

  • I have read and followed the CONTRIBUTING guidelines
  • I have added tests that prove my fix is effective or that my feature works
  • I have made sure code compiles correctly and all tests are passing by running make test-all
  • I have added/updated necessary documentation (if appropriate)
  • I have added the following info to the title of the PR (pick the appropriate option for the type of change). This is important because the release notes will include this information.
    • Feature Request: PRs related to feature requests should have in the title [FeatureRequest: Issue #X] <PR Title>
    • Bug Fixes: PRs related to bug fixes should have in the title [BugFix: Issue #X] <PR Title>
    • Tech Debt: PRs related to technical debt should have in the title [TechDebt: Issue #X] <PR Title>
    • New Release: PRs related to a new release should have in the title [NewRelease] vX.Y.Z

Checklist for Admins

  • Label is populated
  • PR is assigned to the corresponding project
  • PR has at least 1 reviewer and 1 assignee

…tion specs

- Updated base image to use alpine to make the container lighter
-
@dikhan dikhan added the bug-fix label May 18, 2021
@dikhan dikhan self-assigned this May 18, 2021
@dikhan dikhan force-pushed the 293-fix-docker-examples branch 2 times, most recently from 0837b17 to 5036d17 Compare May 24, 2021 19:35
…tion specs

- Updated base image to use alpine to make the container lighter
- go mod tidy
- show terraform version when running integration tests
@dikhan dikhan force-pushed the 293-fix-docker-examples branch from 5036d17 to c3a6a86 Compare May 24, 2021 19:49
…-provider-openapi into 293-fix-docker-examples
@codecov
Copy link

codecov bot commented May 24, 2021

Codecov Report

Merging #294 (37c23f7) into master (a6a1bec) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #294   +/-   ##
=======================================
  Coverage   92.14%   92.14%           
=======================================
  Files          60       60           
  Lines        3069     3069           
=======================================
  Hits         2828     2828           
  Misses        163      163           
  Partials       78       78           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a6a1bec...37c23f7. Read the comment docs.

@dikhan
Copy link
Owner Author

dikhan commented May 27, 2021

User confirmed this PR fixes the issue: #293 (comment)

@dikhan dikhan merged commit 1657b56 into master May 27, 2021
@dikhan dikhan deleted the 293-fix-docker-examples branch May 27, 2021 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error running terraform plan in the examples_container
1 participant