https://pulumi.com logo
#getting-started
Title
# getting-started
s

stale-answer-34162

12/20/2023, 7:48 PM
anyone know how I can get pulumi to ignore cloudwatch resources if it already exists?
Copy code
* creating CloudWatch Logs Log Group (user-redis-engine_log-eks-dev-20231220): operation error CloudWatch Logs: CreateLogGroup, https response error StatusCode: 400, RequestID: b943f5bf-7285-4a17-8687-e5cccda992ba, ResourceAlreadyExistsException: The specified log group already exists
Copy code
export const userSlowLog = new aws.cloudwatch.LogGroup(userRedisSlowLogName, {
  name: userRedisSlowLogName,
  tags: additionalDefaultTags,
}, { ignoreChanges: ["name"] });

export const userRedisEngineLog = new aws.cloudwatch.LogGroup(userRedisEngineLogName, {
  name: userRedisEngineLogName,
  tags: additionalDefaultTags,
}, { ignoreChanges: ["name"] });
l

little-cartoon-10569

12/20/2023, 8:51 PM
That's an AWS error, not a Pulumi one. You can't create a thing that already exists. The best option is to import it into Pulumi.
s

stale-answer-34162

12/20/2023, 8:51 PM
that is challenging as I wanted to rerun this stack multiple times.
l

little-cartoon-10569

12/20/2023, 9:30 PM
That's not challenging. Importing is easy and you only do it once.
Remember, Pulumi is not imperative, it's declarative. You express a desired state and Pulumi makes it happen. You don't express a series of creation instructions.
s

stale-answer-34162

12/20/2023, 9:32 PM
my experience is the opposite of that but I'll try
l

little-cartoon-10569

12/20/2023, 9:34 PM
We're here to help! You just need to add
import: "user-redis-engine_log-eks-dev-20231220"
after
ignoreChanges: ["name"]
and it'll import.
BTW why do you ignore changes to the name? That's unlikely to be right.
s

stale-answer-34162

12/20/2023, 9:37 PM
that was an attempt to bypass the stoppage to pulumi up. I've given up on that and am just trying this, on a new run with
Copy code
export const userSlowLog = new aws.cloudwatch.LogGroup(userRedisSlowLogName, {
  name: userRedisSlowLogName,
  tags: additionalDefaultTags,
});

export const userRedisEngineLog = new aws.cloudwatch.LogGroup(userRedisEngineLogName, {
  name: userRedisEngineLogName,
  tags: additionalDefaultTags,
});
l

little-cartoon-10569

12/20/2023, 10:48 PM
Is there a reason to use
name
? It's generally recommended not to.
s

stale-answer-34162

12/20/2023, 11:11 PM
no particular reason happy to remove, one sec for the stack.
l

little-cartoon-10569

12/20/2023, 11:12 PM
The
name
property should be used only when you need a "well-known" name: maybe for legacy reasons, or because a 3rd party unconfigurable app requires a resource to have a specific name.
s

stale-answer-34162

12/20/2023, 11:14 PM
I am trying to create this in a stack that also creates eks and a vpc and if it is possible use the same vpc for both resources (I think redis needs to make its own subnets in it and I think that is fine):
Copy code
const userRedisSlowLogName = `user-redis-slow_log-${stack}`;
const userRedisEngineLogName = `user-redis-engine_log-${stack}`;

export const userSlowLog = new aws.cloudwatch.LogGroup(userRedisSlowLogName, {
  name: userRedisSlowLogName,
  tags: additionalDefaultTags,
});

export const userRedisEngineLog = new aws.cloudwatch.LogGroup(userRedisEngineLogName, {
  name: userRedisEngineLogName,
  tags: additionalDefaultTags,
});

const redisName = `user-redis-${stack}`;
const redisSubnetGroupName = `user-redis-subnet-group-${stack}`;
const redisEngineVersion = '7.1'; // Use the latest stable version
const redisMaintenanceWindow = 'sun:03:00-sun:04:00'; // Set to off-peak hours
const redisNodeType = 'cache.r6g.large'; // Use a memory-optimized instance type
const redisNumCacheClusters = 3; // Increase number of nodes for high availability and read scalability

export const userRedisSubnetGroup = new aws.elasticache.SubnetGroup(redisSubnetGroupName, {
  description: 'Managed by Pulumi',
  name: redisSubnetGroupName,
  tags: additionalDefaultTags,
  subnetIds: eksVpc.privateSubnetIds,
});

export const redisSecurityGroup = new aws.ec2.SecurityGroup('redisSecurityGroup', {
  description: 'Redis Security Group',
  name: 'redisSecurityGroup',
  tags: additionalDefaultTags,
});

export const userRedis = new aws.elasticache.ReplicationGroup(redisName, {
  autoMinorVersionUpgrade: true,
  automaticFailoverEnabled: true,
  engineVersion: redisEngineVersion,
  maintenanceWindow: redisMaintenanceWindow,
  multiAzEnabled: false,
  networkType: 'ipv4',
  nodeType: redisNodeType,
  numCacheClusters: redisNumCacheClusters,
  parameterGroupName: 'default.redis7.cluster.on', // Use the parameter group that matches the engine version
  port: 6379,
  replicationGroupId: redisName,
  securityGroupIds: [redisSecurityGroup.id],
  snapshotWindow: '07:00-08:00',
  tags: additionalDefaultTags,
  description: 'Managed by Pulumi',
}, 
{
  dependsOn: [
    eksCluster, 
    cniPolicyAttachment,
    ec2ContainerpolicyAttachment,
    nextgenNodePolicyAttachment, 
    workerNodepolicyAttachment,
  ],
  protect: false,
});
l

little-cartoon-10569

12/20/2023, 11:16 PM
But you don't need those resources to have fixed names. You are passing (e.g.) redisSecurityGroup.id into the ReplicationGroup constructor, so the security group doesn't need to have a name parameter. So don't configure it.
Setting the name to be a fixed value is likely to cause the error you saw in your OP. A name clash.
s

stale-answer-34162

12/20/2023, 11:18 PM
giving it a new try now thanks for the tip
fewer errors 💪
l

little-cartoon-10569

12/21/2023, 12:11 AM
Nice. Well if anything stumps you, ask a new question, I'm here for a few more hours, probably.
s

stale-answer-34162

12/21/2023, 12:12 AM
ty I'm just plugging along