Skip to content

Commit

Permalink
feat!: update to allow TPG version 4.0 and TF v0.13+ format (#31)
Browse files Browse the repository at this point in the history
* feat: update TPG version constraints to allow 4.0

* feat: support TF version 0.13+

Co-authored-by: Andrew Peabody <[email protected]>
  • Loading branch information
cloud-foundation-bot and apeabody authored Apr 19, 2022
1 parent 3ae6a60 commit 7997b41
Show file tree
Hide file tree
Showing 23 changed files with 111 additions and 88 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Session.vim
*.tfstate
*.tfstate.*

# tf lock file
.terraform.lock.hcl

# Crash log files
crash.log

Expand Down
2 changes: 2 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ suites:
- name: "simple_example"
driver:
name: "terraform"
verify_version: false
command_timeout: 1800
root_module_directory: test/fixtures/simple_example
- name: "gsutil"
driver:
name: "terraform"
verify_version: false
command_timeout: 1800
root_module_directory: test/fixtures/gsutil
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Make will use bash instead of sh
SHELL := /usr/bin/env bash

DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 0.4.0
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 1
DOCKER_IMAGE_DEVELOPER_TOOLS := cft/developer-tools
REGISTRY_URL := gcr.io/cloud-foundation-cicd

Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ Use cases are:

## Compatibility

This module is meant for use with Terraform 0.12. If you haven't [upgraded](https://www.terraform.io/upgrade-guides/0-12.html) and need a Terraform 0.11.x-compatible version of this module, the last released version intended for Terraform 0.11.x
is [0.1.0](https://registry.terraform.io/modules/terraform-google-modules/startup-scripts/google/0.1.0).
This module is meant for use with Terraform 0.13+ and tested using Terraform 1.0+.
If you find incompatibilities using Terraform `>=0.13`, please open an issue.

If you haven't [upgraded][terraform-0.13-upgrade] and need a Terraform
0.12.x-compatible version of this module, the last released version
intended for Terraform 0.12.x is [1.0.0].

# Usage

Expand Down Expand Up @@ -132,11 +136,11 @@ non-zero length value. Logs are sent to syslog and standard error by default.
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| enable\_get\_from\_bucket | If not false, include stdlib::get_from_bucket() prior to executing startup-script-custom. Requires gsutil in the PATH. See also enable_init_gsutil_crcmod_el feature flag. | bool | `"false"` | no |
| enable\_init\_gsutil\_crcmod\_el | If not false, include stdlib::init_gsutil_crcmod_el() prior to executing startup-script-custom. Call this function from startup-script-custom to initialize gsutil as per https://cloud.google.com/storage/docs/gsutil/addlhelp/CRC32CandInstallingcrcmod#centos-rhel-and-fedora Intended for CentOS, RHEL and Fedora systems. | bool | `"false"` | no |
| enable\_setup\_init\_script | If not false, include stdlib::setup_init_script() prior to executing startup-script-custom. Call this function to load an init script from GCS into /etc/init.d and initialize it with chkconfig. This function depends on stdlib::get_from_bucket, so this function won't be enabled if enable_get_from_bucket is false. | bool | `"false"` | no |
| enable\_setup\_sudoers | If true, include stdlib::setup_sudoers() prior to executing startup-script-custom. Call this function from startup-script-custom to setup unix usernames in sudoers Comma separated values must be posted to the project metadata key project/attributes/sudoers | bool | `"false"` | no |
|------|-------------|------|---------|:--------:|
| enable\_get\_from\_bucket | If not false, include stdlib::get\_from\_bucket() prior to executing startup-script-custom. Requires gsutil in the PATH. See also enable\_init\_gsutil\_crcmod\_el feature flag. | `bool` | `false` | no |
| enable\_init\_gsutil\_crcmod\_el | If not false, include stdlib::init\_gsutil\_crcmod\_el() prior to executing startup-script-custom. Call this function from startup-script-custom to initialize gsutil as per https://cloud.google.com/storage/docs/gsutil/addlhelp/CRC32CandInstallingcrcmod#centos-rhel-and-fedora Intended for CentOS, RHEL and Fedora systems. | `bool` | `false` | no |
| enable\_setup\_init\_script | If not false, include stdlib::setup\_init\_script() prior to executing startup-script-custom. Call this function to load an init script from GCS into /etc/init.d and initialize it with chkconfig. This function depends on stdlib::get\_from\_bucket, so this function won't be enabled if enable\_get\_from\_bucket is false. | `bool` | `false` | no |
| enable\_setup\_sudoers | If true, include stdlib::setup\_sudoers() prior to executing startup-script-custom. Call this function from startup-script-custom to setup unix usernames in sudoers Comma separated values must be posted to the project metadata key project/attributes/sudoers | `bool` | `false` | no |

## Outputs

Expand Down
2 changes: 1 addition & 1 deletion build/int.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ tags:
- 'integration'
substitutions:
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.4.0'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '1'
2 changes: 1 addition & 1 deletion build/lint.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ tags:
- 'bats'
substitutions:
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.4.0'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '1'
12 changes: 6 additions & 6 deletions examples/gsutil/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ functions:
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| message | The content to place in a bucket object message.txt. startup-script-custom fetches this object and validate this message against the content as an end-to-end example of stdlib::get_from_bucket(). | string | `"Hello World! uuid=0afce28a-057b-42cf-a90f-493de3c0666b"` | no |
| network | The network name to deploy to | string | `"default"` | no |
| project\_id | The project_id to deploy the example instance into. (e.g. "simple-sample-project-1234") | string | n/a | yes |
| region | The region to deploy to | string | n/a | yes |
| service\_account\_email | The service acocunt email to associate with the example instance. Should have storage.buckets.get to use stdlib::get_from_bucket | string | n/a | yes |
|------|-------------|------|---------|:--------:|
| message | The content to place in a bucket object message.txt. startup-script-custom fetches this object and validate this message against the content as an end-to-end example of stdlib::get\_from\_bucket(). | `string` | `"Hello World! uuid=0afce28a-057b-42cf-a90f-493de3c0666b"` | no |
| network | The network name to deploy to | `string` | `"default"` | no |
| project\_id | The project\_id to deploy the example instance into. (e.g. "simple-sample-project-1234") | `any` | n/a | yes |
| region | The region to deploy to | `any` | n/a | yes |
| service\_account\_email | The service acocunt email to associate with the example instance. Should have storage.buckets.get to use stdlib::get\_from\_bucket | `any` | n/a | yes |

## Outputs

Expand Down
8 changes: 3 additions & 5 deletions examples/gsutil/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@
*/

provider "google" {
version = "~> 2.9.0"
project = var.project_id
region = var.region
zone = "${var.region}-a"
}

module "startup-scripts" {
source = "../../"
enable_init_gsutil_crcmod_el = true
enable_get_from_bucket = true
enable_setup_init_script = true
source = "../../"
enable_get_from_bucket = true
enable_setup_init_script = true
}

data "google_compute_image" "os" {
Expand Down
14 changes: 13 additions & 1 deletion examples/gsutil/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,17 @@
* limitations under the License.
*/
terraform {
required_version = ">= 0.12"
required_version = ">= 0.13"
required_providers {
google = {
source = "hashicorp/google"
version = ">= 2.9.0, <5.0"
}
random = {
source = "hashicorp/random"
}
template = {
source = "hashicorp/template"
}
}
}
10 changes: 5 additions & 5 deletions examples/simple_example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ $ curl -H Metadata-Flavor:Google http://metadata.google.internal/computeMetadata
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| network | The network name to deploy to | string | `"default"` | no |
| project\_id | The project_id to deploy the example instance into. (e.g. "simple-sample-project-1234") | string | n/a | yes |
| region | The region to deploy to | string | n/a | yes |
| url | The url to fetch in the startup script. This URL is passed via instance metadata to the startup script. (e.g. ifconfig.co/city) | string | `"http://ifconfig.co/json"` | no |
|------|-------------|------|---------|:--------:|
| network | The network name to deploy to | `string` | `"default"` | no |
| project\_id | The project\_id to deploy the example instance into. (e.g. "simple-sample-project-1234") | `any` | n/a | yes |
| region | The region to deploy to | `any` | n/a | yes |
| url | The url to fetch in the startup script. This URL is passed via instance metadata to the startup script. (e.g. ifconfig.co/city) | `string` | `"http://ifconfig.co/json"` | no |

## Outputs

Expand Down
1 change: 0 additions & 1 deletion examples/simple_example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

provider "google" {
version = "~> 2.9.0"
project = var.project_id
region = var.region
zone = "${var.region}-a"
Expand Down
8 changes: 7 additions & 1 deletion examples/simple_example/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,11 @@
* limitations under the License.
*/
terraform {
required_version = ">= 0.12"
required_version = ">= 0.13"
required_providers {
google = {
source = "hashicorp/google"
version = ">= 2.9.0, <5.0"
}
}
}
1 change: 1 addition & 0 deletions test/fixtures/gsutil/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ variable "project_id" {
variable "region" {
description = "The region to deploy to"
type = string
default = "us-central1"
}

variable "service_account_email" {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/simple_example/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ variable "project_id" {
variable "region" {
description = "The region to deploy to"
type = string
default = "us-central1"
}
14 changes: 3 additions & 11 deletions test/integration/gsutil/controls/gcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

require 'retriable'

control 'get_from_bucket with crcmod compilation' do
title "With enable_init_gsutil_crcmod_el=true and enable_get_from_bucket=true"
control 'get_from_bucket' do
title "With enable_get_from_bucket=true"

describe 'console output of startup-scripts-gsutil1' do
# Avoid racing against the instance boot sequence
Expand All @@ -35,22 +35,14 @@

describe "Overall result of startup-script-custom" do
its('exit_status') { should be 0 }
its('stdout') { should match('INFO startup-script: Return code 0.') }
its('stdout') { should match('startup-script exit status 0') }
end

describe "UUID markers from startup-script-custom in the serial output" do
its('stdout') { should match('TEST UUID E62A3897-AAA0-4577-A564-F00B4B54869B') }
its('stdout') { should match('Finished with startup-script-custom example 3FF02EC9-BFFE-4B47-BEE7-C98A07818251') }
end

describe "gsutil version -l before calling stdlib::init_gsutil_crcmod_el" do
its('stdout', focus: true) { should match('679EBF864666 compiled crcmod: False') }
end

describe "gsutil version -l after calling stdlib::init_gsutil_crcmod_el" do
its('stdout') { should match('28BBEF21C095 compiled crcmod: True') }
end

##
# TODO: Move this to another example with no service account bound to the
# instance.
Expand Down
14 changes: 14 additions & 0 deletions test/integration/gsutil/inspec.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: gsutil
attributes:
- name: project_id
Expand Down
2 changes: 1 addition & 1 deletion test/integration/simple_example/controls/gcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@

its('exit_status') { should be 0 }
its('stdout') { should match(%r{Info \[\d+\]: Fetching http://ifconfig\.co/json}) }
its('stdout') { should match('INFO startup-script: Return code 0.') }
its('stdout') { should match('startup-script exit status 0') }
end
end
14 changes: 14 additions & 0 deletions test/integration/simple_example/inspec.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: simple_example
attributes:
- name: project_id
Expand Down
2 changes: 1 addition & 1 deletion test/setup/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ locals {

resource "google_service_account" "int_test" {
project = module.project.project_id
account_id = "ci-account"
account_id = "ci-account-${random_id.random_project_id_suffix.hex}"
display_name = "ci-account"
}

Expand Down
17 changes: 11 additions & 6 deletions test/setup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@
* limitations under the License.
*/

resource "random_id" "random_project_id_suffix" {
byte_length = 2
}

module "project" {
source = "terraform-google-modules/project-factory/google"
version = "~> 3.0"
version = "~> 13.0"

name = "ci-startup-scripts-${random_id.random_project_id_suffix.hex}"
random_project_id = true
org_id = var.org_id
folder_id = var.folder_id
billing_account = var.billing_account

name = "ci-startup-scripts"
random_project_id = "true"
org_id = var.org_id
folder_id = var.folder_id
billing_account = var.billing_account
auto_create_network = true

activate_apis = [
Expand Down
30 changes: 0 additions & 30 deletions test/setup/make_source.sh

This file was deleted.

20 changes: 11 additions & 9 deletions test/setup/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
*/

terraform {
required_version = ">= 0.12"
}

provider "google" {
version = "~> 2.13.0"
}

provider "google-beta" {
version = "~> 2.13.0"
required_version = ">= 0.13"
required_providers {
google = {
source = "hashicorp/google"
version = ">= 2.13.0, < 5.0"
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 2.13.0, < 5.0"
}
}
}
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
* limitations under the License.
*/
terraform {
required_version = ">= 0.12"
required_version = ">= 0.13"
}

0 comments on commit 7997b41

Please sign in to comment.