<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: aamdevsecops</title>
    <description>The latest articles on DEV Community by aamdevsecops (@aamdevsecops).</description>
    <link>https://dev.to/aamdevsecops</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F997275%2F1d665a0e-a348-41ef-b7d9-023ffcaf70b4.png</url>
      <title>DEV Community: aamdevsecops</title>
      <link>https://dev.to/aamdevsecops</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aamdevsecops"/>
    <language>en</language>
    <item>
      <title>How to troubleshoot docker unauthorized 401 error</title>
      <dc:creator>aamdevsecops</dc:creator>
      <pubDate>Sun, 08 Jan 2023 15:19:04 +0000</pubDate>
      <link>https://dev.to/aamdevsecops/how-to-troubleshoot-docker-unauthorized-401-error-4ei6</link>
      <guid>https://dev.to/aamdevsecops/how-to-troubleshoot-docker-unauthorized-401-error-4ei6</guid>
      <description>&lt;p&gt;This is an example from a public repository that was causing an issue. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;https://github.com/MilenkoMarkovic/intens-api-2022&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I created a hub.docker.com account which comes with one free repository. &lt;/p&gt;

&lt;p&gt;Then proceed with the steps below:&lt;/p&gt;

&lt;p&gt;Here is my test Dockerfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM openjdk:8-jdk-alpine

WORKDIR /opt/app

COPY target/aamdevsecops-1.1.1-SNAPSHOT.jar /opt/app/

CMD ["java","-jar","aamdevsecops-1.1.1-SNAPSHOT.jar"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Of course, i changed the &lt;code&gt;&amp;lt;name&amp;gt;,&lt;/code&gt; &lt;code&gt;&amp;lt;version&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;artifactoryId&amp;gt;&lt;/code&gt; in &lt;code&gt;pom.xml&lt;/code&gt; file to match my Dockerfile.&lt;/p&gt;

&lt;p&gt;First, i built the package locally by issuing this command on the intense-api git project folder:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mvn package&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then, I built the docker image out of it:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker build -t aamdevsecops:1.1.1 .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;then logged in to docker with my hub.docker.com credentials.&lt;/p&gt;

&lt;p&gt;docker login # you will be prompted for credentials of hub.docker.com account&lt;/p&gt;

&lt;p&gt;tagged the image: docker tag  aamdevsecops/devops-bootcamp:latest&lt;/p&gt;

&lt;p&gt;then: &lt;code&gt;docker push aamdevsecops/devops-bootcamp:1.1.1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Finally, I did:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker run --name aamdevsecops -p 8090:8090 aamdevsecops/devops-bootcamp:latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And here's the result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flal6eaqxqh5kck7yf22z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flal6eaqxqh5kck7yf22z.png" alt="Image description" width="800" height="297"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag__stackexchange--container"&gt;
  &lt;div class="ltag__stackexchange--title-container"&gt;
    
      &lt;div class="ltag__stackexchange--title"&gt;
        &lt;div class="ltag__stackexchange--header"&gt;
          &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fstackoverflow-logo-b42691ae545e4810b105ee957979a853a696085e67e43ee14c5699cf3e890fb4.svg" alt=""&gt;
          &lt;a href="https://stackoverflow.com/questions/75032734/why-am-i-not-authorized-docker-you-are-not-authorized-to-perform-this-operatio" rel="noopener noreferrer"&gt;
            Why am I not authorized? docker: you are not authorized to perform this operation: server returned 401
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="ltag__stackexchange--post-metadata"&gt;
          &lt;span&gt;Jan  6 '23&lt;/span&gt;
            &lt;span&gt;Comments: 13&lt;/span&gt;
            &lt;span&gt;Answers: 2&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;a class="ltag__stackexchange--score-container" href="https://stackoverflow.com/questions/75032734/why-am-i-not-authorized-docker-you-are-not-authorized-to-perform-this-operatio" rel="noopener noreferrer"&gt;
        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fstackexchange-arrow-up-eff2e2849e67d156181d258e38802c0b57fa011f74164a7f97675ca3b6ab756b.svg" alt=""&gt;
        &lt;div class="ltag__stackexchange--score-number"&gt;
          1
        &lt;/div&gt;
        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fstackexchange-arrow-down-4349fac0dd932d284fab7e4dd9846f19a3710558efde0d2dfd05897f3eeb9aba.svg" alt=""&gt;
      &lt;/a&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--body"&gt;
    
&lt;p&gt;My Dockerfile&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;FROM openjdk:8-jdk-alpine
WORKDIR /opt/app

COPY target/pichk-0.0.1-SNAPSHOT.jar /opt/app/

CMD ["java","-jar","pichk-0.0.1-SNAPSHOT.jar"]
EXPOSE 8090
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When I run image&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;docker run -p 8090:8090 pichk:001
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I got error&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;docker: you are not authorized to perform this operation: server returned 401.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I am adding target permissions line&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;drwxrwxr-x   9 miki miki  4096 Jan  4&lt;/code&gt;&lt;/pre&gt;…
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--btn--container"&gt;
    &lt;a href="https://stackoverflow.com/questions/75032734/why-am-i-not-authorized-docker-you-are-not-authorized-to-perform-this-operatio" class="ltag__stackexchange--btn" rel="noopener noreferrer"&gt;Open Full Question&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;



</description>
      <category>gratitude</category>
      <category>devchallenge</category>
      <category>pulumi</category>
      <category>cloudcomputing</category>
    </item>
    <item>
      <title>How to prevent destroy an instance after an update</title>
      <dc:creator>aamdevsecops</dc:creator>
      <pubDate>Tue, 27 Dec 2022 17:48:33 +0000</pubDate>
      <link>https://dev.to/aamdevsecops/how-to-prevent-destroy-an-instance-after-an-update-29hp</link>
      <guid>https://dev.to/aamdevsecops/how-to-prevent-destroy-an-instance-after-an-update-29hp</guid>
      <description>&lt;p&gt;While stumbling upon stackoverflow to crawl some posts about GCP and Terraform as part of my learning curve, I came across this particular issue: &lt;/p&gt;

&lt;h4&gt;
  
  
  How can I update an instance as part of the Infrastructure as Code after creation.
&lt;/h4&gt;

&lt;p&gt;After hours of research, manual errors and trials, it turned out that the issue was on plain sight...to quote Benoît Blanc.&lt;sup id="fnref1"&gt;1&lt;/sup&gt;. Being enthusiastic about my findings, I wanted to answer.&lt;/p&gt;

&lt;p&gt;So, it turns out that:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Instance Templates cannot be updated after creation with the Google Cloud Platform API. In order to update an Instance Template, Terraform will destroy the existing resource and create a replacement. In order to effectively use an Instance Template resource with an Instance Group Manager resource, it's recommended to specify create_before_destroy in a lifecycle block. Either omit the Instance Template name attribute, or specify a partial name with name_prefix&lt;/em&gt;"&lt;br&gt;
&lt;sup id="fnref2"&gt;2&lt;/sup&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Concretly, three options: &lt;/p&gt;

&lt;h5&gt;
  
  
  1. Use create before destroy lifecycle:
&lt;/h5&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   resource "google_compute_region_instance_group_manager" "my_service_mig" {
      version {
        instance_template = google_compute_instance_template.my_service_template.id
        name              = "primary"
      }

+ lifecycle {
+   create_before_destroy = true
+ }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  2. Use prevent_destroy
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "google_compute_region_instance_group_manager" "my_service_mig" {
      version {
        instance_template = google_compute_instance_template.my_service_template.id
        name              = "primary"
      }

+ lifecycle {
+   prevent_destroy = true
+ }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  3. Quick and dirty
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform plan | grep &amp;lt;resource&amp;gt; | grep id 
terraform state rm &amp;lt;resource&amp;gt;
terraform apply
terraform import &amp;lt;resource&amp;gt; &amp;lt;ID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;My original answer, here:&lt;/p&gt;


&lt;div class="ltag__stackexchange--container"&gt;
  &lt;div class="ltag__stackexchange--title-container"&gt;
    
      &lt;div class="ltag__stackexchange--title"&gt;
        &lt;div class="ltag__stackexchange--header"&gt;
          &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fstackoverflow-logo-b42691ae545e4810b105ee957979a853a696085e67e43ee14c5699cf3e890fb4.svg" alt=""&gt;
          &lt;a href="https://stackoverflow.com/questions/74903201/how-can-i-configure-terraform-to-update-a-gcp-compute-engine-instance-template-w" rel="noopener noreferrer"&gt;
            How can I configure Terraform to update a GCP compute engine instance template without destroying and re-creating?
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="ltag__stackexchange--post-metadata"&gt;
          &lt;span&gt;Dec 23 '22&lt;/span&gt;
            &lt;span&gt;Comments: 1&lt;/span&gt;
            &lt;span&gt;Answers: 1&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;a class="ltag__stackexchange--score-container" href="https://stackoverflow.com/questions/74903201/how-can-i-configure-terraform-to-update-a-gcp-compute-engine-instance-template-w" rel="noopener noreferrer"&gt;
        &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fstackexchange-arrow-up-eff2e2849e67d156181d258e38802c0b57fa011f74164a7f97675ca3b6ab756b.svg" alt=""&gt;
        &lt;div class="ltag__stackexchange--score-number"&gt;
          2
        &lt;/div&gt;
        &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fstackexchange-arrow-down-4349fac0dd932d284fab7e4dd9846f19a3710558efde0d2dfd05897f3eeb9aba.svg" alt=""&gt;
      &lt;/a&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--body"&gt;
    
&lt;p&gt;I have a service deployed on GCP compute engine.  It consists of a compute engine instance template, instance group, instance group manager, and load balancer + associated forwarding rules etc.&lt;/p&gt;
&lt;p&gt;We're forced into using compute engine rather than Cloud Run or some other serverless offering due to the need for…&lt;/p&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--btn--container"&gt;
    &lt;a href="https://stackoverflow.com/questions/74903201/how-can-i-configure-terraform-to-update-a-gcp-compute-engine-instance-template-w" class="ltag__stackexchange--btn" rel="noopener noreferrer"&gt;Open Full Question&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;






&lt;ol&gt;

&lt;li id="fn1"&gt;
&lt;p&gt;!!! &lt;strong&gt;&lt;em&gt;Spoiler Alert&lt;/em&gt;&lt;/strong&gt; !!!&lt;em&gt;"Well, I keep returning in my mind to the glass onion. Something that seems densely layered, mysterious and inscrutable. But in fact, the centre is in plain sight."&lt;/em&gt; - &lt;em&gt;Glass Onion&lt;/em&gt; ↩&lt;/p&gt;
&lt;/li&gt;

&lt;li id="fn2"&gt;
&lt;p&gt;&lt;a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance_template#using-with-instance-group-manager" rel="noopener noreferrer"&gt;registry.terraform.io&lt;/a&gt; ↩&lt;/p&gt;
&lt;/li&gt;

&lt;/ol&gt;

</description>
      <category>terraform</category>
      <category>gcp</category>
      <category>googlecloud</category>
    </item>
  </channel>
</rss>
