Skip to content

Fixed container image issue, linters issue and migrated modules #31

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

Merged
merged 1 commit into from
Aug 22, 2019

Conversation

ivankorn
Copy link
Contributor

@ivankorn ivankorn commented Aug 8, 2019

Fixes #32

Fixes #35

  • Migrated modules to 0.12 syntax
  • Added variable types constraints

Fixes #29

  • Updated examples/simple_instance/main.tf by introducing local.instance_name and adding substring of contianer image hash into instance_name
  • Updated examples/simple_instance/outputs.tf by reflecting the change above
  • Updated examples/instance_with_attached_disk/main.tf by introducing local.instance_name and adding substring of contianer image hash into instance_name
  • Updated examples/instance_with_attached_disk/outputs.tf by reflecting the change above

@ivankorn
Copy link
Contributor Author

ivankorn commented Aug 8, 2019

Simple example behaves as expected: image change causes container restart which fixes #29

Applied examples/simple_instance template:

[19:26][user@host:~/workspace/google/terraform-google-container-vm/examples/simple_instance]$ terraform apply -auto-approve 
data.google_compute_zones.available: Refreshing state...
module.gce-container.data.google_compute_image.coreos: Refreshing state...
module.gce-container.data.external.spec_as_yaml: Refreshing state...
random_shuffle.zone: Creating...
random_shuffle.zone: Creation complete after 0s [id=-]
google_compute_instance.vm: Creating...
google_compute_instance.vm: Still creating... [10s elapsed]
google_compute_instance.vm: Creation complete after 10s [id=container-vm-example-test-60b69fa4498cfcaec403a7b438073a2f]

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

Outputs:

container = {
  "env" = [
    {
      "name" = "TEST_VAR"
      "value" = "Hello World!"
    },
  ]
  "image" = "gcr.io/google-samples/hello-app:1.0"
  "volumeMounts" = [
    {
      "mountPath" = "/cache"
      "name" = "tempfs-0"
      "readOnly" = "false"
    },
  ]
}
instance_name = container-vm-example-test-60b69fa4498cfcaec403a7b438073a2f
ipv4 = 35.245.149.25
project_id = gl-ivankorniienko-seed
vm_container_label = cos-stable-75-12105-97-0
volumes = [
  {
    "emptyDir" = {
      "medium" = "Memory"
    }
    "name" = "tempfs-0"
  },
]
zone = us-east4-b

Checked imange name directly on the host:

[19:28][user@host:~/workspace/google/terraform-google-container-vm/examples/simple_instance]$ gcloud compute ssh container-vm-example-test-60b69fa4498cfcaec403a7b438073a2f --project=gl-ivankorniienko-seed --zone=us-east4-b
Warning: Permanently added 'compute.7130843309368537999' (ED25519) to the list of known hosts.
  ########################[ Welcome ]########################
  #  You have logged in to the guest OS.                    #
  #  To access your containers use 'docker attach' command  #
  ###########################################################
                                                             
user@container-vm-example-test-60b69fa4498cfcaec403a7b438073a2f ~ $ 
user@container-vm-example-test-60b69fa4498cfcaec403a7b438073a2f ~ $ docker container ls
CONTAINER ID        IMAGE                                 COMMAND             CREATED              STATUS              PORTS               NAMES
3d61fbc7c73e        gcr.io/google-samples/hello-app:1.0   "./hello-app"       About a minute ago   Up About a minute                       klt--mook
user@container-vm-example-test-60b69fa4498cfcaec403a7b438073a2f ~ $ 

Modified image and re-applied template:

[19:29][user@host:~/workspace/google/terraform-google-container-vm/examples/simple_instance]$ sed -i 's/hello-app:1.0/hello-app:2.0/g' main.tf 
[19:29][user@host:~/workspace/google/terraform-google-container-vm/examples/simple_instance]$ terraform apply -auto-approve 
module.gce-container.data.external.spec_as_yaml: Refreshing state...
data.google_compute_zones.available: Refreshing state...
module.gce-container.data.google_compute_image.coreos: Refreshing state...
random_shuffle.zone: Refreshing state... [id=-]
google_compute_instance.vm: Refreshing state... [id=container-vm-example-test-60b69fa4498cfcaec403a7b438073a2f]
google_compute_instance.vm: Destroying... [id=container-vm-example-test-60b69fa4498cfcaec403a7b438073a2f]
google_compute_instance.vm: Still destroying... [id=container-vm-example-test-60b69fa4498cfcaec403a7b438073a2f, 10s elapsed]
google_compute_instance.vm: Still destroying... [id=container-vm-example-test-60b69fa4498cfcaec403a7b438073a2f, 20s elapsed]
google_compute_instance.vm: Destruction complete after 28s
google_compute_instance.vm: Creating...
google_compute_instance.vm: Still creating... [10s elapsed]
google_compute_instance.vm: Creation complete after 10s [id=container-vm-example-test-d9e2e37558f80bccd1c8d52b5e757c91]

Apply complete! Resources: 1 added, 0 changed, 1 destroyed.

Outputs:

container = {
  "env" = [
    {
      "name" = "TEST_VAR"
      "value" = "Hello World!"
    },
  ]
  "image" = "gcr.io/google-samples/hello-app:2.0"
  "volumeMounts" = [
    {
      "mountPath" = "/cache"
      "name" = "tempfs-0"
      "readOnly" = "false"
    },
  ]
}
instance_name = container-vm-example-test-d9e2e37558f80bccd1c8d52b5e757c91
ipv4 = 35.245.73.87
project_id = gl-ivankorniienko-seed
vm_container_label = cos-stable-75-12105-97-0
volumes = [
  {
    "emptyDir" = {
      "medium" = "Memory"
    }
    "name" = "tempfs-0"
  },
]
zone = us-east4-b

Double checked container image directly on the host:

[19:30][user@host:~/workspace/google/terraform-google-container-vm/examples/simple_instance]$ gcloud compute ssh container-vm-example-test-d9e2e37558f80bccd1c8d52b5e757c91 --project=gl-ivankorniienko-seed --zone=us-east4-b
Warning: Permanently added 'compute.7788447641844707553' (ED25519) to the list of known hosts.
  ########################[ Welcome ]########################
  #  You have logged in to the guest OS.                    #
  #  To access your containers use 'docker attach' command  #
  ###########################################################
                                                             
user@container-vm-example-test-d9e2e37558f80bccd1c8d52b5e757c91 ~ $ docker container ls
CONTAINER ID        IMAGE                                 COMMAND             CREATED             STATUS              PORTS               NAMES
df7947a7d632        gcr.io/google-samples/hello-app:2.0   "./hello-app"       2 minutes ago       Up 2 minutes                            klt--xjnx
user@container-vm-example-test-d9e2e37558f80bccd1c8d52b5e757c91 ~ $ 

Destroyed instance:

[19:35][user@host:~/workspace/google/terraform-google-container-vm/examples/simple_instance]$ terraform destroy -force
data.google_compute_zones.available: Refreshing state...
module.gce-container.data.google_compute_image.coreos: Refreshing state...
module.gce-container.data.external.spec_as_yaml: Refreshing state...
random_shuffle.zone: Refreshing state... [id=-]
google_compute_instance.vm: Refreshing state... [id=container-vm-example-test-d9e2e37558f80bccd1c8d52b5e757c91]
google_compute_instance.vm: Destroying... [id=container-vm-example-test-d9e2e37558f80bccd1c8d52b5e757c91]
google_compute_instance.vm: Still destroying... [id=container-vm-example-test-d9e2e37558f80bccd1c8d52b5e757c91, 10s elapsed]
google_compute_instance.vm: Still destroying... [id=container-vm-example-test-d9e2e37558f80bccd1c8d52b5e757c91, 20s elapsed]
google_compute_instance.vm: Destruction complete after 27s
random_shuffle.zone: Destroying... [id=-]
random_shuffle.zone: Destruction complete after 0s

Destroy complete! Resources: 2 destroyed.
[19:36][user@host:~/workspace/google/terraform-google-container-vm/examples/simple_instance]$ 
 

@ivankorn
Copy link
Contributor Author

ivankorn commented Aug 8, 2019

Please note: the linters are broken in master branch which is reported as #32

@ivankorn
Copy link
Contributor Author

ivankorn commented Aug 9, 2019

Double-checked the example:

[15:46][user@host:~/workspace/google/terraform-google-container-vm/examples/simple_instance]$ terraform apply -auto-approve 
data.google_compute_zones.available: Refreshing state...
module.gce-container.data.google_compute_image.coreos: Refreshing state...
module.gce-container.data.external.spec_as_yaml: Refreshing state...
random_shuffle.zone: Creating...
random_shuffle.zone: Creation complete after 0s [id=-]
google_compute_instance.vm: Creating...
google_compute_instance.vm: Still creating... [10s elapsed]
google_compute_instance.vm: Creation complete after 11s [id=container-vm-example-test-60b69fa4498cfcaec403a7b438073a2f]

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

Outputs:

container = {
  "env" = [
    {
      "name" = "TEST_VAR"
      "value" = "Hello World!"
    },
  ]
  "image" = "gcr.io/google-samples/hello-app:1.0"
  "volumeMounts" = [
    {
      "mountPath" = "/cache"
      "name" = "tempfs-0"
      "readOnly" = "false"
    },
  ]
}
instance_name = container-vm-example-test-60b69fa4498cfcaec403a7b438073a2f
ipv4 = 35.245.73.87
project_id = gl-ivankorniienko-seed
vm_container_label = cos-stable-75-12105-97-0
volumes = [
  {
    "emptyDir" = {
      "medium" = "Memory"
    }
    "name" = "tempfs-0"
  },
]
zone = us-east4-a
[15:50][user@host:~/workspace/google/terraform-google-container-vm/examples/simple_instance]$ sed -i 's/hello-app:1.0/hello-app:2.0/g' main.tf 
[15:51][user@host:~/workspace/google/terraform-google-container-vm/examples/simple_instance]$ terraform apply -auto-approve 
data.google_compute_zones.available: Refreshing state...
module.gce-container.data.google_compute_image.coreos: Refreshing state...
module.gce-container.data.external.spec_as_yaml: Refreshing state...
random_shuffle.zone: Refreshing state... [id=-]
google_compute_instance.vm: Refreshing state... [id=container-vm-example-test-60b69fa4498cfcaec403a7b438073a2f]
google_compute_instance.vm: Destroying... [id=container-vm-example-test-60b69fa4498cfcaec403a7b438073a2f]
google_compute_instance.vm: Still destroying... [id=container-vm-example-test-60b69fa4498cfcaec403a7b438073a2f, 10s elapsed]
google_compute_instance.vm: Still destroying... [id=container-vm-example-test-60b69fa4498cfcaec403a7b438073a2f, 20s elapsed]
google_compute_instance.vm: Destruction complete after 27s
google_compute_instance.vm: Creating...
google_compute_instance.vm: Still creating... [10s elapsed]
google_compute_instance.vm: Creation complete after 12s [id=container-vm-example-test-d9e2e37558f80bccd1c8d52b5e757c91]

Apply complete! Resources: 1 added, 0 changed, 1 destroyed.

Outputs:

container = {
  "env" = [
    {
      "name" = "TEST_VAR"
      "value" = "Hello World!"
    },
  ]
  "image" = "gcr.io/google-samples/hello-app:2.0"
  "volumeMounts" = [
    {
      "mountPath" = "/cache"
      "name" = "tempfs-0"
      "readOnly" = "false"
    },
  ]
}
instance_name = container-vm-example-test-d9e2e37558f80bccd1c8d52b5e757c91
ipv4 = 35.245.149.25
project_id = gl-ivankorniienko-seed
vm_container_label = cos-stable-75-12105-97-0
volumes = [
  {
    "emptyDir" = {
      "medium" = "Memory"
    }
    "name" = "tempfs-0"
  },
]
zone = us-east4-a
[15:52][user@host:~/workspace/google/terraform-google-container-vm/examples/simple_instance]$ gcloud compute ssh container-vm-example-test-d9e2e37558f80bccd1c8d52b5e757c91 --project=gl-ivankorniienko-seed --zone=us-east4-a
Warning: Permanently added 'compute.3636803477526598254' (ED25519) to the list of known hosts.
  ########################[ Welcome ]########################
  #  You have logged in to the guest OS.                    #
  #  To access your containers use 'docker attach' command  #
  ###########################################################
                                                             
user@container-vm-example-test-d9e2e37558f80bccd1c8d52b5e757c91 ~ $ docker container ls
CONTAINER ID        IMAGE                                 COMMAND             CREATED             STATUS              PORTS               NAMES
0b975917af08        gcr.io/google-samples/hello-app:2.0   "./hello-app"       12 seconds ago      Up 12 seconds                           klt--xjnx
user@container-vm-example-test-d9e2e37558f80bccd1c8d52b5e757c91 ~ $ 

Copy link
Contributor

@ingwarr ingwarr left a comment

Choose a reason for hiding this comment

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

All looking good

@nick4fake nick4fake marked this pull request as ready for review August 12, 2019 07:58
@ivankorn ivankorn requested review from morgante and removed request for paulpalamarchuk August 14, 2019 12:02
@morgante
Copy link
Contributor

@ivankorn Can we also make the same update for the attached-disk example?

@aaron-lane aaron-lane added the bug Something isn't working label Aug 16, 2019
@ivankorn ivankorn changed the title Fix: Updating image inside the example doesn't cause container to restart Fixed container image issue, linters issue and migrated modules Aug 19, 2019
@ivankorn
Copy link
Contributor Author

Integration tests passed locally

bash-4.4# kitchen create
-----> Starting Kitchen (v1.24.0)
-----> Creating <simple-instance-local>...
       Terraform v0.12.3
       
       Your version of Terraform is out of date! The latest version
       is 0.12.6. You can update by downloading from www.terraform.io/downloads.html
$$$$$$ Running command `terraform init -input=false -lock=true -lock-timeout=0s  -upgrade -force-copy -backend=true  -get=true -get-plugins=true -verify-plugins=true` in directory /cft/workdir/test/fixtures/simple_instance
       Upgrading modules...
       - example in ../../../examples/simple_instance
       - example.gce-container in ../../..
       
       Initializing the backend...
       
       Initializing provider plugins...
       - Checking for available provider plugins...
       - Downloading plugin for provider "random" (terraform-providers/random) 2.2.0...
       - Downloading plugin for provider "external" (terraform-providers/external) 1.2.0...
       
       The following providers do not have any version constraints in configuration,
       so the latest version was installed.
       
       To prevent automatic upgrades to new major versions that may contain breaking
       changes, it is recommended to add version = "..." constraints to the
       corresponding provider blocks in configuration, with the constraint strings
       suggested below.
       
       * provider.external: version = "~> 1.2"
       * provider.google: version = "~> 2.7"
       * provider.random: version = "~> 2.2"
       
       Terraform has been successfully initialized!
$$$$$$ Running command `terraform workspace select kitchen-terraform-simple-instance-local` in directory /cft/workdir/test/fixtures/simple_instance
       
       Workspace "kitchen-terraform-simple-instance-local" doesn't exist.
       
       You can create this workspace with the "new" subcommand.
$$$$$$ Running command `terraform workspace new kitchen-terraform-simple-instance-local` in directory /cft/workdir/test/fixtures/simple_instance
       Created and switched to workspace "kitchen-terraform-simple-instance-local"!
       
       You're now on a new, empty workspace. Workspaces isolate their state,
       so if you run "terraform plan" Terraform will not see any existing state
       for this configuration.
       Finished creating <simple-instance-local> (0m3.98s).
-----> Creating <instance-with-attached-disk-local>...
       Terraform v0.12.3
       
       Your version of Terraform is out of date! The latest version
       is 0.12.6. You can update by downloading from www.terraform.io/downloads.html
$$$$$$ Running command `terraform init -input=false -lock=true -lock-timeout=0s  -upgrade -force-copy -backend=true  -get=true -get-plugins=true -verify-plugins=true` in directory /cft/workdir/test/fixtures/instance_with_attached_disk
       Upgrading modules...
       - example in ../../../examples/instance_with_attached_disk
       - example.gce-container in ../../..
       
       Initializing the backend...
       
       Initializing provider plugins...
       - Checking for available provider plugins...
       - Downloading plugin for provider "external" (terraform-providers/external) 1.2.0...
       - Downloading plugin for provider "tls" (terraform-providers/tls) 2.1.0...
       - Downloading plugin for provider "local" (terraform-providers/local) 1.3.0...
       - Downloading plugin for provider "random" (terraform-providers/random) 2.2.0...
       
       The following providers do not have any version constraints in configuration,
       so the latest version was installed.
       
       To prevent automatic upgrades to new major versions that may contain breaking
       changes, it is recommended to add version = "..." constraints to the
       corresponding provider blocks in configuration, with the constraint strings
       suggested below.
       
       * provider.external: version = "~> 1.2"
       * provider.google: version = "~> 2.7"
       * provider.local: version = "~> 1.3"
       * provider.random: version = "~> 2.2"
       * provider.tls: version = "~> 2.1"
       
       Terraform has been successfully initialized!
$$$$$$ Running command `terraform workspace select kitchen-terraform-instance-with-attached-disk-local` in directory /cft/workdir/test/fixtures/instance_with_attached_disk
       
       Workspace "kitchen-terraform-instance-with-attached-disk-local" doesn't exist.
       
       You can create this workspace with the "new" subcommand.
$$$$$$ Running command `terraform workspace new kitchen-terraform-instance-with-attached-disk-local` in directory /cft/workdir/test/fixtures/instance_with_attached_disk
       Created and switched to workspace "kitchen-terraform-instance-with-attached-disk-local"!
       
       You're now on a new, empty workspace. Workspaces isolate their state,
       so if you run "terraform plan" Terraform will not see any existing state
       for this configuration.
       Finished creating <instance-with-attached-disk-local> (0m5.59s).
-----> Kitchen is finished. (0m10.92s)
bash-4.4# kitchen converge
-----> Starting Kitchen (v1.24.0)
-----> Converging <simple-instance-local>...
       Terraform v0.12.3
       
       Your version of Terraform is out of date! The latest version
       is 0.12.6. You can update by downloading from www.terraform.io/downloads.html
$$$$$$ Running command `terraform workspace select kitchen-terraform-simple-instance-local` in directory /cft/workdir/test/fixtures/simple_instance
$$$$$$ Running command `terraform get -update` in directory /cft/workdir/test/fixtures/simple_instance
       - example in ../../../examples/simple_instance
       - example.gce-container in ../../..
$$$$$$ Running command `terraform validate   ` in directory /cft/workdir/test/fixtures/simple_instance
       Success! The configuration is valid.
       
$$$$$$ Running command `terraform apply -lock=true -lock-timeout=0s -input=false -auto-approve=true  -parallelism=10 -refresh=true  ` in directory /cft/workdir/test/fixtures/simple_instance
       module.example.module.gce-container.data.external.spec_as_yaml: Refreshing state...
       module.example.module.gce-container.data.google_compute_image.coreos: Refreshing state...
       module.example.data.google_compute_zones.available: Refreshing state...
       module.example.random_shuffle.zone: Creating...
       random_string.suffix: Creating...
       module.example.random_shuffle.zone: Creation complete after 0s [id=-]
       random_string.suffix: Creation complete after 0s [id=gocu]
       google_compute_network.main: Creating...
       google_compute_network.main: Still creating... [10s elapsed]
       google_compute_network.main: Still creating... [20s elapsed]
       google_compute_network.main: Creation complete after 28s [id=cft-container-vm-test-simple-gocu]
       google_compute_subnetwork.main: Creating...
       google_compute_subnetwork.main: Still creating... [10s elapsed]
       google_compute_subnetwork.main: Still creating... [20s elapsed]
       google_compute_subnetwork.main: Creation complete after 27s [id=us-east4/cft-container-vm-test-simple-gocu]
       google_compute_firewall.ssh: Creating...
       module.example.google_compute_instance.vm: Creating...
       google_compute_firewall.ssh: Still creating... [10s elapsed]
       module.example.google_compute_instance.vm: Still creating... [10s elapsed]
       module.example.google_compute_instance.vm: Creation complete after 11s [id=cft-test-simple-gocu-60b69fa4]
       google_compute_firewall.ssh: Creation complete after 17s [id=cft-test-gocu-simple-ssh]
       
       Apply complete! Resources: 6 added, 0 changed, 0 destroyed.
       
       Outputs:
       
       container = {
         "env" = [
           {
             "name" = "TEST_VAR"
             "value" = "Hello World!"
           },
         ]
         "image" = "gcr.io/google-samples/hello-app:1.0"
         "volumeMounts" = [
           {
             "mountPath" = "/cache"
             "name" = "tempfs-0"
             "readOnly" = "false"
           },
         ]
       }
       instance_name = cft-test-simple-gocu-60b69fa4
       ipv4 = 35.221.38.185
       network = cft-container-vm-test-simple-gocu
       project_id = gl-ivankorniienko-seed
       subnetwork = cft-container-vm-test-simple-gocu
       vm_container_label = cos-stable-76-12239-60-0
       volumes = [
         {
           "emptyDir" = {
             "medium" = "Memory"
           }
           "name" = "tempfs-0"
         },
       ]
       zone = us-east4-c
       Finished converging <simple-instance-local> (1m16.31s).
-----> Converging <instance-with-attached-disk-local>...
       Terraform v0.12.3
       
       Your version of Terraform is out of date! The latest version
       is 0.12.6. You can update by downloading from www.terraform.io/downloads.html
$$$$$$ Running command `terraform workspace select kitchen-terraform-instance-with-attached-disk-local` in directory /cft/workdir/test/fixtures/instance_with_attached_disk
$$$$$$ Running command `terraform get -update` in directory /cft/workdir/test/fixtures/instance_with_attached_disk
       - example in ../../../examples/instance_with_attached_disk
       - example.gce-container in ../../..
$$$$$$ Running command `terraform validate   ` in directory /cft/workdir/test/fixtures/instance_with_attached_disk
       Success! The configuration is valid.
       
$$$$$$ Running command `terraform apply -lock=true -lock-timeout=0s -input=false -auto-approve=true  -parallelism=10 -refresh=true  ` in directory /cft/workdir/test/fixtures/instance_with_attached_disk
       module.example.module.gce-container.data.external.spec_as_yaml: Refreshing state...
       module.example.module.gce-container.data.google_compute_image.coreos: Refreshing state...
       random_string.suffix: Creating...
       tls_private_key.gce-keypair: Creating...
       random_string.suffix: Creation complete after 0s [id=fftt]
       google_compute_network.main: Creating...
       module.example.google_compute_disk.pd: Creating...
       tls_private_key.gce-keypair: Creation complete after 3s [id=81a791ecdf5fe2544161f27546f3802278103179]
       local_file.gce-keypair-pk: Creating...
       local_file.gce-keypair-pk: Creation complete after 0s [id=1714c6b225daf6c19eca37ae59003fc03c256674]
       module.example.google_compute_disk.pd: Creation complete after 5s [id=cft-test-instance-with-attached-disk-fftt-60b69fa4-data-disk]
       google_compute_network.main: Still creating... [10s elapsed]
       google_compute_network.main: Creation complete after 17s [id=cft-container-vm-test-instance-with-attached-disk-fftt]
       google_compute_subnetwork.main: Creating...
       google_compute_subnetwork.main: Still creating... [10s elapsed]
       google_compute_subnetwork.main: Still creating... [20s elapsed]
       google_compute_subnetwork.main: Creation complete after 28s [id=us-east4/cft-container-vm-test-instance-with-attached-disk-fftt]
       google_compute_firewall.ssh: Creating...
       module.example.google_compute_firewall.http-access: Creating...
       module.example.google_compute_instance.vm: Creating...
       google_compute_firewall.ssh: Still creating... [10s elapsed]
       module.example.google_compute_firewall.http-access: Still creating... [10s elapsed]
       module.example.google_compute_instance.vm: Still creating... [10s elapsed]
       module.example.google_compute_instance.vm: Creation complete after 11s [id=cft-test-instance-with-attached-disk-fftt-60b69fa4]
       module.example.google_compute_firewall.http-access: Creation complete after 17s [id=cft-test-instance-with-attached-disk-fftt-60b69fa4-http]
       google_compute_firewall.ssh: Creation complete after 17s [id=cft-test-fftt-instance-with-attached-disk-ssh]
       
       Apply complete! Resources: 9 added, 0 changed, 0 destroyed.
       
       Outputs:
       
       container = {
         "env" = [
           {
             "name" = "TEST_VAR"
             "value" = "Hello World!"
           },
         ]
         "image" = "gcr.io/google-samples/hello-app:1.0"
         "volumeMounts" = [
           {
             "mountPath" = "/cache"
             "name" = "tempfs-0"
             "readOnly" = "false"
           },
           {
             "mountPath" = "/persistent-data"
             "name" = "data-disk-0"
             "readOnly" = "false"
           },
         ]
       }
       http_address = 35.221.3.183
       http_port = 8080
       instance_name = cft-test-instance-with-attached-disk-fftt-60b69fa4
       ipv4 = 35.221.3.183
       network = cft-container-vm-test-instance-with-attached-disk-fftt
       project_id = gl-ivankorniienko-seed
       subnetwork = cft-container-vm-test-instance-with-attached-disk-fftt
       vm_container_label = cos-stable-76-12239-60-0
       volumes = [
         {
           "emptyDir" = {
             "medium" = "Memory"
           }
           "name" = "tempfs-0"
         },
         {
           "gcePersistentDisk" = {
             "fsType" = "ext4"
             "pdName" = "data-disk-0"
           }
           "name" = "data-disk-0"
         },
       ]
       zone = us-east4-b
       Finished converging <instance-with-attached-disk-local> (1m7.51s).
-----> Kitchen is finished. (2m25.18s)
bash-4.4# echo $?
0
bash-4.4# kitchen verify
-----> Starting Kitchen (v1.24.0)
-----> Setting up <simple-instance-local>...
       Finished setting up <simple-instance-local> (0m0.00s).
-----> Verifying <simple-instance-local>...
$$$$$$ Running command `terraform workspace select kitchen-terraform-simple-instance-local` in directory /cft/workdir/test/fixtures/simple_instance
$$$$$$ Running command `terraform output -json` in directory /cft/workdir/test/fixtures/simple_instance
system: Verifying

Profile: simple_instance
Version: (not specified)
Target:  local://

  ✔  gce: Google Compute Engine instance configuration
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-simple-gocu-60b69fa4 --zone=us-east4-c --format json` is in a running state
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-simple-gocu-60b69fa4 --zone=us-east4-c --format json` is in the correct network
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-simple-gocu-60b69fa4 --zone=us-east4-c --format json` is in the correct subnetwork
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-simple-gocu-60b69fa4 --zone=us-east4-c --format json` is the expected machine type
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-simple-gocu-60b69fa4 --zone=us-east4-c --format json` has the expected labels
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-simple-gocu-60b69fa4 --zone=us-east4-c --format json` is configured with the expected container(s), volumes, env and restart policy
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-simple-gocu-60b69fa4 --zone=us-east4-c --format json` exit_status should equal 0
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-simple-gocu-60b69fa4 --zone=us-east4-c --format json` stderr should eq ""


Profile Summary: 1 successful control, 0 control failures, 0 controls skipped
Test Summary: 8 successful, 0 failures, 0 skipped
       Finished verifying <simple-instance-local> (0m1.63s).
-----> Setting up <instance-with-attached-disk-local>...
       Finished setting up <instance-with-attached-disk-local> (0m0.00s).
-----> Verifying <instance-with-attached-disk-local>...
$$$$$$ Running command `terraform workspace select kitchen-terraform-instance-with-attached-disk-local` in directory /cft/workdir/test/fixtures/instance_with_attached_disk
$$$$$$ Running command `terraform output -json` in directory /cft/workdir/test/fixtures/instance_with_attached_disk
system: Verifying

Profile: instance_with_attached_disk
Version: (not specified)
Target:  local://

  ✔  gce: Google Compute Engine instance configuration
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-instance-with-attached-disk-fftt-60b69fa4 --zone=us-east4-b --format json` is in a running state
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-instance-with-attached-disk-fftt-60b69fa4 --zone=us-east4-b --format json` is in the correct network
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-instance-with-attached-disk-fftt-60b69fa4 --zone=us-east4-b --format json` is in the correct subnetwork
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-instance-with-attached-disk-fftt-60b69fa4 --zone=us-east4-b --format json` is the expected machine type
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-instance-with-attached-disk-fftt-60b69fa4 --zone=us-east4-b --format json` has the expected labels
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-instance-with-attached-disk-fftt-60b69fa4 --zone=us-east4-b --format json` is configured with the expected container(s), volumes, env and restart policy
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-instance-with-attached-disk-fftt-60b69fa4 --zone=us-east4-b --format json` exit_status should equal 0
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-instance-with-attached-disk-fftt-60b69fa4 --zone=us-east4-b --format json` stderr should eq ""
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute disks list --filter="zone:( us-east4-b )" --format json` creates and attaches a disk to the instance
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute disks list --filter="zone:( us-east4-b )" --format json` exit_status should equal 0
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute disks list --filter="zone:( us-east4-b )" --format json` stderr should eq ""


Profile Summary: 1 successful control, 0 control failures, 0 controls skipped
Test Summary: 11 successful, 0 failures, 0 skipped
remote: Verifying host 35.221.3.183

Profile: instance_with_attached_disk
Version: (not specified)
Target:  ssh://[email protected]:22

  ✔  docker: Docker containers
     ✔  #<Inspec::Resources::DockerContainerFilter:0x0000564cdf45b988> should have our container
     ✔  #<Inspec::Resources::DockerContainerFilter:0x0000564cdf45b988> should be running the designated image
     ✔  #<Inspec::Resources::DockerContainerFilter:0x0000564cdf45b988> should have a properly configured restart policy
     ✔  #<Inspec::Resources::DockerContainerFilter:0x0000564cdf45b988> should have the right number of disk mounts
     ✔  #<Inspec::Resources::DockerContainerFilter:0x0000564cdf45b988> should have the right number of bound disk mounts
     ✔  #<Inspec::Resources::DockerContainerFilter:0x0000564cdf45b988> should have the right number of GCE persistent disks on the right mount points
     ✔  #<Inspec::Resources::DockerContainerFilter:0x0000564cdf45b988> should have the right number of tempfs disks on the right mount points
     ✔  #<Inspec::Resources::DockerContainerFilter:0x0000564cdf45b988> images should include "gcr.io/google-samples/hello-app:1.0"


Profile Summary: 1 successful control, 0 control failures, 0 controls skipped
Test Summary: 8 successful, 0 failures, 0 skipped
       Finished verifying <instance-with-attached-disk-local> (0m26.90s).
-----> Kitchen is finished. (0m29.94s)
bash-4.4# 

bash-4.4# echo $?
0
bash-4.4# 

@ivankorn
Copy link
Contributor Author

linters passed locally

[21:08][user@host:~/workspace/google/terraform-google-container-vm_28]$ make -s
Running shellcheck
Running flake8
Running go fmt and go vet
Running terraform fmt
terraform fmt -diff -check=true -write=false . 
terraform fmt -diff -check=true -write=false ./examples/instance_with_attached_disk 
terraform fmt -diff -check=true -write=false ./examples/simple_instance 
terraform fmt -diff -check=true -write=false ./modules/cos-coredns 
terraform fmt -diff -check=true -write=false ./modules/cos-generic 
terraform fmt -diff -check=true -write=false ./modules/cos-mysql 
terraform fmt -diff -check=true -write=false ./test/fixtures/instance_with_attached_disk 
terraform fmt -diff -check=true -write=false ./test/fixtures/shared 
terraform fmt -diff -check=true -write=false ./test/fixtures/simple_instance 
Running terraform validate
helpers/terraform_validate . 

Initializing provider plugins...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.external: version = "~> 1.2"
* provider.google: version = "~> 2.13"

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.
Success! The configuration is valid.

helpers/terraform_validate ./examples/instance_with_attached_disk 
Initializing modules...

Initializing provider plugins...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.external: version = "~> 1.2"
* provider.google: version = "~> 2.13"

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.
Success! The configuration is valid.

helpers/terraform_validate ./examples/simple_instance 
Initializing modules...

Initializing provider plugins...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.external: version = "~> 1.2"
* provider.google: version = "~> 2.12"
* provider.random: version = "~> 2.1"

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.
Success! The configuration is valid.

helpers/terraform_validate ./modules/cos-coredns 

Initializing provider plugins...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.google: version = "~> 2.13"
* provider.template: version = "~> 2.1"

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.
Success! The configuration is valid.

helpers/terraform_validate ./modules/cos-generic 

Initializing provider plugins...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.google: version = "~> 2.13"
* provider.template: version = "~> 2.1"

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.
Success! The configuration is valid.

helpers/terraform_validate ./modules/cos-mysql 

Initializing provider plugins...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.google: version = "~> 2.13"
* provider.random: version = "~> 2.2"
* provider.template: version = "~> 2.1"

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.
Success! The configuration is valid.

helpers/terraform_validate ./test/fixtures/instance_with_attached_disk 
Initializing modules...

Initializing provider plugins...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.external: version = "~> 1.2"
* provider.google: version = "~> 2.13"
* provider.local: version = "~> 1.3"
* provider.random: version = "~> 2.2"
* provider.tls: version = "~> 2.1"

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.
Success! The configuration is valid.

helpers/terraform_validate ./test/fixtures/simple_instance 
Initializing modules...

Initializing provider plugins...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.external: version = "~> 1.2"
* provider.google: version = "~> 2.13"
* provider.random: version = "~> 2.2"

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.
Success! The configuration is valid.

Checking for required files LICENSE README.md
Testing the validity of the header check
..
----------------------------------------------------------------------
Ran 2 tests in 0.009s

OK
Checking file headers
Checking for trailing whitespace
Generating markdown docs with terraform-docs
Skipping ./test/fixtures/instance_with_attached_disk because README.md does not exist.
Skipping ./test/fixtures/shared because README.md does not exist.
Skipping ./test/fixtures/simple_instance because README.md does not exist.
[21:08][user@host:~/workspace/google/terraform-google-container-vm_28]$ echo $?
0
[21:09][user@host:~/workspace/google/terraform-google-container-vm_28]$ 

@ivankorn
Copy link
Contributor Author

trailing whitespaces linter is passing:

  • locally
[21:10][user@host:~/workspace/google/terraform-google-container-vm_28]$ make check_trailing_whitespace 
Checking for trailing whitespace
  • locally with the same docker lint image(2.2.0) as in concourse here
[21:12][user@host:~/workspace/google/terraform-google-container-vm_28]$ docker run -ti -v `pwd`:/cft/workdir gcr.io/cloud-foundation-cicd/cft/lint:2.2.0 /bin/bash -c 'cd /cft/workdir && make check_trailing_whitespace'
Checking for trailing whitespace
[21:14][user@host:~/workspace/google/terraform-google-container-vm_28]$ echo $?
0
  • locally with image tag 2.4.0 (most commonly used)
[21:14][user@host:~/workspace/google/terraform-google-container-vm_28]$ docker run -ti -v `pwd`:/cft/workdir gcr.io/cloud-foundation-cicd/cft/lint:2.4.0 /bin/bash -c 'cd /cft/workdir && make check_trailing_whitespace'
Checking for trailing whitespace
[21:14][user@host:~/workspace/google/terraform-google-container-vm_28]$ echo $?
0
[21:14][user@host:~/workspace/google/terraform-google-container-vm_28]$ 

@ivankorn
Copy link
Contributor Author

trailing whitespaces linter is passing:

  • locally with the same docker lint image(2.2.0) as in concourse here

Just another version of the same check:
Double-checked the file using 2.2.0 linter image: I don't see any whitespaces at line 26

$ docker run -ti -v `pwd`:/cft/workdir gcr.io/cloud-foundation-cicd/cft/lint:2.2.0 /bin/bash -c 'cd /cft/workdir && bash'
bash-4.4# pwd
/cft/workdir
bash-4.4# ls 
CHANGELOG.md  Gemfile  Gemfile.lock  LICENSE  Makefile	README.md  credentials.json  examples  helpers	main.tf  modules  output.tf  requirements.txt  terraform-google-container-vm_28_tests  test  variables.tf  versions.tf
bash-4.4# sed -n '26{p;q}'  README.md | cat -E
    volumeMounts = [$
bash-4.4# 

the check is passing as well

bash-4.4# make check_trailing_whitespace
Checking for trailing whitespace
bash-4.4# echo $?
0
bash-4.4# 

@aaron-lane @kopachevsky @nick4fake @paulpalamarchuk @ingwarr
Is there anything I keep missing?
Thanks

@ivankorn
Copy link
Contributor Author

@ivankorn Can we also make the same update for the attached-disk example?

@morgante, sure. I hope this would work for you.
Would you mind giving a look at the linter problem when you get a time for minor things ?

@ivankorn ivankorn force-pushed the 29 branch 2 times, most recently from cdc9ec7 to 221f9d7 Compare August 19, 2019 21:52
@ivankorn
Copy link
Contributor Author

Fixed trailing whitespace from master
@morgante, thank you for helping out!

@ivankorn
Copy link
Contributor Author

ivankorn commented Aug 20, 2019

@kopachevsky @ingwarr

There seem to be intermittent issue with image tests in instance_with_attached_disk
Previous push touched only readme and gitignore, but that test failed.. Build before is green.

Locally there're all passing..

Profile: instance_with_attached_disk
Version: (not specified)
Target:  local://

  ✔  gce: Google Compute Engine instance configuration
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-instance-with-attached-disk-efnd-60b69fa4 --zone=us-east4-b --format json` is in a running state
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-instance-with-attached-disk-efnd-60b69fa4 --zone=us-east4-b --format json` is in the correct network
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-instance-with-attached-disk-efnd-60b69fa4 --zone=us-east4-b --format json` is in the correct subnetwork
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-instance-with-attached-disk-efnd-60b69fa4 --zone=us-east4-b --format json` is the expected machine type
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-instance-with-attached-disk-efnd-60b69fa4 --zone=us-east4-b --format json` has the expected labels
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-instance-with-attached-disk-efnd-60b69fa4 --zone=us-east4-b --format json` is configured with the expected container(s), volumes, env and restart policy
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-instance-with-attached-disk-efnd-60b69fa4 --zone=us-east4-b --format json` exit_status should equal 0
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute instances describe cft-test-instance-with-attached-disk-efnd-60b69fa4 --zone=us-east4-b --format json` stderr should eq ""
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute disks list --filter="zone:( us-east4-b )" --format json` creates and attaches a disk to the instance
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute disks list --filter="zone:( us-east4-b )" --format json` exit_status should equal 0
     ✔  Command: `gcloud --project=gl-ivankorniienko-seed compute disks list --filter="zone:( us-east4-b )" --format json` stderr should eq ""


Profile Summary: 1 successful control, 0 control failures, 0 controls skipped
Test Summary: 11 successful, 0 failures, 0 skipped
remote: Verifying host 35.221.3.183
    
Profile: instance_with_attached_disk
Version: (not specified)
Target:  ssh://[email protected]:22

  ✔  docker: Docker containers
     ✔  #<Inspec::Resources::DockerContainerFilter:0x0000561d2228b208> should have our container
     ✔  #<Inspec::Resources::DockerContainerFilter:0x0000561d2228b208> should be running the designated image
     ✔  #<Inspec::Resources::DockerContainerFilter:0x0000561d2228b208> should have a properly configured restart policy
     ✔  #<Inspec::Resources::DockerContainerFilter:0x0000561d2228b208> should have the right number of disk mounts
     ✔  #<Inspec::Resources::DockerContainerFilter:0x0000561d2228b208> should have the right number of bound disk mounts
     ✔  #<Inspec::Resources::DockerContainerFilter:0x0000561d2228b208> should have the right number of GCE persistent disks on the right mount points
     ✔  #<Inspec::Resources::DockerContainerFilter:0x0000561d2228b208> should have the right number of tempfs disks on the right mount points
     ✔  #<Inspec::Resources::DockerContainerFilter:0x0000561d2228b208> images should include "gcr.io/google-samples/hello-app:1.0"


Profile Summary: 1 successful control, 0 control failures, 0 controls skipped
Test Summary: 8 successful, 0 failures, 0 skipped
       Finished verifying <instance-with-attached-disk-local> (0m24.21s).
-----> Kitchen is finished. (1m40.01s)

- Removed outdated doc_generator
- Added missing helper scripts
- Removed outdated docker linter
- Fixed flake8 errors reported in terraform-google-modules#32
- Fixed broken simlinks(fixes terraform fmt terraform-google-modules#32)
- Updated shared tfvars
- Updated README files
- Fixed trailing white-space from master
- Adjusted .gitingore

Migrate modules to 0.12 and make the rest of the code base 0.12-compatible terraform-google-modules#35

- Migrated modules to 0.12 syntax
- Added variable types constraints
- Updated README
- Removed outdated check_docker make target
- Added a temporary workgaround for terraform-google-modules#28 (skip not migrated files in `find_files`)

Updating image inside the example doesn't cause container to restart terraform-google-modules#29

- Updated examples/simple_instance/main.tf by introducing local.instance_name and adding substring of contianer image hash into instance_name
- Updated examples/simple_instance/outputs.tf by reflecting the change above
- Updated examples/instance_with_attached_disk/main.tf by introducing local.instance_name and adding substring of contianer image hash into instance_name
- Updated examples/instance_with_attached_disk/outputs.tf by reflecting the change above
@ivankorn
Copy link
Contributor Author

@kopachevsky @ingwarr
There seem to be intermittent issue with image tests in instance_with_attached_disk

Latest build confirms that, 50/50 passes so far. We may want to track/investigate this further.

@aaron-lane aaron-lane self-assigned this Aug 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
5 participants